From a66fc03441cff3f9ad2047852d1dcbfed9f48683 Mon Sep 17 00:00:00 2001 From: Guilherme Blanco Date: Thu, 13 Jun 2013 23:53:53 -0400 Subject: [PATCH] Reducing dependency on RepositoryFactory by providing EntityManager as a getRepository argument. --- lib/Doctrine/ORM/EntityManager.php | 12 +++----- .../Repository/DefaultRepositoryFactory.php | 28 ++++++------------- .../ORM/Repository/RepositoryFactory.php | 12 ++------ 3 files changed, 15 insertions(+), 37 deletions(-) diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index 8ee39cf06..acaec984d 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -161,13 +161,9 @@ use Doctrine\Common\Util\ClassUtils; $this->metadataFactory->setEntityManager($this); $this->metadataFactory->setCacheDriver($this->config->getMetadataCacheImpl()); - $repositoryFactory = $config->getRepositoryFactory(); - - $this->repositoryFactory = $repositoryFactory; - $this->repositoryFactory->setEntityManager($this); - - $this->unitOfWork = new UnitOfWork($this); - $this->proxyFactory = new ProxyFactory( + $this->repositoryFactory = $config->getRepositoryFactory(); + $this->unitOfWork = new UnitOfWork($this); + $this->proxyFactory = new ProxyFactory( $this, $config->getProxyDir(), $config->getProxyNamespace(), @@ -767,7 +763,7 @@ use Doctrine\Common\Util\ClassUtils; */ public function getRepository($entityName) { - return $this->repositoryFactory->getRepository($entityName); + return $this->repositoryFactory->getRepository($this, $entityName); } /** diff --git a/lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php b/lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php index b97424810..0caab1b63 100644 --- a/lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php +++ b/lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php @@ -36,23 +36,10 @@ class DefaultRepositoryFactory implements RepositoryFactory */ private $repositoryList = array(); - /** - * @var \Doctrine\ORM\EntityManagerInterface - */ - protected $entityManager; - /** * {@inheritdoc} */ - public function setEntityManager(EntityManagerInterface $entityManager) - { - $this->entityManager = $entityManager; - } - - /** - * {@inheritdoc} - */ - public function getRepository($entityName) + public function getRepository(EntityManagerInterface $entityManager, $entityName) { $entityName = ltrim($entityName, '\\'); @@ -60,7 +47,7 @@ class DefaultRepositoryFactory implements RepositoryFactory return $this->repositoryList[$entityName]; } - $repository = $this->createRepository($entityName); + $repository = $this->createRepository($entityManager, $entityName); $this->repositoryList[$entityName] = $repository; @@ -70,20 +57,21 @@ class DefaultRepositoryFactory implements RepositoryFactory /** * Create a new repository instance for an entity class. * - * @param string $entityName The name of the entity. + * @param \Doctrine\ORM\EntityManagerInterface $entityManager The EntityManager instance. + * @param string $entityName The name of the entity. * * @return \Doctrine\ORM\EntityRepository */ - protected function createRepository($entityName) + protected function createRepository(EntityManagerInterface $entityManager, $entityName) { - $metadata = $this->entityManager->getClassMetadata($entityName); + $metadata = $entityManager->getClassMetadata($entityName); $repositoryClassName = $metadata->customRepositoryClassName; if ($repositoryClassName === null) { - $configuration = $this->entityManager->getConfiguration(); + $configuration = $entityManager->getConfiguration(); $repositoryClassName = $configuration->getDefaultRepositoryClassName(); } - return new $repositoryClassName($this->entityManager, $metadata); + return new $repositoryClassName($entityManager, $metadata); } } \ No newline at end of file diff --git a/lib/Doctrine/ORM/Repository/RepositoryFactory.php b/lib/Doctrine/ORM/Repository/RepositoryFactory.php index cd3e20a26..faf7d6c81 100644 --- a/lib/Doctrine/ORM/Repository/RepositoryFactory.php +++ b/lib/Doctrine/ORM/Repository/RepositoryFactory.php @@ -29,19 +29,13 @@ use Doctrine\ORM\EntityManagerInterface; */ interface RepositoryFactory { - /** - * Set the entity manager. - * - * @param \Doctrine\ORM\EntityManagerInterface $entityManager - */ - public function setEntityManager(EntityManagerInterface $entityManager); - /** * Gets the repository for an entity class. * - * @param string $entityName The name of the entity. + * @param \Doctrine\ORM\EntityManagerInterface $entityManager The EntityManager instance. + * @param string $entityName The name of the entity. * * @return \Doctrine\ORM\EntityRepository */ - public function getRepository($entityName); + public function getRepository(EntityManagerInterface $entityManager, $entityName); } \ No newline at end of file