Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Implemented support for RepositoryFactory. #695

Merged
merged 5 commits into from

7 participants

@guilhermeblanco

This allows anyone to override the default behavior to load Repositories.

lib/Doctrine/ORM/Configuration.php
((22 lines not shown))
use Doctrine\ORM\Mapping\EntityListenerResolver;
-use Doctrine\ORM\Mapping\DefaultEntityListenerResolver;
-use Doctrine\Common\Annotations\SimpleAnnotationReader;
-use Doctrine\Common\Annotations\CachedReader;
+use Doctrine\ORM\Mapping\NamingStrategy;
+use Doctrine\ORM\Mapping\QuoteStrategy;
+use Doctrine\ORM\Repository\DefaultRepositoryFactory;
+use Doctrine\ORM\Repository\RepositoryFactoryInterface;
@FabioBatSilva Owner

Should be Doctrine\ORM\Repository\RepositoryFactory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/Doctrine/ORM/Configuration.php
@@ -779,4 +781,28 @@ public function getEntityListenerResolver()
return $this->_attributes['entityListenerResolver'];
}
+
+ /**
+ * Set the entity repository factory.
+ *
+ * @since 2.5
+ * @param \Doctrine\ORM\Repository\RepositoryFactoryInterface $repositoryFactory
+ */
+ public function setRepositoryFactory(RepositoryFactoryInterface $repositoryFactory)
@FabioBatSilva Owner

