vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/ManagerRegistry.php line 63

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Bridge\Doctrine;
  11. use Doctrine\Common\Persistence\AbstractManagerRegistry as LegacyAbstractManagerRegistry;
  12. use Doctrine\Persistence\AbstractManagerRegistry;
  13. use ProxyManager\Proxy\LazyLoadingInterface;
  14. use Symfony\Component\DependencyInjection\Container;
  15. use Symfony\Component\DependencyInjection\ContainerAwareInterface;
  16. use Symfony\Component\DependencyInjection\ContainerInterface as SymfonyContainerInterface;
  17. if (class_exists(AbstractManagerRegistry::class)) {
  18.     abstract class ManagerRegistry extends AbstractManagerRegistry implements ContainerAwareInterface
  19.     {
  20.         use ManagerRegistryTrait;
  21.     }
  22. } else {
  23.     abstract class ManagerRegistry extends LegacyAbstractManagerRegistry implements ContainerAwareInterface
  24.     {
  25.         use ManagerRegistryTrait;
  26.     }
  27. }
  28. /**
  29.  * References Doctrine connections and entity/document managers.
  30.  *
  31.  * @author  Lukas Kahwe Smith <smith@pooteeweet.org>
  32.  *
  33.  * @internal
  34.  */
  35. trait ManagerRegistryTrait
  36. {
  37.     /**
  38.      * @var Container
  39.      */
  40.     protected $container;
  41.     /**
  42.      * @deprecated since version 3.4, to be removed in 4.0 alongside with the ContainerAwareInterface type.
  43.      * @final since version 3.4
  44.      */
  45.     public function setContainer(SymfonyContainerInterface $container null)
  46.     {
  47.         @trigger_error(sprintf('The "%s()" method is deprecated since Symfony 3.4 and will be removed in 4.0. Inject a PSR-11 container using the constructor instead.'__METHOD__), \E_USER_DEPRECATED);
  48.         $this->container $container;
  49.     }
  50.     /**
  51.      * {@inheritdoc}
  52.      */
  53.     protected function getService($name)
  54.     {
  55.         return $this->container->get($name);
  56.     }
  57.     /**
  58.      * {@inheritdoc}
  59.      */
  60.     protected function resetService($name)
  61.     {
  62.         if (!$this->container->initialized($name)) {
  63.             return;
  64.         }
  65.         $manager $this->container->get($name);
  66.         if (!$manager instanceof LazyLoadingInterface) {
  67.             @trigger_error(sprintf('Resetting a non-lazy manager service is deprecated since Symfony 3.2 and will throw an exception in version 4.0. Set the "%s" service as lazy and require "symfony/proxy-manager-bridge" in your composer.json file instead.'$name), \E_USER_DEPRECATED);
  68.             $this->container->set($namenull);
  69.             return;
  70.         }
  71.         $manager->setProxyInitializer(\Closure::bind(
  72.             function (&$wrappedInstanceLazyLoadingInterface $manager) use ($name) {
  73.                 if (isset($this->normalizedIds[$normalizedId strtolower($name)])) {
  74.                     $name $this->normalizedIds[$normalizedId];
  75.                 }
  76.                 if (isset($this->aliases[$name])) {
  77.                     $name $this->aliases[$name];
  78.                 }
  79.                 if (isset($this->fileMap[$name])) {
  80.                     $wrappedInstance $this->load($this->fileMap[$name]);
  81.                 } else {
  82.                     $method = !isset($this->methodMap[$name]) ? 'get'.strtr($name$this->underscoreMap).'Service' $this->methodMap[$name];
  83.                     $wrappedInstance $this->{$method}(false);
  84.                 }
  85.                 $manager->setProxyInitializer(null);
  86.                 return true;
  87.             },
  88.             $this->container,
  89.             Container::class
  90.         ));
  91.     }
  92. }