vendor/symfony/doctrine-bridge/ManagerRegistry.php line 38

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\Persistence\AbstractManagerRegistry;
  12. use ProxyManager\Proxy\LazyLoadingInterface;
  13. use Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator;
  14. use Symfony\Component\DependencyInjection\Container;
  15. /**
  16.  * References Doctrine connections and entity/document managers.
  17.  *
  18.  * @author  Lukas Kahwe Smith <smith@pooteeweet.org>
  19.  */
  20. abstract class ManagerRegistry extends AbstractManagerRegistry
  21. {
  22.     /**
  23.      * @var Container
  24.      */
  25.     protected $container;
  26.     /**
  27.      * {@inheritdoc}
  28.      *
  29.      * @return object
  30.      */
  31.     protected function getService($name)
  32.     {
  33.         return $this->container->get($name);
  34.     }
  35.     /**
  36.      * {@inheritdoc}
  37.      *
  38.      * @return void
  39.      */
  40.     protected function resetService($name)
  41.     {
  42.         if (!$this->container->initialized($name)) {
  43.             return;
  44.         }
  45.         $manager $this->container->get($name);
  46.         if (!$manager instanceof LazyLoadingInterface) {
  47.             throw new \LogicException('Resetting a non-lazy manager service is not supported. '.(interface_exists(LazyLoadingInterface::class) && class_exists(RuntimeInstantiator::class) ? sprintf('Declare the "%s" service as lazy.'$name) : 'Try running "composer require symfony/proxy-manager-bridge".'));
  48.         }
  49.         $manager->setProxyInitializer(\Closure::bind(
  50.             function (&$wrappedInstanceLazyLoadingInterface $manager) use ($name) {
  51.                 if (isset($this->normalizedIds[$normalizedId strtolower($name)])) { // BC with DI v3.4
  52.                     $name $this->normalizedIds[$normalizedId];
  53.                 }
  54.                 if (isset($this->aliases[$name])) {
  55.                     $name $this->aliases[$name];
  56.                 }
  57.                 if (isset($this->fileMap[$name])) {
  58.                     $wrappedInstance $this->load($this->fileMap[$name]);
  59.                 } else {
  60.                     $method $this->methodMap[$name] ?? 'get'.strtr($name$this->underscoreMap).'Service'// BC with DI v3.4
  61.                     $wrappedInstance $this->{$method}(false);
  62.                 }
  63.                 $manager->setProxyInitializer(null);
  64.                 return true;
  65.             },
  66.             $this->container,
  67.             Container::class
  68.         ));
  69.     }
  70. }