From a6c4c59ac33832d0e73e12b7cf0d7846ccc39b6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Tue, 29 Nov 2022 16:13:47 +0100 Subject: [PATCH] Fix declaring a repository when it is a service entity repository --- .../Driver/Doctrine/DoctrineORMDriver.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Bundle/DependencyInjection/Driver/Doctrine/DoctrineORMDriver.php b/src/Bundle/DependencyInjection/Driver/Doctrine/DoctrineORMDriver.php index d3a736885..382c40e10 100644 --- a/src/Bundle/DependencyInjection/Driver/Doctrine/DoctrineORMDriver.php +++ b/src/Bundle/DependencyInjection/Driver/Doctrine/DoctrineORMDriver.php @@ -13,7 +13,9 @@ namespace Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\Doctrine; +use App\Repository\BookRepository; use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\ServiceRepositoryCompilerPass; +use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Common\Persistence\ObjectManager as DeprecatedObjectManager; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadata; @@ -56,7 +58,6 @@ protected function addRepository(ContainerBuilder $container, MetadataInterface $managerReference = new Reference($metadata->getServiceId('manager')); $definition = new Definition($repositoryClass); $definition->setPublic(true); - if ($repositoryClass === EntityRepository::class) { /** @var string $entityClass */ $entityClass = $metadata->getClass('model'); @@ -68,7 +69,12 @@ protected function addRepository(ContainerBuilder $container, MetadataInterface $genericEntities[] = $entityClass; } else { - $definition->setArguments([$managerReference, $this->getClassMetadataDefinition($metadata)]); + if (is_a($repositoryClass, ServiceEntityRepository::class, true)) { + $definition->setArguments([new Reference('doctrine')]); + $container->setDefinition($serviceId, $definition); + } else { + $definition->setArguments([$managerReference, $this->getClassMetadataDefinition($metadata)]); + } $container->setDefinition($serviceId, $definition);