Should be \Doctrine\ORM\Repository\RepositoryFactory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/Doctrine/ORM/Repository/RepositoryFactory.php
((22 lines not shown))
+use Doctrine\ORM\EntityManagerInterface;
+
+/**
+ * Interface for entity repository factory.
+ *
+ * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
+ * @since 2.5
+ */
+interface RepositoryFactory
+{
+ /**
+ * Set the entity manager.
+ *
+ * @param \Doctrine\ORM\EntityManagerInterface $entityManager
+ */
+ public function setEntityManager(EntityManagerInterface $entityManager);
@FabioBatSilva Owner

Just thinking - Maybe we should give EntityManager as parameter to getRepository.
Seems more clear for me keep the factory method aware about the EM that's asking for a repository.

@guilhermeblanco Owner

Good idea. It actually makes code cleaner too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/Doctrine/ORM/Repository/RepositoryFactory.php
((29 lines not shown))
+ */
+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.
+ *
+ * @return \Doctrine\ORM\EntityRepository
@FabioBatSilva Owner

should be @return \Doctrine\Common\Persistence\ObjectRepository

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php
((20 lines not shown))
+namespace Doctrine\ORM\Repository;
+
+use Doctrine\ORM\EntityManagerInterface;
+
+/**
+ * This factory is used to create default repository objects for entities at runtime.
+ *
+ * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
+ * @since 2.5
+ */
+class DefaultRepositoryFactory implements RepositoryFactory
+{
+ /**
+ * The list of EntityRepository instances.
+ *
+ * @var array<\Doctrine\ORM\EntityRepository>
@FabioBatSilva Owner

@var array<\Doctrine\Common\Persistence\ObjectRepository>

@guilhermeblanco Owner

Not really. This is tied to ORM only so far.

@FabioBatSilva Owner

I've mentioned because we already support \Doctrine\Common\Persistence\ObjectRepository as default repository.

@guilhermeblanco Owner

Ok... not a huge deal tbh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Guilherme Bl... added some commits
Guilherme Blanco Reducing dependency on RepositoryFactory by providing EntityManager a…
…s a getRepository argument.
a66fc03
Guilherme Blanco Reduced granularity of DefaultRepositoryFactory reference to ObjectRe…
…pository instances, in cases where consumers are completely rewrote EntityRepository.
3488049
@deeky666 deeky666 commented on the diff
lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php
((57 lines not shown))
+ /**
+ * Create a new repository instance for an entity class.
+ *
+ * @param \Doctrine\ORM\EntityManagerInterface $entityManager The EntityManager instance.
+ * @param string $entityName The name of the entity.
+ *
+ * @return \Doctrine\Common\Persistence\ObjectRepository
+ */
+ protected function createRepository(EntityManagerInterface $entityManager, $entityName)
+ {
+ $metadata = $entityManager->getClassMetadata($entityName);
+ $repositoryClassName = $metadata->customRepositoryClassName;
+
+ if ($repositoryClassName === null) {
+ $configuration = $entityManager->getConfiguration();
+ $repositoryClassName = $configuration->getDefaultRepositoryClassName();
@deeky666 Collaborator

I think you can make one assignment instead of two here $repositoryClassName = $entityManager->getConfiguration()->getDefaultRepositoryClassName()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@guilhermeblanco guilhermeblanco merged commit 7903a2b into from
@Ocramius Ocramius commented on the diff
lib/Doctrine/ORM/Configuration.php
((11 lines not shown))
+ public function setRepositoryFactory(RepositoryFactory $repositoryFactory)
+ {
+ $this->_attributes['repositoryFactory'] = $repositoryFactory;
+ }
+
+ /**
+ * Get the entity repository factory.
+ *
+ * @since 2.4
+ * @return \Doctrine\ORM\Repository\RepositoryFactory
+ */
+ public function getRepositoryFactory()
+ {
+ return isset($this->_attributes['repositoryFactory'])
+ ? $this->_attributes['repositoryFactory']
+ : new DefaultRepositoryFactory();
@Ocramius Owner

Should be : $this->_attributes['repositoryFactory'] = new DefaultRepositoryFactory(); I guess

@guilhermeblanco Owner

it doesn't matter tbh.... =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Ocramius Ocramius commented on the diff
lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php
((29 lines not shown))
+ */
+class DefaultRepositoryFactory implements RepositoryFactory
+{
+ /**
+ * The list of EntityRepository instances.
+ *
+ * @var array<\Doctrine\Common\Persistence\ObjectRepository>
+ */
+ private $repositoryList = array();
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getRepository(EntityManagerInterface $entityManager, $entityName)
+ {
+ $entityName = ltrim($entityName, '\\');
@Ocramius Owner

We should probably start using the metadata factory for this kind of stuff, since it allows fetching repositories by entity alias, interface names (if you use weird listeners on the load metadata events) etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Ocramius Ocramius commented on the diff
lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php
((35 lines not shown))
+ * @var array<\Doctrine\Common\Persistence\ObjectRepository>
+ */
+ private $repositoryList = array();
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getRepository(EntityManagerInterface $entityManager, $entityName)
+ {
+ $entityName = ltrim($entityName, '\\');
+
+ if (isset($this->repositoryList[$entityName])) {
+ return $this->repositoryList[$entityName];
+ }
+
+ $repository = $this->createRepository($entityManager, $entityName);
@Ocramius Owner

This and the two subsequent statements can be inlined

@guilhermeblanco Owner

Makes code harder to understand... I'd avoid relying on magical language behavior of PHP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Ocramius Ocramius commented on the diff
lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php
((55 lines not shown))
+ }
+
+ /**
+ * Create a new repository instance for an entity class.
+ *
+ * @param \Doctrine\ORM\EntityManagerInterface $entityManager The EntityManager instance.
+ * @param string $entityName The name of the entity.
+ *
+ * @return \Doctrine\Common\Persistence\ObjectRepository
+ */
+ protected function createRepository(EntityManagerInterface $entityManager, $entityName)
+ {
+ $metadata = $entityManager->getClassMetadata($entityName);
+ $repositoryClassName = $metadata->customRepositoryClassName;
+
+ if ($repositoryClassName === null) {
@Ocramius Owner

Yoda: Looking? Found someone, you have, I would say, hmmm?

@guilhermeblanco Owner

Not really... Yoda conditions are "null repository class name is..." (null === $var)

still, you should invert left and right side, to avoid typo -> assignment.

@beberlei Owner

we dont do yoda just for the fun of it. This discussion is wasting our all time :) The code works, why bother?

@Ocramius Owner

If everyone bothers about CS consistency I'll bother too :p

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Ocramius Ocramius commented on the diff
lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php
((62 lines not shown))
+ *
+ * @return \Doctrine\Common\Persistence\ObjectRepository
+ */
+ protected function createRepository(EntityManagerInterface $entityManager, $entityName)
+ {
+ $metadata = $entityManager->getClassMetadata($entityName);
+ $repositoryClassName = $metadata->customRepositoryClassName;
+
+ if ($repositoryClassName === null) {
+ $configuration = $entityManager->getConfiguration();
+ $repositoryClassName = $configuration->getDefaultRepositoryClassName();
+ }
+
+ return new $repositoryClassName($entityManager, $metadata);
+ }
+}
@Ocramius Owner

EOF EOL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Ocramius Ocramius commented on the diff
lib/Doctrine/ORM/Repository/RepositoryFactory.php
((26 lines not shown))
+ *
+ * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
+ * @since 2.4
+ */
+interface RepositoryFactory
+{
+ /**
+ * Gets the repository for an entity class.
+ *
+ * @param \Doctrine\ORM\EntityManagerInterface $entityManager The EntityManager instance.
+ * @param string $entityName The name of the entity.
+ *
+ * @return \Doctrine\Common\Persistence\ObjectRepository
+ */
+ public function getRepository(EntityManagerInterface $entityManager, $entityName);
+}
@Ocramius Owner

EOF EOL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Ocramius
Owner

Uh... that new class doesn't come with tests :X

Also: I noticed the PR was already merged - shall I do one with my suggested fixes?

@guilhermeblanco

@Ocramius feel free to provide another pull request to update the ones I haven't commented. =)

@guilhermeblanco guilhermeblanco deleted the branch
@stof

@beberlei is it really intended to merge such changes while 2.4-RC1 has already been released but the 2.4 branch is not created yet ? I find it weird to introduce new features while being in RC phase

@Ocramius
Owner

@stof agreed - should be reverted here :\

@stof

@Ocramius we may not need to revert it if @beberlei creates the 2.4 branch based on the commit before the merge. However, we will need to bump the @since annotation in this class

@mnapoli mnapoli referenced this pull request in mnapoli/PHP-DI
Open

Integration with Doctrine's RepositoryFactory #81

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 14, 2013
  1. Implemented support for RepositoryFactory.

    Guilherme Blanco authored
  2. Fixed wrong interface.

    Guilherme Blanco authored
  3. Reducing dependency on RepositoryFactory by providing EntityManager a…

    Guilherme Blanco authored
    …s a getRepository argument.
  4. Reduced granularity of DefaultRepositoryFactory reference to ObjectRe…

    Guilherme Blanco authored
    …pository instances, in cases where consumers are completely rewrote EntityRepository.
  5. Updated since php doc tag.

    Guilherme Blanco authored
This page is out of date. Refresh to see the latest.
View
46 lib/Doctrine/ORM/Configuration.php
@@ -19,20 +19,22 @@
namespace Doctrine\ORM;
-use Doctrine\Common\Cache\Cache;
-use Doctrine\Common\Cache\ArrayCache;
-use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\Common\Annotations\AnnotationReader;
+use Doctrine\Common\Annotations\AnnotationRegistry;
+use Doctrine\Common\Annotations\CachedReader;
+use Doctrine\Common\Annotations\SimpleAnnotationReader;
+use Doctrine\Common\Cache\ArrayCache;
+use Doctrine\Common\Cache\Cache;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
-use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
-use Doctrine\ORM\Mapping\QuoteStrategy;
-use Doctrine\ORM\Mapping\DefaultQuoteStrategy;
-use Doctrine\ORM\Mapping\NamingStrategy;
+use Doctrine\ORM\Mapping\DefaultEntityListenerResolver;
use Doctrine\ORM\Mapping\DefaultNamingStrategy;
+use Doctrine\ORM\Mapping\DefaultQuoteStrategy;
+use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Doctrine\ORM\Mapping\EntityListenerResolver;
-use Doctrine\ORM\Mapping\DefaultEntityListenerResolver;
-use Doctrine\Common\Annotations\SimpleAnnotationReader;
-use Doctrine\Common\Annotations\CachedReader;
+use Doctrine\ORM\Mapping\NamingStrategy;
+use Doctrine\ORM\Mapping\QuoteStrategy;
+use Doctrine\ORM\Repository\DefaultRepositoryFactory;
+use Doctrine\ORM\Repository\RepositoryFactory;
/**
* Configuration container for all configuration options of Doctrine.
@@ -779,4 +781,28 @@ public function getEntityListenerResolver()
return $this->_attributes['entityListenerResolver'];
}
+
+ /**
+ * Set the entity repository factory.
+ *
+ * @since 2.4
+ * @param \Doctrine\ORM\Repository\RepositoryFactory $repositoryFactory
+ */
+ public function setRepositoryFactory(RepositoryFactory $repositoryFactory)
+ {
+ $this->_attributes['repositoryFactory'] = $repositoryFactory;
+ }
+
+ /**
+ * Get the entity repository factory.
+ *
+ * @since 2.4
+ * @return \Doctrine\ORM\Repository\RepositoryFactory
+ */
+ public function getRepositoryFactory()
+ {
+ return isset($this->_attributes['repositoryFactory'])
+ ? $this->_attributes['repositoryFactory']
+ : new DefaultRepositoryFactory();
@Ocramius Owner

Should be : $this->_attributes['repositoryFactory'] = new DefaultRepositoryFactory(); I guess

@guilhermeblanco Owner

it doesn't matter tbh.... =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ }
}
View
46 lib/Doctrine/ORM/EntityManager.php
@@ -86,13 +86,6 @@
private $metadataFactory;
/**
- * The EntityRepository instances.
- *
- * @var array
- */
- private $repositories = array();
-
- /**
* The UnitOfWork used to coordinate object-level transactions.
*
* @var \Doctrine\ORM\UnitOfWork
@@ -121,6 +114,13 @@
private $proxyFactory;
/**
+ * The repository factory used to create dynamic repositories.
+ *
+ * @var \Doctrine\ORM\Repository\RepositoryFactory
+ */
+ private $repositoryFactory;
+
+ /**
* The expression builder instance used to generate query expressions.
*
* @var \Doctrine\ORM\Query\Expr
@@ -151,9 +151,9 @@
*/
protected function __construct(Connection $conn, Configuration $config, EventManager $eventManager)
{
- $this->conn = $conn;
- $this->config = $config;
- $this->eventManager = $eventManager;
+ $this->conn = $conn;
+ $this->config = $config;
+ $this->eventManager = $eventManager;
$metadataFactoryClassName = $config->getClassMetadataFactoryName();
@@ -161,8 +161,9 @@ protected function __construct(Connection $conn, Configuration $config, EventMan
$this->metadataFactory->setEntityManager($this);
$this->metadataFactory->setCacheDriver($this->config->getMetadataCacheImpl());
- $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(),
@@ -758,28 +759,11 @@ public function lock($entity, $lockMode, $lockVersion = null)
*
* @param string $entityName The name of the entity.
*
- * @return EntityRepository The repository class.
+ * @return \Doctrine\ORM\EntityRepository The repository class.
*/
public function getRepository($entityName)
{
- $entityName = ltrim($entityName, '\\');
-
- if (isset($this->repositories[$entityName])) {
- return $this->repositories[$entityName];
- }
-
- $metadata = $this->getClassMetadata($entityName);
- $repositoryClassName = $metadata->customRepositoryClassName;
-
- if ($repositoryClassName === null) {
- $repositoryClassName = $this->config->getDefaultRepositoryClassName();
- }
-
- $repository = new $repositoryClassName($this, $metadata);
-
- $this->repositories[$entityName] = $repository;
-
- return $repository;
+ return $this->repositoryFactory->getRepository($this, $entityName);
}
/**
View
77 lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php
@@ -0,0 +1,77 @@
+<?php
+/*
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the MIT license. For more information, see
+ * <http://www.doctrine-project.org>.
+ */
+
+namespace Doctrine\ORM\Repository;
+
+use Doctrine\ORM\EntityManagerInterface;
+
+/**
+ * This factory is used to create default repository objects for entities at runtime.
+ *
+ * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
+ * @since 2.4
+ */
+class DefaultRepositoryFactory implements RepositoryFactory
+{
+ /**
+ * The list of EntityRepository instances.
+ *
+ * @var array<\Doctrine\Common\Persistence\ObjectRepository>
+ */
+ private $repositoryList = array();
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getRepository(EntityManagerInterface $entityManager, $entityName)
+ {
+ $entityName = ltrim($entityName, '\\');
@Ocramius Owner

We should probably start using the metadata factory for this kind of stuff, since it allows fetching repositories by entity alias, interface names (if you use weird listeners on the load metadata events) etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+ if (isset($this->repositoryList[$entityName])) {
+ return $this->repositoryList[$entityName];
+ }
+
+ $repository = $this->createRepository($entityManager, $entityName);
@Ocramius Owner

This and the two subsequent statements can be inlined

@guilhermeblanco Owner

Makes code harder to understand... I'd avoid relying on magical language behavior of PHP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+ $this->repositoryList[$entityName] = $repository;
+
+ return $repository;
+ }
+
+ /**
+ * Create a new repository instance for an entity class.
+ *
+ * @param \Doctrine\ORM\EntityManagerInterface $entityManager The EntityManager instance.
+ * @param string $entityName The name of the entity.
+ *
+ * @return \Doctrine\Common\Persistence\ObjectRepository
+ */
+ protected function createRepository(EntityManagerInterface $entityManager, $entityName)
+ {
+ $metadata = $entityManager->getClassMetadata($entityName);
+ $repositoryClassName = $metadata->customRepositoryClassName;
+
+ if ($repositoryClassName === null) {
@Ocramius Owner

Yoda: Looking? Found someone, you have, I would say, hmmm?

@guilhermeblanco Owner

Not really... Yoda conditions are "null repository class name is..." (null === $var)

still, you should invert left and right side, to avoid typo -> assignment.

@beberlei Owner

we dont do yoda just for the fun of it. This discussion is wasting our all time :) The code works, why bother?

@Ocramius Owner

If everyone bothers about CS consistency I'll bother too :p

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ $configuration = $entityManager->getConfiguration();
+ $repositoryClassName = $configuration->getDefaultRepositoryClassName();
@deeky666 Collaborator

I think you can make one assignment instead of two here $repositoryClassName = $entityManager->getConfiguration()->getDefaultRepositoryClassName()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ }
+
+ return new $repositoryClassName($entityManager, $metadata);
+ }
+}
@Ocramius Owner

EOF EOL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
View
41 lib/Doctrine/ORM/Repository/RepositoryFactory.php
@@ -0,0 +1,41 @@
+<?php
+/*
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the MIT license. For more information, see
+ * <http://www.doctrine-project.org>.
+ */
+
+namespace Doctrine\ORM\Repository;
+
+use Doctrine\ORM\EntityManagerInterface;
+
+/**
+ * Interface for entity repository factory.
+ *
+ * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
+ * @since 2.4
+ */
+interface RepositoryFactory
+{
+ /**
+ * Gets the repository for an entity class.
+ *
+ * @param \Doctrine\ORM\EntityManagerInterface $entityManager The EntityManager instance.
+ * @param string $entityName The name of the entity.
+ *
+ * @return \Doctrine\Common\Persistence\ObjectRepository
+ */
+ public function getRepository(EntityManagerInterface $entityManager, $entityName);
+}
@Ocramius Owner

EOF EOL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
View
5 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2359Test.php
@@ -19,18 +19,21 @@ public function testIssue()
$mockDriver = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\Driver\\MappingDriver');
$mockMetadata = $this->getMock('Doctrine\\ORM\\Mapping\\ClassMetadata', array(), array(), '', false);
$entityManager = $this->getMock('Doctrine\\ORM\\EntityManager', array(), array(), '', false);
+
/* @var $metadataFactory \Doctrine\ORM\Mapping\ClassMetadataFactory|\PHPUnit_Framework_MockObject_MockObject */
$metadataFactory = $this->getMock(
'Doctrine\\ORM\\Mapping\\ClassMetadataFactory',
array('newClassMetadataInstance', 'wakeupReflection')
);
- $configuration = $this->getMock('Doctrine\\ORM\\Configuration');
+
+ $configuration = $this->getMock('Doctrine\\ORM\\Configuration', array('getMetadataDriverImpl'));
$connection = $this->getMock('Doctrine\\DBAL\\Connection', array(), array(), '', false);
$configuration
->expects($this->any())
->method('getMetadataDriverImpl')
->will($this->returnValue($mockDriver));
+
$entityManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($configuration));
$entityManager->expects($this->any())->method('getConnection')->will($this->returnValue($connection));
$entityManager
Something went wrong with that request. Please try again.