Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

[Doctrine] added a default implementation of the ManagerRegistry #2244

Merged
merged 8 commits into from

2 participants

@lsmith77
Collaborator

Bug fix: no
Feature addition: yes
Backwards compatibility break: yes (minor change in the interface see below)
Symfony2 tests pass: yes
Fixes the following tickets: -

added a default implementation of the ManagerRegistry integrating the container

attempted to maintain BC as good as possible, but RegistryInterface::getRepository() had to be dropped from RegistryInterface. Its still part of the ManagerRegistry, so its only a BC break for people using RegistryInterface to create their own implementation as I ran into https://bugs.php.net/bug.php?id=43200

all implementation (ORM/ODM) will need to match the changes to the ClassMetadataFactory interface

ORM, PHPCR, CouchDB have been upgraded already.
The Bundles also need to be updated. ORM is covered with this PR, I have a PR ready for PHPCR:
symfony-cmf/symfony-cmf#108

also note that before merging the change to vendors.php needs to be fixed to point to the right repo again

For MongoDB it currently does not yet have a registry and I can take care of CouchDB once this is all merged.

@lsmith77 lsmith77 added a default implementation of the ManagerRegistry integrating the…
… container

attempted to maintain BC as good as possible, but RegistryInterface::getRepository() had to be dropped from RegistryInterface. Its still part of the ManagerRegistry, so its only a BC break for people using RegistryInterface to create their own implementation
13c2f33
@lsmith77
Collaborator

still a few failing tests and details still need to be discussed ..

@lsmith77
Collaborator

ok .. tests are passing now

@lsmith77
Collaborator

ok Doctrine/ORM updates are done .. PR updated .. ready to be merged.

@fabpot fabpot referenced this pull request from a commit
@fabpot fabpot merged branch lsmith77/ManagerRegistry (PR #2244)
Commits
-------

dc5772d use ORM master
4364463 use doctrine-common master
55b572d fixed getting the alias for a namespace
2b89e15 use getObjectNamespace() in getEntityNamespace()
0217a0e updated base class name
e8f3c21 updated vendors to point to lsmith77's fork of doctrine-common until its merged
6e87d01 fix tests
13c2f33 added a default implementation of the ManagerRegistry integrating the container

Discussion
----------

[Doctrine] added a default implementation of the ManagerRegistry

Bug fix: no
Feature addition: yes
Backwards compatibility break: yes (minor change in the interface see below)
Symfony2 tests pass: yes
Fixes the following tickets: -

added a default implementation of the ManagerRegistry integrating the container

attempted to maintain BC as good as possible, but RegistryInterface::getRepository() had to be dropped from RegistryInterface. Its still part of the ManagerRegistry, so its only a BC break for people using RegistryInterface to create their own implementation as I ran into https://bugs.php.net/bug.php?id=43200

all implementation (ORM/ODM) will need to match the changes to the ClassMetadataFactory interface

ORM, PHPCR, CouchDB have been upgraded already.
The Bundles also need to be updated. ORM is covered with this PR, I have a PR ready for PHPCR:
symfony-cmf/symfony-cmf#108

also note that before merging the change to vendors.php needs to be fixed to point to the right repo again

For MongoDB it currently does not yet have a registry and I can take care of CouchDB once this is all merged.

---------------------------------------------------------------------------

by lsmith77 at 2011/09/23 00:40:07 -0700

still a few failing tests and details still need to be discussed ..

---------------------------------------------------------------------------

by lsmith77 at 2011/09/23 00:53:23 -0700

ok .. tests are passing now

---------------------------------------------------------------------------

by lsmith77 at 2011/10/11 10:27:52 -0700

ok Doctrine/ORM updates are done .. PR updated .. ready to be merged.
ec45893
@fabpot fabpot merged commit dc5772d into symfony:master
@mmucklo mmucklo referenced this pull request from a commit
@fabpot fabpot merged branch lsmith77/ManagerRegistry (PR #2244)
Commits
-------

dc5772d use ORM master
4364463 use doctrine-common master
55b572d fixed getting the alias for a namespace
2b89e15 use getObjectNamespace() in getEntityNamespace()
0217a0e updated base class name
e8f3c21 updated vendors to point to lsmith77's fork of doctrine-common until its merged
6e87d01 fix tests
13c2f33 added a default implementation of the ManagerRegistry integrating the container

Discussion
----------

[Doctrine] added a default implementation of the ManagerRegistry

Bug fix: no
Feature addition: yes
Backwards compatibility break: yes (minor change in the interface see below)
Symfony2 tests pass: yes
Fixes the following tickets: -

added a default implementation of the ManagerRegistry integrating the container

attempted to maintain BC as good as possible, but RegistryInterface::getRepository() had to be dropped from RegistryInterface. Its still part of the ManagerRegistry, so its only a BC break for people using RegistryInterface to create their own implementation as I ran into https://bugs.php.net/bug.php?id=43200

all implementation (ORM/ODM) will need to match the changes to the ClassMetadataFactory interface

ORM, PHPCR, CouchDB have been upgraded already.
The Bundles also need to be updated. ORM is covered with this PR, I have a PR ready for PHPCR:
symfony-cmf/symfony-cmf#108

also note that before merging the change to vendors.php needs to be fixed to point to the right repo again

For MongoDB it currently does not yet have a registry and I can take care of CouchDB once this is all merged.

---------------------------------------------------------------------------

by lsmith77 at 2011/09/23 00:40:07 -0700

still a few failing tests and details still need to be discussed ..

---------------------------------------------------------------------------

by lsmith77 at 2011/09/23 00:53:23 -0700

ok .. tests are passing now

---------------------------------------------------------------------------

by lsmith77 at 2011/10/11 10:27:52 -0700

ok Doctrine/ORM updates are done .. PR updated .. ready to be merged.
291a3b7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 23, 2011
  1. @lsmith77

    added a default implementation of the ManagerRegistry integrating the…

    lsmith77 authored
    … container
    
    attempted to maintain BC as good as possible, but RegistryInterface::getRepository() had to be dropped from RegistryInterface. Its still part of the ManagerRegistry, so its only a BC break for people using RegistryInterface to create their own implementation
  2. @lsmith77

    fix tests

    lsmith77 authored
  3. @lsmith77
Commits on Sep 25, 2011
  1. @lsmith77

    updated base class name

    lsmith77 authored
  2. @lsmith77
  3. @lsmith77
Commits on Oct 11, 2011
  1. @lsmith77

    use doctrine-common master

    lsmith77 authored
  2. @lsmith77

    use ORM master

    lsmith77 authored
This page is out of date. Refresh to see the latest.
View
53 src/Symfony/Bridge/Doctrine/ManagerRegistry.php
@@ -0,0 +1,53 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Bridge\Doctrine;
+
+use Symfony\Component\DependencyInjection\ContainerAwareInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+use Doctrine\Common\Persistence\AbstractManagerRegistry;
+
+/**
+ * References Doctrine connections and entity/document managers.
+ *
+ * @author Lukas Kahwe Smith <smith@pooteeweet.org>
+ */
+abstract class ManagerRegistry extends AbstractManagerRegistry implements ContainerAwareInterface
+{
+ /**
+ * @var ContainerInterface
+ */
+ protected $container;
+
+ /**
+ * @inheritdoc
+ */
+ protected function getService($name)
+ {
+ return $this->container->get($name);
+ }
+
+ /**
+ * @inheritdoc
+ */
+ protected function resetService($name)
+ {
+ $this->container->set($name, null);
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function setContainer(ContainerInterface $container = null)
+ {
+ $this->container = $container;
+ }
+}
View
44 src/Symfony/Bridge/Doctrine/RegistryInterface.php
@@ -15,44 +15,16 @@
use Doctrine\ORM\Configuration;
use Doctrine\ORM\ORMException;
+use Doctrine\Common\Persistence\ConnectionRegistry as ConnectionRegistryInterface;
+
/**
* References Doctrine connections and entity managers.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
-interface RegistryInterface
+interface RegistryInterface extends ConnectionRegistryInterface
{
/**
- * Gets the default connection name.
- *
- * @return string The default connection name
- */
- function getDefaultConnectionName();
-
- /**
- * Gets the named connection.
- *
- * @param string $name The connection name (null for the default one)
- *
- * @return Connection
- */
- function getConnection($name = null);
-
- /**
- * Gets an array of all registered connections
- *
- * @return array An array of Connection instances
- */
- function getConnections();
-
- /**
- * Gets all connection names.
- *
- * @return array An array of connection names
- */
- function getConnectionNames();
-
- /**
* Gets the default entity manager name.
*
* @return string The default entity manager name
@@ -115,16 +87,6 @@ function getEntityNamespace($alias);
function getEntityManagerNames();
/**
- * Gets the EntityRepository for an entity.
- *
- * @param string $entityName The name of the entity.
- * @param string $entityManagerNAme The entity manager name (null for the default one)
- *
- * @return Doctrine\ORM\EntityRepository
- */
- function getRepository($entityName, $entityManagerName = null);
-
- /**
* Gets the entity manager associated with a given class.
*
* @param string $class A Doctrine Entity class name
View
153 src/Symfony/Bundle/DoctrineBundle/Registry.php
@@ -13,6 +13,7 @@
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Bridge\Doctrine\RegistryInterface;
+use Symfony\Bridge\Doctrine\ManagerRegistry;
use Doctrine\DBAL\Connection;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\ORMException;
@@ -22,86 +23,25 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*/
-class Registry implements RegistryInterface
+class Registry extends ManagerRegistry implements RegistryInterface
{
- private $container;
- private $connections;
- private $entityManagers;
- private $defaultConnection;
- private $defaultEntityManager;
-
public function __construct(ContainerInterface $container, array $connections, array $entityManagers, $defaultConnection, $defaultEntityManager)
{
- $this->container = $container;
- $this->connections = $connections;
- $this->entityManagers = $entityManagers;
- $this->defaultConnection = $defaultConnection;
- $this->defaultEntityManager = $defaultEntityManager;
- }
-
- /**
- * Gets the default connection name.
- *
- * @return string The default connection name
- */
- public function getDefaultConnectionName()
- {
- return $this->defaultConnection;
- }
-
- /**
- * Gets the named connection.
- *
- * @param string $name The connection name (null for the default one)
- *
- * @return Connection
- */
- public function getConnection($name = null)
- {
- if (null === $name) {
- $name = $this->defaultConnection;
- }
-
- if (!isset($this->connections[$name])) {
- throw new \InvalidArgumentException(sprintf('Doctrine Connection named "%s" does not exist.', $name));
- }
+ $this->setContainer($container);
- return $this->container->get($this->connections[$name]);
- }
-
- /**
- * Gets an array of all registered connections
- *
- * @return array An array of Connection instances
- */
- public function getConnections()
- {
- $connections = array();
- foreach ($this->connections as $name => $id) {
- $connections[$name] = $this->container->get($id);
- }
-
- return $connections;
- }
-
- /**
- * Gets all connection names.
- *
- * @return array An array of connection names
- */
- public function getConnectionNames()
- {
- return $this->connections;
+ parent::__construct('ORM', $connections, $entityManagers, $defaultConnection, $defaultEntityManager, 'Doctrine\ORM\Proxy\Proxy');
}
/**
* Gets the default entity manager name.
*
* @return string The default entity manager name
+ *
+ * @deprecated
*/
public function getDefaultEntityManagerName()
{
- return $this->defaultEntityManager;
+ return $this->getDefaultManagerName();
}
/**
@@ -110,33 +50,24 @@ public function getDefaultEntityManagerName()
* @param string $name The entity manager name (null for the default one)
*
* @return EntityManager
+ *
+ * @deprecated
*/
public function getEntityManager($name = null)
{
- if (null === $name) {
- $name = $this->defaultEntityManager;
- }
-
- if (!isset($this->entityManagers[$name])) {
- throw new \InvalidArgumentException(sprintf('Doctrine EntityManager named "%s" does not exist.', $name));
- }
-
- return $this->container->get($this->entityManagers[$name]);
+ return $this->getManager($name);
}
/**
* Gets an array of all registered entity managers
*
* @return array An array of EntityManager instances
+ *
+ * @deprecated
*/
public function getEntityManagers()
{
- $ems = array();
- foreach ($this->entityManagers as $name => $id) {
- $ems[$name] = $this->container->get($id);
- }
-
- return $ems;
+ return $this->getManagers();
}
/**
@@ -158,17 +89,21 @@ public function getEntityManagers()
*/
public function resetEntityManager($name = null)
{
- if (null === $name) {
- $name = $this->defaultEntityManager;
- }
-
- if (!isset($this->entityManagers[$name])) {
- throw new \InvalidArgumentException(sprintf('Doctrine EntityManager named "%s" does not exist.', $name));
- }
+ $this->resetManager($name);
+ }
- // force the creation of a new entity manager
- // if the current one is closed
- $this->container->set($this->entityManagers[$name], null);
+ /**
+ * Resolves a registered namespace alias to the full namespace.
+ *
+ * This method looks for the alias in all registered entity managers.
+ *
+ * @param string $alias The alias
+ *
+ * @return string The full namespace
+ */
+ public function getEntityNamespace($alias)
+ {
+ return $this->getAliasNamespace($alias);
}
/**
@@ -182,11 +117,11 @@ public function resetEntityManager($name = null)
*
* @see Configuration::getEntityNamespace
*/
- public function getEntityNamespace($alias)
+ public function getAliasNamespace($alias)
{
- foreach (array_keys($this->entityManagers) as $name) {
+ foreach (array_keys($this->getManagers()) as $name) {
try {
- return $this->getEntityManager($name)->getConfiguration()->getEntityNamespace($alias);
+ return $this->getManager($name)->getConfiguration()->getEntityNamespace($alias);
} catch (ORMException $e) {
}
}
@@ -201,20 +136,7 @@ public function getEntityNamespace($alias)
*/
public function getEntityManagerNames()
{
- return $this->entityManagers;
- }
-
- /**
- * Gets the EntityRepository for an entity.
- *
- * @param string $entityName The name of the entity.
- * @param string $entityManagerNAme The entity manager name (null for the default one)
- *
- * @return Doctrine\ORM\EntityRepository
- */
- public function getRepository($entityName, $entityManagerName = null)
- {
- return $this->getEntityManager($entityManagerName)->getRepository($entityName);
+ return $this->getManagerNames();
}
/**
@@ -226,17 +148,6 @@ public function getRepository($entityName, $entityManagerName = null)
*/
public function getEntityManagerForClass($class)
{
- $proxyClass = new \ReflectionClass($class);
- if ($proxyClass->implementsInterface('Doctrine\ORM\Proxy\Proxy')) {
- $class = $proxyClass->getParentClass()->getName();
- }
-
- foreach ($this->entityManagers as $id) {
- $em = $this->container->get($id);
-
- if (!$em->getConfiguration()->getMetadataDriverImpl()->isTransient($class)) {
- return $em;
- }
- }
+ return $this->getManagerForClass($class);
}
}
View
6 src/Symfony/Bundle/DoctrineBundle/Tests/RegistryTest.php
@@ -64,7 +64,7 @@ public function testGetUnknownConnection()
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$registry = new Registry($container, array(), array(), 'default', 'default');
- $this->setExpectedException('InvalidArgumentException', 'Doctrine Connection named "default" does not exist.');
+ $this->setExpectedException('InvalidArgumentException', 'Doctrine ORM Connection named "default" does not exist.');
$registry->getConnection('default');
}
@@ -109,7 +109,7 @@ public function testGetUnknownEntityManager()
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$registry = new Registry($container, array(), array(), 'default', 'default');
- $this->setExpectedException('InvalidArgumentException', 'Doctrine EntityManager named "default" does not exist.');
+ $this->setExpectedException('InvalidArgumentException', 'Doctrine ORM Manager named "default" does not exist.');
$registry->getEntityManager('default');
}
@@ -140,7 +140,7 @@ public function testResetUnknownEntityManager()
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$registry = new Registry($container, array(), array(), 'default', 'default');
- $this->setExpectedException('InvalidArgumentException', 'Doctrine EntityManager named "default" does not exist.');
+ $this->setExpectedException('InvalidArgumentException', 'Doctrine ORM Manager named "default" does not exist.');
$registry->resetEntityManager('default');
}
}
View
4 vendors.php
@@ -24,9 +24,9 @@
}
$deps = array(
- array('doctrine', 'http://github.com/doctrine/doctrine2.git', 'origin/2.1.x'),
+ array('doctrine', 'http://github.com/doctrine/doctrine2.git', 'origin/master'),
array('doctrine-dbal', 'http://github.com/doctrine/dbal.git', 'origin/2.1.x'),
- array('doctrine-common', 'http://github.com/doctrine/common.git', 'origin/2.1.x'),
+ array('doctrine-common', 'http://github.com/doctrine/common.git', 'origin/master'),
array('monolog', 'http://github.com/Seldaek/monolog.git', '1.0.1'),
array('swiftmailer', 'http://github.com/swiftmailer/swiftmailer.git', 'v4.1.2'),
array('twig', 'http://github.com/fabpot/Twig.git', 'v1.2.0'),
Something went wrong with that request. Please try again.