Skip to content

Commit

Permalink
Fix declaring a repository when it is a service entity repository
Browse files Browse the repository at this point in the history
  • Loading branch information
loic425 committed Nov 29, 2022
1 parent aa1fdd6 commit a6c4c59
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand All @@ -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);

Expand Down

0 comments on commit a6c4c59

Please sign in to comment.