vendor/doctrine/doctrine-bundle/Registry.php line 57

Open in your IDE?
  1. <?php
  2. namespace Doctrine\Bundle\DoctrineBundle;
  3. use Doctrine\ORM\EntityManager;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Doctrine\ORM\ORMException;
  6. use ProxyManager\Proxy\LazyLoadingInterface;
  7. use Psr\Container\ContainerInterface;
  8. use Symfony\Bridge\Doctrine\ManagerRegistry;
  9. use Symfony\Bridge\Doctrine\RegistryInterface;
  10. use Symfony\Contracts\Service\ResetInterface;
  11. /**
  12.  * References all Doctrine connections and entity managers in a given Container.
  13.  */
  14. class Registry extends ManagerRegistry implements RegistryInterfaceResetInterface
  15. {
  16.     /**
  17.      * @param string[] $connections
  18.      * @param string[] $entityManagers
  19.      * @param string   $defaultConnection
  20.      * @param string   $defaultEntityManager
  21.      */
  22.     public function __construct(ContainerInterface $container, array $connections, array $entityManagers$defaultConnection$defaultEntityManager)
  23.     {
  24.         $this->container $container;
  25.         parent::__construct('ORM'$connections$entityManagers$defaultConnection$defaultEntityManager'Doctrine\ORM\Proxy\Proxy');
  26.     }
  27.     /**
  28.      * Gets the default entity manager name.
  29.      *
  30.      * @deprecated
  31.      *
  32.      * @return string The default entity manager name
  33.      */
  34.     public function getDefaultEntityManagerName()
  35.     {
  36.         @trigger_error('getDefaultEntityManagerName is deprecated since Symfony 2.1. Use getDefaultManagerName instead'E_USER_DEPRECATED);
  37.         return $this->getDefaultManagerName();
  38.     }
  39.     /**
  40.      * Gets a named entity manager.
  41.      *
  42.      * @deprecated
  43.      *
  44.      * @param string $name The entity manager name (null for the default one)
  45.      *
  46.      * @return EntityManager
  47.      */
  48.     public function getEntityManager($name null)
  49.     {
  50.         @trigger_error('getEntityManager is deprecated since Symfony 2.1. Use getManager instead'E_USER_DEPRECATED);
  51.         return $this->getManager($name);
  52.     }
  53.     /**
  54.      * Gets an array of all registered entity managers
  55.      *
  56.      * @deprecated
  57.      *
  58.      * @return EntityManager[] an array of all EntityManager instances
  59.      */
  60.     public function getEntityManagers()
  61.     {
  62.         @trigger_error('getEntityManagers is deprecated since Symfony 2.1. Use getManagers instead'E_USER_DEPRECATED);
  63.         return $this->getManagers();
  64.     }
  65.     /**
  66.      * Resets a named entity manager.
  67.      *
  68.      * This method is useful when an entity manager has been closed
  69.      * because of a rollbacked transaction AND when you think that
  70.      * it makes sense to get a new one to replace the closed one.
  71.      *
  72.      * Be warned that you will get a brand new entity manager as
  73.      * the existing one is not usable anymore. This means that any
  74.      * other object with a dependency on this entity manager will
  75.      * hold an obsolete reference. You can inject the registry instead
  76.      * to avoid this problem.
  77.      *
  78.      * @deprecated
  79.      *
  80.      * @param string $name The entity manager name (null for the default one)
  81.      */
  82.     public function resetEntityManager($name null) : EntityManager
  83.     {
  84.         @trigger_error('resetEntityManager is deprecated since Symfony 2.1. Use resetManager instead'E_USER_DEPRECATED);
  85.         return $this->resetManager($name);
  86.     }
  87.     /**
  88.      * Resolves a registered namespace alias to the full namespace.
  89.      *
  90.      * This method looks for the alias in all registered entity managers.
  91.      *
  92.      * @deprecated
  93.      *
  94.      * @param string $alias The alias
  95.      *
  96.      * @return string The full namespace
  97.      */
  98.     public function getEntityNamespace($alias)
  99.     {
  100.         @trigger_error('getEntityNamespace is deprecated since Symfony 2.1. Use getAliasNamespace instead'E_USER_DEPRECATED);
  101.         return $this->getAliasNamespace($alias);
  102.     }
  103.     /**
  104.      * Resolves a registered namespace alias to the full namespace.
  105.      *
  106.      * This method looks for the alias in all registered entity managers.
  107.      *
  108.      * @see Configuration::getEntityNamespace
  109.      *
  110.      * @param string $alias The alias
  111.      *
  112.      * @return string The full namespace
  113.      */
  114.     public function getAliasNamespace($alias)
  115.     {
  116.         foreach (array_keys($this->getManagers()) as $name) {
  117.             try {
  118.                 return $this->getManager($name)->getConfiguration()->getEntityNamespace($alias);
  119.             } catch (ORMException $e) {
  120.             }
  121.         }
  122.         throw ORMException::unknownEntityNamespace($alias);
  123.     }
  124.     /**
  125.      * Gets all connection names.
  126.      *
  127.      * @deprecated
  128.      *
  129.      * @return string[] An array of connection names
  130.      */
  131.     public function getEntityManagerNames()
  132.     {
  133.         @trigger_error('getEntityManagerNames is deprecated since Symfony 2.1. Use getManagerNames instead'E_USER_DEPRECATED);
  134.         return $this->getManagerNames();
  135.     }
  136.     /**
  137.      * Gets the entity manager associated with a given class.
  138.      *
  139.      * @deprecated
  140.      *
  141.      * @param string $class A Doctrine Entity class name
  142.      *
  143.      * @return EntityManager|null
  144.      */
  145.     public function getEntityManagerForClass($class)
  146.     {
  147.         @trigger_error('getEntityManagerForClass is deprecated since Symfony 2.1. Use getManagerForClass instead'E_USER_DEPRECATED);
  148.         return $this->getManagerForClass($class);
  149.     }
  150.     public function reset() : void
  151.     {
  152.         foreach ($this->getManagerNames() as $managerName => $serviceId) {
  153.             $this->resetOrClearManager($managerName$serviceId);
  154.         }
  155.     }
  156.     private function resetOrClearManager(string $managerNamestring $serviceId) : void
  157.     {
  158.         if (! $this->container->initialized($serviceId)) {
  159.             return;
  160.         }
  161.         $manager $this->container->get($serviceId);
  162.         assert($manager instanceof EntityManagerInterface);
  163.         if (! $manager instanceof LazyLoadingInterface || $manager->isOpen()) {
  164.             $manager->clear();
  165.             return;
  166.         }
  167.         $this->resetManager($managerName);
  168.     }
  169. }