From f0dd12e4965dec386e76023b482767310070f9e2 Mon Sep 17 00:00:00 2001 From: Maxime Veber Date: Wed, 26 Sep 2018 16:41:28 +0200 Subject: [PATCH] Support user defined repositories A verification was done with EntityRepository inheritance. This commit drop it in favor of a check on interface ObjectRepository which allow user to define its own complete repository. --- Repository/ContainerRepositoryFactory.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Repository/ContainerRepositoryFactory.php b/Repository/ContainerRepositoryFactory.php index 02ef8b5d9..6283c57cd 100644 --- a/Repository/ContainerRepositoryFactory.php +++ b/Repository/ContainerRepositoryFactory.php @@ -50,8 +50,15 @@ public function getRepository(EntityManagerInterface $entityManager, $entityName if ($this->container && $this->container->has($customRepositoryName)) { $repository = $this->container->get($customRepositoryName); - if (! $repository instanceof EntityRepository) { - throw new \RuntimeException(sprintf('The service "%s" must extend EntityRepository (or a base class, like ServiceEntityRepository).', $repositoryServiceId)); + if (\interface_exists(ObjectRepository::class)) { + if (!$repository instanceof ObjectRepository) { + throw new \RuntimeException(sprintf('The service "%s" must implement ObjectRepository (or extend a base class, like ServiceEntityRepository).', $repositoryServiceId)); + } + } else { + // Doctrine 2.4 compatibility layer + if (!$repository instanceof EntityRepository) { + throw new \RuntimeException(sprintf('The service "%s" must implement ObjectRepository (or extend a base class, like ServiceEntityRepository).', $repositoryServiceId)); + } } return $repository;