From e0d529a13b4c2e81f7fa8df792c528e964297602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Proch=C3=A1zka?= Date: Sat, 4 Jul 2015 09:05:13 +0200 Subject: [PATCH] RepositoryFactory: implemented handling of repositories as services --- composer.json | 5 + src/Kdyby/Doctrine/DI/IRepositoryFactory.php | 33 +++ src/Kdyby/Doctrine/DI/OrmExtension.php | 222 ++++++++++++++++-- src/Kdyby/Doctrine/RepositoryFactory.php | 53 ++++- .../Doctrine/RepositoryFactory.phpt | 123 ++++++++++ .../repository-factory.default-class.neon | 6 + .../config/repository-factory.manual.neon | 16 ++ .../Doctrine/config/repository-factory.neon | 19 ++ .../repository-factory.without-service.neon | 6 + tests/KdybyTests/Doctrine/models/cms.php | 18 +- .../Doctrine/models/cms.repositories.php | 44 ++++ 11 files changed, 509 insertions(+), 36 deletions(-) create mode 100644 src/Kdyby/Doctrine/DI/IRepositoryFactory.php create mode 100644 tests/KdybyTests/Doctrine/RepositoryFactory.phpt create mode 100644 tests/KdybyTests/Doctrine/config/repository-factory.default-class.neon create mode 100644 tests/KdybyTests/Doctrine/config/repository-factory.manual.neon create mode 100644 tests/KdybyTests/Doctrine/config/repository-factory.neon create mode 100644 tests/KdybyTests/Doctrine/config/repository-factory.without-service.neon create mode 100644 tests/KdybyTests/Doctrine/models/cms.repositories.php diff --git a/composer.json b/composer.json index e97e7022..0b4f68b6 100644 --- a/composer.json +++ b/composer.json @@ -66,6 +66,11 @@ "src/Kdyby/Doctrine/exceptions.php" ] }, + "autoload-dev": { + "classmap": [ + "tests/KdybyTests/Doctrine" + ] + }, "extra": { "branch-alias": { "dev-master": "3.0-dev" diff --git a/src/Kdyby/Doctrine/DI/IRepositoryFactory.php b/src/Kdyby/Doctrine/DI/IRepositoryFactory.php new file mode 100644 index 00000000..b0daaa1d --- /dev/null +++ b/src/Kdyby/Doctrine/DI/IRepositoryFactory.php @@ -0,0 +1,33 @@ + + */ +interface IRepositoryFactory +{ + + /** + * @param ORM\EntityManagerInterface $entityManager + * @param ORM\Mapping\ClassMetadata $classMetadata + * @return EntityRepository + */ + public function create(ORM\EntityManagerInterface $entityManager, ORM\Mapping\ClassMetadata $classMetadata); + +} diff --git a/src/Kdyby/Doctrine/DI/OrmExtension.php b/src/Kdyby/Doctrine/DI/OrmExtension.php index 10303f7a..3f39a6cf 100644 --- a/src/Kdyby/Doctrine/DI/OrmExtension.php +++ b/src/Kdyby/Doctrine/DI/OrmExtension.php @@ -32,6 +32,8 @@ class OrmExtension extends Nette\DI\CompilerExtension const PHP_NAMESPACE = '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff\\\\]*'; const TAG_CONNECTION = 'doctrine.connection'; const TAG_ENTITY_MANAGER = 'doctrine.entityManager'; + const TAG_BIND_TO_MANAGER = 'doctrine.bindToManager'; + const TAG_REPOSITORY_ENTITY = 'doctrine.repositoryEntity'; /** * @var array @@ -129,18 +131,31 @@ class OrmExtension extends Nette\DI\CompilerExtension */ private $configuredManagers = array(); + /** + * @var array + */ + private $managerConfigs = array(); + /** * @var array */ private $configuredConnections = array(); + /** + * @var array + */ + private $postCompileRepositoriesQueue = array(); + public function loadConfiguration() { $this->proxyAutoloaders = + $this->targetEntityMappings = $this->configuredConnections = - $this->configuredManagers = array(); + $this->managerConfigs = + $this->configuredManagers = + $this->postCompileRepositoriesQueue = array(); $extensions = array_filter($this->compiler->getExtensions(), function ($item) { return $item instanceof Kdyby\Annotations\DI\AnnotationsExtension; @@ -178,21 +193,6 @@ public function loadConfiguration() $this->processEntityManager($name, $emConfig); } - // syntax sugar for config - $builder->addDefinition($this->prefix('dao')) - ->setClass('Kdyby\Doctrine\EntityDao') - ->setFactory('@Kdyby\Doctrine\EntityManager::getDao', array(new Code\PhpLiteral('$entityName'))) - ->setParameters(array('entityName')) - ->setInject(FALSE); - - // interface for models & presenters - $builder->addDefinition($this->prefix('daoFactory')) - ->setClass('Kdyby\Doctrine\EntityDao') - ->setFactory('@Kdyby\Doctrine\EntityManager::getDao', array(new Code\PhpLiteral('$entityName'))) - ->setParameters(array('entityName')) - ->setImplement('Kdyby\Doctrine\EntityDaoFactory') - ->setInject(FALSE)->setAutowired(TRUE); - $builder->addDefinition($this->prefix('schemaValidator')) ->setClass('Doctrine\ORM\Tools\SchemaValidator') ->setInject(FALSE); @@ -325,6 +325,9 @@ protected function processEntityManager($name, array $defaults) )); } + if ($config['repositoryFactoryClassName'] === 'default') { + $config['repositoryFactoryClassName'] = 'Doctrine\ORM\Repository\DefaultRepositoryFactory'; + } $builder->addDefinition($this->prefix($name . '.repositoryFactory')) ->setClass($config['repositoryFactoryClassName']) ->setAutowired(FALSE); @@ -408,7 +411,32 @@ protected function processEntityManager($name, array $defaults) ->setAutowired($isDefault) ->setInject(FALSE); + if ($isDefault && $config['defaultRepositoryClassName'] === 'Kdyby\Doctrine\EntityDao') { + // syntax sugar for config + $builder->addDefinition($this->prefix('dao')) + ->setClass('Kdyby\Doctrine\EntityDao') + ->setFactory('@Kdyby\Doctrine\EntityManager::getDao', array(new Code\PhpLiteral('$entityName'))) + ->setParameters(array('entityName')) + ->setInject(FALSE); + + // interface for models & presenters + $builder->addDefinition($this->prefix('daoFactory')) + ->setClass('Kdyby\Doctrine\EntityDao') + ->setFactory('@Kdyby\Doctrine\EntityManager::getDao', array(new Code\PhpLiteral('$entityName'))) + ->setParameters(array('entityName')) + ->setImplement('Kdyby\Doctrine\EntityDaoFactory') + ->setInject(FALSE)->setAutowired(TRUE); + } + + $builder->addDefinition($this->prefix('repositoryFactory.' . $name . '.defaultRepositoryFactory')) + ->setClass($config['defaultRepositoryClassName']) + ->setImplement('Kdyby\Doctrine\DI\IRepositoryFactory') + ->setArguments([new Code\PhpLiteral('$entityManager'), new Code\PhpLiteral('$classMetadata')]) + ->setParameters(array('Doctrine\ORM\EntityManagerInterface entityManager', 'Doctrine\ORM\Mapping\ClassMetadata classMetadata')) + ->setAutowired(FALSE); + $this->configuredManagers[$name] = $managerServiceId; + $this->managerConfigs[$name] = $config; } @@ -626,6 +654,106 @@ public function beforeCompile() if ($eventsExt === NULL) { throw new Nette\Utils\AssertionException('Please register the required Kdyby\Events\DI\EventsExtension to Compiler.'); } + + $this->processRepositories(); + } + + + + protected function processRepositories() + { + $builder = $this->getContainerBuilder(); + + $disabled = TRUE; + foreach ($this->configuredManagers as $managerName => $_) { + $factoryClassName = $builder->getDefinition($this->prefix($managerName . '.repositoryFactory'))->class; + if ($factoryClassName === 'Kdyby\Doctrine\RepositoryFactory' || in_array('Kdyby\Doctrine\RepositoryFactory', class_parents($factoryClassName), TRUE)) { + $disabled = FALSE; + } + } + + if ($disabled) { + return; + } + + if (!method_exists($builder, 'findByType')) { + foreach ($this->configuredManagers as $managerName => $_) { + $builder->getDefinition($this->prefix($managerName . '.repositoryFactory')) + ->addSetup('setServiceIdsMap', array(array(), $this->prefix('repositoryFactory.' . $managerName . '.defaultRepositoryFactory'))); + } + + return; + } + + $serviceMap = array_fill_keys(array_keys($this->configuredManagers), array()); + foreach ($builder->findByType('Doctrine\ORM\EntityRepository', FALSE) as $originalServiceName => $originalDef) { + if (is_string($originalDef)) { + $originalServiceName = $originalDef; + $originalDef = $builder->getDefinition($originalServiceName); + } + + if (strpos($originalServiceName, $this->name . '.') === 0) { + continue; // ignore + } + + $factory = $originalDef->getFactory() ? $originalDef->getFactory()->getEntity() : $originalDef->getClass(); + if (stripos($factory, '::getRepository') !== FALSE || stripos($factory, '::getDao') !== FALSE) { + continue; // ignore + } + + $factoryServiceName = $this->prefix('repositoryFactory.' . $originalServiceName); + $factoryDef = $builder->addDefinition($factoryServiceName, $originalDef) + ->setImplement('Kdyby\Doctrine\DI\IRepositoryFactory') + ->setParameters(array('Doctrine\ORM\EntityManagerInterface entityManager', 'Doctrine\ORM\Mapping\ClassMetadata classMetadata')) + ->setAutowired(FALSE); + $factoryStatement = $factoryDef->getFactory() ?: new Statement($factoryDef->getClass()); + $factoryStatement->arguments[0] = new Code\PhpLiteral('$entityManager'); + $factoryStatement->arguments[1] = new Code\PhpLiteral('$classMetadata'); + $factoryDef->setArguments($factoryStatement->arguments); + + $boundManagers = $this->getServiceBoundManagers($originalDef); + Validators::assert($boundManagers, 'list:1', 'bound manager'); + + if ($boundEntity = $originalDef->getTag(self::TAG_REPOSITORY_ENTITY)) { + if (!is_string($boundEntity) || !class_exists($boundEntity)) { + throw new Nette\Utils\AssertionException(sprintf('The entity "%s" for repository "%s" cannot be autoloaded.')); + } + $entityArgument = $boundEntity; + + } else { + $entityArgument = new Code\PhpLiteral('"%entityName%"'); + $this->postCompileRepositoriesQueue[$boundManagers[0]][] = [ltrim($originalDef->class, '\\'), $originalServiceName]; + } + + $builder->removeDefinition($originalServiceName); + $builder->addDefinition($originalServiceName) + ->setClass($originalDef->class) + ->setFactory(sprintf('@%s::getRepository', $this->configuredManagers[$boundManagers[0]]), array($entityArgument)); + + $serviceMap[$boundManagers[0]][$originalDef->class] = $factoryServiceName; + } + + foreach ($this->configuredManagers as $managerName => $_) { + $builder->getDefinition($this->prefix($managerName . '.repositoryFactory')) + ->addSetup('setServiceIdsMap', array( + $serviceMap[$managerName], + $this->prefix('repositoryFactory.' . $managerName . '.defaultRepositoryFactory') + )); + } + } + + + + /** + * @param Nette\DI\ServiceDefinition $def + * @return string[] + */ + protected function getServiceBoundManagers(Nette\DI\ServiceDefinition $def) + { + $builder = $this->getContainerBuilder(); + $boundManagers = $def->getTag(self::TAG_BIND_TO_MANAGER); + + return is_array($boundManagers) ? $boundManagers : array($builder->parameters[$this->name]['orm']['defaultEntityManager']); } @@ -646,6 +774,68 @@ public function afterCompile(Code\ClassType $class) $init->addBody($blueScreen . '->collapsePaths[] = ?;', array($dir)); } } + + $this->processRepositoryFactoryEntities($class); + } + + + + protected function processRepositoryFactoryEntities(Code\ClassType $class) + { + if (empty($this->postCompileRepositoriesQueue)) { + return; + } + + $dic = self::evalAndInstantiateContainer($class); + + foreach ($this->postCompileRepositoriesQueue as $manager => $items) { + $config = $this->managerConfigs[$manager]; + /** @var Kdyby\Doctrine\EntityManager $entityManager */ + $entityManager = $dic->getService($this->configuredManagers[$manager]); + /** @var Doctrine\ORM\Mapping\ClassMetadata $entityMetadata */ + $metadataFactory = $entityManager->getMetadataFactory(); + + $allMetadata = []; + foreach ($metadataFactory->getAllMetadata() as $entityMetadata) { + if ($config['defaultRepositoryClassName'] === $entityMetadata->customRepositoryClassName || empty($entityMetadata->customRepositoryClassName)) { + continue; + } + + $allMetadata[ltrim($entityMetadata->customRepositoryClassName, '\\')] = $entityMetadata; + } + + foreach ($items as $item) { + if (!isset($allMetadata[$item[0]])) { + throw new Nette\Utils\AssertionException(sprintf('Repository class %s have been found in DIC, but no entity has it assigned and it has no entity configured', $item[0])); + } + + $entityMetadata = $allMetadata[$item[0]]; + $serviceMethod = Nette\DI\Container::getMethodName($item[1]); + + $method = $class->getMethod($serviceMethod); + $methodBody = $method->getBody(); + $method->setBody(str_replace('"%entityName%"', Code\Helpers::format('?', $entityMetadata->getName()), $methodBody)); + } + } + } + + + + /** + * @param Code\ClassType $class + * @return Nette\DI\Container + */ + private static function evalAndInstantiateContainer(Code\ClassType $class) + { + $classCopy = clone $class; + $classCopy->setName($className = 'Kdyby_Doctrine_IamTheKingOfHackingNette_' . $class->getName() . '_' . rand()); + + $containerCode = "$classCopy"; + + return call_user_func(function () use ($className, $containerCode) { + eval($containerCode); + return new $className(); + }); } diff --git a/src/Kdyby/Doctrine/RepositoryFactory.php b/src/Kdyby/Doctrine/RepositoryFactory.php index 7950bc4c..c23bc9bd 100644 --- a/src/Kdyby/Doctrine/RepositoryFactory.php +++ b/src/Kdyby/Doctrine/RepositoryFactory.php @@ -35,6 +35,16 @@ class RepositoryFactory extends Nette\Object implements Doctrine\ORM\Repository\ */ private $repositoryList = array(); + /** + * @var array + */ + private $repositoryServicesMap = array(); + + /** + * @var string + */ + private $defaultRepositoryFactory; + public function __construct(Nette\DI\Container $serviceLocator) @@ -44,6 +54,18 @@ public function __construct(Nette\DI\Container $serviceLocator) + /** + * @param array $repositoryServicesMap [RepositoryType => repositoryServiceId] + * @param string $defaultRepositoryFactory + */ + public function setServiceIdsMap(array $repositoryServicesMap, $defaultRepositoryFactory) + { + $this->repositoryServicesMap = $repositoryServicesMap; + $this->defaultRepositoryFactory = $defaultRepositoryFactory; + } + + + /** * @param EntityManagerInterface|EntityManager $entityManager * @param string $entityName @@ -77,26 +99,35 @@ public function getRepository(EntityManagerInterface $entityManager, $entityName * * @param \Doctrine\ORM\EntityManagerInterface $entityManager The EntityManager instance. * @param Doctrine\ORM\Mapping\ClassMetadata $metadata - * @return Doctrine\Common\Persistence\ObjectRepository */ private function createRepository(EntityManagerInterface $entityManager, Doctrine\ORM\Mapping\ClassMetadata $metadata) { - $defaultRepository = $entityManager->getConfiguration()->getDefaultRepositoryClassName(); - $repositoryClassName = $metadata->customRepositoryClassName ?: $defaultRepository; - - if ($repositoryClassName === $defaultRepository) { - return new $repositoryClassName($entityManager, $metadata); + $defaultClass = $entityManager->getConfiguration()->getDefaultRepositoryClassName(); + $customClass = ltrim($metadata->customRepositoryClassName, '\\'); - } elseif (!$services = $this->serviceLocator->findByType($repositoryClassName)) { // todo: solve me in future, maybe just throw an exception? - return new $repositoryClassName($entityManager, $metadata); + if (empty($customClass) || $customClass === $defaultClass) { + $factory = $this->getRepositoryFactory($this->defaultRepositoryFactory); - } elseif (count($services) > 1) { // todo: solve me in future, maybe just throw an exception? - return new $repositoryClassName($entityManager, $metadata); + } elseif (isset($this->repositoryServicesMap[$customClass])) { + $factory = $this->getRepositoryFactory($this->repositoryServicesMap[$customClass]); } else { - return $this->serviceLocator->createService($services[0], array('entityManager' => $entityManager, 'metadata' => $metadata)); + return new $customClass($entityManager, $metadata); } + + return $factory->create($entityManager, $metadata); + } + + + + /** + * @param string $serviceName + * @return Kdyby\Doctrine\DI\IRepositoryFactory + */ + protected function getRepositoryFactory($serviceName) + { + return $this->serviceLocator->getService($serviceName); } } diff --git a/tests/KdybyTests/Doctrine/RepositoryFactory.phpt b/tests/KdybyTests/Doctrine/RepositoryFactory.phpt new file mode 100644 index 00000000..7f822911 --- /dev/null +++ b/tests/KdybyTests/Doctrine/RepositoryFactory.phpt @@ -0,0 +1,123 @@ + + * @package Kdyby\Doctrine + */ + +namespace KdybyTests\Doctrine; + +use Doctrine\ORM\Mapping\ClassMetadata; +use Kdyby; +use Nette; +use Tester; +use Tester\Assert; + +require_once __DIR__ . '/../bootstrap.php'; + + + +/** + * @author Filip Procházka + */ +class RepositoryFactoryTest extends Tester\TestCase +{ + + /** + * @param string $configFile + * @return \SystemContainer|Nette\DI\Container + */ + public function createContainer($configFile) + { + require_once __DIR__ . '/models/cms.php'; + + $config = new Nette\Configurator(); + $config->setTempDirectory(TEMP_DIR); + $config->addParameters(array('appDir' => $rootDir = __DIR__ . '/..', 'wwwDir' => $rootDir)); + $config->addConfig(__DIR__ . '/../nette-reset.neon', !isset($config->defaultExtensions['nette']) ? 'v23' : 'v22'); + $config->addConfig(__DIR__ . '/config/' . $configFile . '.neon'); + + return $config->createContainer(); + } + + + + public function testCustomRepositoryFactory() + { + if (!method_exists('Nette\DI\ContainerBuilder', 'findByType')) { + Tester\Environment::skip('Custom repositories require functionality that is available only in Nette ~2.3'); + } + + $container = $this->createContainer('repository-factory'); + + /** @var \KdybyTests\Doctrine\CmsAddressRepository $cmsAddressRepository */ + $cmsAddressRepository = $container->getByType('KdybyTests\Doctrine\CmsAddressRepository'); + Assert::type('KdybyTests\Doctrine\CmsAddressRepository', $cmsAddressRepository); + Assert::type('Kdyby\Doctrine\EntityRepository', $cmsAddressRepository); + Assert::same('KdybyTests\Doctrine\CmsAddress', $cmsAddressRepository->getClassName()); + Assert::same('KdybyTests\Doctrine\CmsAddress', $cmsAddressRepository->getClassMetadata()->getName()); + + /** @var \Kdyby\Doctrine\EntityManager $em */ + $em = $container->getByType('Kdyby\Doctrine\EntityManager'); + Assert::same($cmsAddressRepository, $em->getRepository('KdybyTests\Doctrine\CmsAddress')); + } + + + + public function testDefaultRepositoryFactory() + { + $container = $this->createContainer('repository-factory.default-class'); + + /** @var \Kdyby\Doctrine\EntityManager $em */ + $em = $container->getByType('Kdyby\Doctrine\EntityManager'); + + $cmsEmailRepository = $em->getRepository('KdybyTests\Doctrine\CmsEmail'); + Assert::same('Kdyby\Doctrine\EntityRepository', get_class($cmsEmailRepository)); + Assert::same('KdybyTests\Doctrine\CmsEmail', $cmsEmailRepository->getClassName()); + Assert::same('KdybyTests\Doctrine\CmsEmail', $cmsEmailRepository->getClassMetadata()->getName()); + } + + + + public function testCustomRepository_withoutService() + { + $container = $this->createContainer('repository-factory.without-service'); + + /** @var \Kdyby\Doctrine\EntityManager $em */ + $em = $container->getByType('Kdyby\Doctrine\EntityManager'); + + $cmsCommentRepository = $em->getRepository('KdybyTests\Doctrine\CmsComment'); + Assert::type('KdybyTests\Doctrine\CmsCommentRepository', $cmsCommentRepository); + Assert::type('Kdyby\Doctrine\EntityRepository', $cmsCommentRepository); + Assert::same('KdybyTests\Doctrine\CmsComment', $cmsCommentRepository->getClassName()); + Assert::same('KdybyTests\Doctrine\CmsComment', $cmsCommentRepository->getClassMetadata()->getName()); + } + + + + public function testManualRegistration() + { + $container = $this->createContainer('repository-factory.manual'); + + list($employeeRepositoryServiceName) = $container->findByType('KdybyTests\Doctrine\CmsEmployeeRepository'); + + /** @var \Kdyby\Doctrine\EntityManager $em */ + $em = $container->getByType('Kdyby\Doctrine\EntityManager'); + + $cmsEmployeeRepository = $em->getRepository('KdybyTests\Doctrine\CmsEmployee'); + Assert::type('Kdyby\Doctrine\EntityRepository', $cmsEmployeeRepository); + Assert::type('KdybyTests\Doctrine\CmsEmployeeRepository', $cmsEmployeeRepository); + Assert::same('KdybyTests\Doctrine\CmsEmployee', $cmsEmployeeRepository->getClassName()); + Assert::same('KdybyTests\Doctrine\CmsEmployee', $cmsEmployeeRepository->getClassMetadata()->getName()); + + Assert::false($container->isCreated($employeeRepositoryServiceName)); + Assert::same($cmsEmployeeRepository, $container->getService($employeeRepositoryServiceName)); + Assert::same($cmsEmployeeRepository, $container->getByType('KdybyTests\Doctrine\CmsEmployeeRepository')); + } + +} + +\run(new RepositoryFactoryTest()); diff --git a/tests/KdybyTests/Doctrine/config/repository-factory.default-class.neon b/tests/KdybyTests/Doctrine/config/repository-factory.default-class.neon new file mode 100644 index 00000000..377c9683 --- /dev/null +++ b/tests/KdybyTests/Doctrine/config/repository-factory.default-class.neon @@ -0,0 +1,6 @@ +kdyby.doctrine: + driver: pdo_sqlite + memory: true + metadata: + KdybyTests\Doctrine: annotations(%appDir%/Doctrine/models) + defaultRepositoryClassName: Kdyby\Doctrine\EntityRepository diff --git a/tests/KdybyTests/Doctrine/config/repository-factory.manual.neon b/tests/KdybyTests/Doctrine/config/repository-factory.manual.neon new file mode 100644 index 00000000..f019e141 --- /dev/null +++ b/tests/KdybyTests/Doctrine/config/repository-factory.manual.neon @@ -0,0 +1,16 @@ +kdyby.doctrine: + driver: pdo_sqlite + memory: true + metadata: + KdybyTests\Doctrine: annotations(%appDir%/Doctrine/models) + defaultRepositoryClassName: Kdyby\Doctrine\EntityRepository + + +services: + - + class: KdybyTests\Doctrine\CmsEmployeeRepository + factory: @Kdyby\Doctrine\EntityManager::getRepository(KdybyTests\Doctrine\CmsEmployee) + + - + class: KdybyTests\Doctrine\CmsGroupRepository + factory: @Kdyby\Doctrine\EntityManager::getDao(KdybyTests\Doctrine\CmsGroup) diff --git a/tests/KdybyTests/Doctrine/config/repository-factory.neon b/tests/KdybyTests/Doctrine/config/repository-factory.neon new file mode 100644 index 00000000..e2e50dd5 --- /dev/null +++ b/tests/KdybyTests/Doctrine/config/repository-factory.neon @@ -0,0 +1,19 @@ +kdyby.doctrine: + driver: pdo_sqlite + memory: true + metadata: + KdybyTests\Doctrine: annotations(%appDir%/Doctrine/models) + defaultRepositoryClassName: Kdyby\Doctrine\EntityRepository + + +services: + - KdybyTests\Doctrine\CmsAddressRepository + - KdybyTests\Doctrine\CmsArticleRepository + + - + class: KdybyTests\Doctrine\CmsEmployeeRepository + factory: @Kdyby\Doctrine\EntityManager::getRepository(KdybyTests\Doctrine\CmsEmployee) + + - + class: KdybyTests\Doctrine\CmsGroupRepository + factory: @Kdyby\Doctrine\EntityManager::getDao(KdybyTests\Doctrine\CmsGroup) diff --git a/tests/KdybyTests/Doctrine/config/repository-factory.without-service.neon b/tests/KdybyTests/Doctrine/config/repository-factory.without-service.neon new file mode 100644 index 00000000..377c9683 --- /dev/null +++ b/tests/KdybyTests/Doctrine/config/repository-factory.without-service.neon @@ -0,0 +1,6 @@ +kdyby.doctrine: + driver: pdo_sqlite + memory: true + metadata: + KdybyTests\Doctrine: annotations(%appDir%/Doctrine/models) + defaultRepositoryClassName: Kdyby\Doctrine\EntityRepository diff --git a/tests/KdybyTests/Doctrine/models/cms.php b/tests/KdybyTests/Doctrine/models/cms.php index 67649c1c..cdd2ce1d 100644 --- a/tests/KdybyTests/Doctrine/models/cms.php +++ b/tests/KdybyTests/Doctrine/models/cms.php @@ -25,7 +25,7 @@ interface ICmsAddress * CmsAddress * * @author Roman S. Borschel - * @ORM\Entity + * @ORM\Entity(repositoryClass="\KdybyTests\Doctrine\CmsAddressRepository") * @ORM\Table(name="cms_addresses") */ class CmsAddress implements ICmsAddress @@ -85,7 +85,7 @@ public function setUser(CmsUser $user) /** - * @ORM\Entity + * @ORM\Entity(repositoryClass="\KdybyTests\Doctrine\CmsArticleRepository") * @ORM\Table(name="cms_articles") */ class CmsArticle @@ -144,7 +144,7 @@ public function addComment(CmsComment $comment) /** - * @ORM\Entity + * @ORM\Entity(repositoryClass="\KdybyTests\Doctrine\CmsCommentRepository") * @ORM\Table(name="cms_comments") */ class CmsComment @@ -184,7 +184,7 @@ public function __toString() /** * CmsEmail * - * @ORM\Entity + * @ORM\Entity() * @ORM\Table(name="cms_emails") */ class CmsEmail @@ -215,7 +215,7 @@ class CmsEmail * Description of CmsEmployee * * @author robo - * @ORM\Entity + * @ORM\Entity(repositoryClass="KdybyTests\Doctrine\CmsEmployeeRepository") * @ORM\Table(name="cms_employees") */ class CmsEmployee @@ -247,7 +247,7 @@ class CmsEmployee * Description of CmsGroup * * @author robo - * @ORM\Entity + * @ORM\Entity(repositoryClass="KdybyTests\Doctrine\CmsGroupRepository") * @ORM\Table(name="cms_groups") */ class CmsGroup @@ -284,7 +284,7 @@ public function __construct($name = NULL) /** - * @ORM\Entity + * @ORM\Entity() * @ORM\Table(name="cms_phonenumbers") */ class CmsPhoneNumber @@ -305,7 +305,7 @@ class CmsPhoneNumber /** - * @ORM\Entity + * @ORM\Entity() * @ORM\Table(name="cms_users") */ class CmsUser @@ -461,7 +461,7 @@ public function setEmail(CmsEmail $email = NULL) /** - * @ORM\Entity + * @ORM\Entity() * @ORM\Table(name="cms_orders") */ class CmsOrder diff --git a/tests/KdybyTests/Doctrine/models/cms.repositories.php b/tests/KdybyTests/Doctrine/models/cms.repositories.php new file mode 100644 index 00000000..8fceda5c --- /dev/null +++ b/tests/KdybyTests/Doctrine/models/cms.repositories.php @@ -0,0 +1,44 @@ +