Currently the persistence bundle works not with such repositories.
But when you use autowire to register your repositories you need something similiar.
Expected Behavior
I think it should be possible to use.
Example Repository to autowire
// src/Repository/ProductRepository.php
namespace App\Repository;
use App\Entity\Product;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Symfony\Bridge\Doctrine\RegistryInterface;
class ProductRepository extends ServiceEntityRepository
{
public function __construct(RegistryInterface $registry)
{
parent::__construct($registry, Product::class);
}
}
Possible Solutions
Something like this could work:
diff --git a/src/Sulu/Bundle/PersistenceBundle/DependencyInjection/PersistenceExtensionTrait.php b/src/Sulu/Bundle/PersistenceBundle/DependencyInje
ction/PersistenceExtensionTrait.php
index 96ba21812..157d2fc9b 100644
--- a/src/Sulu/Bundle/PersistenceBundle/DependencyInjection/PersistenceExtensionTrait.php
+++ b/src/Sulu/Bundle/PersistenceBundle/DependencyInjection/PersistenceExtensionTrait.php
@@ -11,6 +11,7 @@
namespace Sulu\Bundle\PersistenceBundle\DependencyInjection;
+use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepositoryInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
@@ -87,11 +88,18 @@ trait PersistenceExtensionTrait
$repositoryClass = $services['repository'];
}
- $definition = new Definition($repositoryClass);
- $definition->setArguments([
- new Reference($this->getEntityManagerServiceKey()),
- $this->getClassMetadataDefinition($services['model']),
- ]);
+ if (is_subclass_of($repositoryClass, ServiceEntityRepositoryInterface::class)) {
+ $definition = new Definition($repositoryClass);
+ $definition->setArguments([
+ new Reference($this->getDoctrine()),
+ ]);
+ } else {
+ $definition = new Definition($repositoryClass);
+ $definition->setArguments([
+ new Reference($this->getEntityManagerServiceKey()),
+ $this->getClassMetadataDefinition($services['model']),
+ ]);
+ }
return $definition;
Actual Behavior
Currently the persistence bundle works not with such repositories. But when you use autowire to register your repositories you need something similiar.
Expected Behavior
I think it should be possible to use.
Example Repository to autowire
Possible Solutions
Something like this could work: