Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

use Doctrine Common ManagerRegistry instead of custom code

  • Loading branch information...
commit 240a5b8bf58a94d855582c280dabeed98b57711d 1 parent 3fb94ad
@lsmith77 lsmith77 authored
View
23 CouchDBRegistry.php
@@ -1,23 +0,0 @@
-<?php
-
-/*
- * Doctrine CouchDB Bundle
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to kontakt@beberlei.de so I can send you a copy immediately.
- */
-
-namespace Doctrine\Bundle\CouchDBBundle;
-
-class CouchDBRegistry extends PersistentObjectRegistry
-{
- public function getName()
- {
- return 'CouchDB';
- }
-}
View
4 Form/DoctrineCouchDBExtension.php
@@ -12,13 +12,13 @@
namespace Doctrine\Bundle\CouchDBBundle\Form;
use Symfony\Component\Form\AbstractExtension;
-use Doctrine\Bundle\CouchDBBundle\PersistenceRegistryInterface;
+use Doctrine\Common\Persistence\ManagerRegistry;
class DoctrineCouchDBExtension extends AbstractExtension
{
protected $registry;
- public function __construct(PersistenceRegistryInterface $registry)
+ public function __construct(ManagerRegistry $registry)
{
$this->registry = $registry;
}
View
4 Form/Type/PersistentObjectType.php
@@ -17,7 +17,7 @@
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\AbstractType;
-use Doctrine\Bundle\CouchDBBundle\PersistenceRegistryInterface;
+use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Bundle\CouchDBBundle\ChoiceList\EntityChoiceList;
use Doctrine\Bundle\CouchDBBundle\Form\EventListener\MergeCollectionListener;
use Doctrine\Bundle\CouchDBBundle\Form\DataTransformer\PersistentObjectToArrayTransformer;
@@ -27,7 +27,7 @@
{
protected $registry;
- public function __construct(PersistenceRegistryInterface $registry)
+ public function __construct(ManagerRegistry $registry)
{
$this->registry = $registry;
}
View
40 ManagerRegistry.php
@@ -0,0 +1,40 @@
+<?php
+
+/*
+ * Doctrine CouchDB Bundle
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to kontakt@beberlei.de so I can send you a copy immediately.
+ */
+
+namespace Doctrine\Bundle\CouchDBBundle;
+
+use Symfony\Bridge\Doctrine\ManagerRegistry as BaseManagerRegistry;
+use Doctrine\ODM\CouchDB\CouchDBException;
+
+class ManagerRegistry extends BaseManagerRegistry
+{
+ /**
+ * Resolves a registered namespace alias to the full namespace.
+ *
+ * @param string $alias
+ * @return string
+ * @throws CouchDBException
+ */
+ public function getAliasNamespace($alias)
+ {
+ foreach (array_keys($this->getManagers()) as $name) {
+ try {
+ return $this->getManager($name)->getConfiguration()->getDocumentNamespace($alias);
+ } catch (CouchDBException $e) {
+ }
+ }
+
+ throw CouchDBException::unknownDocumentNamespace($alias);
+ }
+}
View
127 PersistenceRegistryInterface.php
@@ -1,127 +0,0 @@
-<?php
-
-/*
- * Doctrine CouchDB Bundle
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to kontakt@beberlei.de so I can send you a copy immediately.
- */
-
-namespace Doctrine\Bundle\CouchDBBundle;
-
-interface PersistenceRegistryInterface
-{
- /**
- * 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 object manager name.
- *
- * @return string The default object manager name
- */
- function getDefaultObjectManagerName();
-
- /**
- * Gets a named object manager.
- *
- * @param string $name The object manager name (null for the default one)
- *
- * @return \Doctrine\Common\Persistence\ObjectManager
- */
- function getObjectManager($name = null);
-
- /**
- * Gets an array of all registered object managers
- *
- * @return array An array of ObjectManager instances
- */
- function getObjectManagers();
-
- /**
- * Resets a named object manager.
- *
- * This method is useful when an object manager has been closed
- * because of a rollbacked transaction AND when you think that
- * it makes sense to get a new one to replace the closed one.
- *
- * Be warned that you will get a brand new object manager as
- * the existing one is not useable anymore. This means that any
- * other object with a dependency on this object manager will
- * hold an obsolete reference. You can inject the registry instead
- * to avoid this problem.
- *
- * @param string $name The object manager name (null for the default one)
- *
- * @return \Doctrine\Common\Persistence\ObjectManager
- */
- function resetObjectManager($name = null);
-
- /**
- * Resolves a registered namespace alias to the full namespace.
- *
- * This method looks for the alias in all registered object managers.
- *
- * @param string $alias The alias
- *
- * @return string The full namespace
- */
- function getObjectNamespace($alias);
-
- /**
- * Gets all connection names.
- *
- * @return array An array of connection names
- */
- function getObjectManagerNames();
-
- /**
- * Gets the ObjectRepository for an persistent object.
- *
- * @param string $persistentObject The name of the persistent object.
- * @param string $persistentObjectManagerName The object manager name (null for the default one)
- *
- * @return Doctrine\Common\Persistence\ObjectRepository
- */
- function getRepository($persistentObject, $persistentObjectManagerName = null);
-
- /**
- * Gets the object manager associated with a given class.
- *
- * @param string $class A persistent object class name
- *
- * @return ObjectManager|null
- */
- function getObjectManagerForClass($class);
-}
View
178 PersistentObjectRegistry.php
@@ -1,178 +0,0 @@
-<?php
-
-/*
- * Doctrine CouchDB Bundle
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to kontakt@beberlei.de so I can send you a copy immediately.
- */
-
-namespace Doctrine\Bundle\CouchDBBundle;
-
-use Symfony\Component\DependencyInjection\ContainerInterface;
-
-class PersistentObjectRegistry implements PersistenceRegistryInterface
-{
- private $container;
- private $connections;
- private $objectManagers;
- private $defaultConnection;
- private $defaultObjectManager;
-
- public function __construct(ContainerInterface $container, array $connections, array $objectManagers, $defaultConnection, $defaultObjectManager)
- {
- $this->container = $container;
- $this->connections = $connections;
- $this->objectManagers = $objectManagers;
- $this->defaultConnection = $defaultConnection;
- $this->defaultObjectManager = $defaultObjectManager;
- }
-
- /**
- * @inheritdoc
- */
- public function getConnection($name = null)
- {
- if (null === $name) {
- $name = $this->defaultConnection;
- }
-
- if (!isset($this->connections[$name])) {
- throw new \InvalidArgumentException(sprintf('Doctrine %s Connection named "%s" does not exist.', $this->getName(), $name));
- }
-
- return $this->container->get($this->connections[$name]);
- }
-
- /**
- * @inheritdoc
- */
- public function getConnectionNames()
- {
- return $this->connections;
- }
-
- /**
- * @inheritdoc
- */
- public function getConnections()
- {
- $connections = array();
- foreach ($this->connections as $name => $id) {
- $connections[$name] = $this->container->get($id);
- }
-
- return $connections;
- }
-
- /**
- * @inheritdoc
- */
- public function getDefaultConnectionName()
- {
- return $this->defaultConnection;
- }
-
- /**
- * @inheritdoc
- */
- public function getDefaultObjectManagerName()
- {
- return $this->defaultObjectManager;
- }
-
- /**
- * @inheritdoc
- */
- public function getObjectManager($name = null)
- {
- if (null === $name) {
- $name = $this->defaultObjectManager;
- }
-
- if (!isset($this->objectManagers[$name])) {
- throw new \InvalidArgumentException(sprintf('Doctrine %s Object Manager named "%s" does not exist.', $this->getName(), $name));
- }
-
- return $this->container->get($this->objectManagers[$name]);
- }
-
- /**
- * @inheritdoc
- */
- public function getObjectManagerForClass($class)
- {
- $proxyClass = new \ReflectionClass($class);
- if ($proxyClass->implementsInterface('Doctrine\ODM\CouchDB\Proxy\Proxy')) {
- $class = $proxyClass->getParentClass()->getName();
- }
-
- foreach ($this->objectManagers as $id) {
- $objectManager = $this->container->get($id);
-
- if (!$objectManager->getConfiguration()->getMetadataDriverImpl()->isTransient($class)) {
- return $objectManager;
- }
- }
- }
-
- /**
- * @inheritdoc
- */
- public function getObjectManagerNames()
- {
- return $this->objectManagers;
- }
-
- /**
- * @inheritdoc
- */
- public function getObjectManagers()
- {
- $dms = array();
- foreach ($this->objectManagers as $name => $id) {
- $dms[$name] = $this->container->get($id);
- }
-
- return $dms;
- }
-
- /**
- * @inheritdoc
- */
- public function getObjectNamespace($alias)
- {
- throw new \BadMethodCallException("Not yet implemented.");
- }
-
- /**
- * @inheritdoc
- */
- public function getRepository($persistentObjectName, $persistentObjectManagerName = null)
- {
- return $this->getObjectManager($persistentObjectManagerName)->getRepository($persistentObjectName);
- }
-
- /**
- * @inheritdoc
- */
- public function resetObjectManager($name = null)
- {
- if (null === $name) {
- $name = $this->defaultObjectManager;
- }
-
- if (!isset($this->objectManagers[$name])) {
- throw new \InvalidArgumentException(sprintf('Doctrine %s Manager named "%s" does not exist.', $this->getName(), $name));
- }
-
- // force the creation of a new entity manager
- // if the current one is closed
- $this->container->set($this->objectManagers[$name], null);
- }
-}
View
13 Resources/config/client.xml
@@ -8,7 +8,7 @@
<parameters>
<parameter key="doctrine_couchdb.client.connection.class">Doctrine\CouchDB\CouchDBClient</parameter>
<parameter key="doctrine_couchdb.datacollector.class">Doctrine\Bundle\CouchDBBundle\DataCollector\CouchDBDataCollector</parameter>
- <parameter key="doctrine_couchdb.couchdb.class">Doctrine\Bundle\CouchDBBundle\CouchDBRegistry</parameter>
+ <parameter key="doctrine_couchdb.couchdb.class">Doctrine\Bundle\DoctrineCouchDBBundle\ManagerRegistry</parameter>
<parameter key="doctrine_couchdb.connections" type="collection" />
<parameter key="doctrine_couchdb.document_managers" type="collection" />
<parameter key="doctrine_couchdb.default_connection"></parameter>
@@ -16,22 +16,29 @@
</parameters>
<services>
+
<service id="doctrine_couchdb.client.connection"
class="%doctrine_couchdb.client.connection.class%"
factory-class="%doctrine_couchdb.client.connection.class%"
factory-method="create"
abstract="true"
/>
+
<service id="doctrine_couchdb.datacollector" class="%doctrine_couchdb.datacollector.class%">
<tag name="data_collector" template="DoctrineCouchDBBundle:Collector:couchdb" id="couchdb" />
</service>
<service id="doctrine_couchdb" class="%doctrine_couchdb.couchdb.class%">
- <argument type="service" id="service_container" />
+ <argument>CouchDB</argument>
<argument>%doctrine_couchdb.connections%</argument>
<argument>%doctrine_couchdb.document_managers%</argument>
<argument>%doctrine_couchdb.default_connection%</argument>
<argument>%doctrine_couchdb.default_document_manager%</argument>
+ <argument>Doctrine\ODM\CouchDB\Proxy\Proxy</argument>
+ <call method="setContainer">
+ <argument type="service" id="service_container" />
+ </call>
</service>
+
</services>
-</container>
+</container>
Please sign in to comment.
Something went wrong with that request. Please try again.