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

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.     protected function getService($name)
  30.     {
  31.         return $this->container->get($name);
  32.     }
  33.     /**
  34.      * {@inheritdoc}
  35.      */
  36.     protected function resetService($name)
  37.     {
  38.         if (!$this->container->initialized($name)) {
  39.             return;
  40.         }
  41.         $manager $this->container->get($name);
  42.         if (!$manager instanceof LazyLoadingInterface) {
  43.             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".'));
  44.         }
  45.         $manager->setProxyInitializer(\Closure::bind(
  46.             function (&$wrappedInstanceLazyLoadingInterface $manager) use ($name) {
  47.                 if (isset($this->normalizedIds[$normalizedId strtolower($name)])) { // BC with DI v3.4
  48.                     $name $this->normalizedIds[$normalizedId];
  49.                 }
  50.                 if (isset($this->aliases[$name])) {
  51.                     $name $this->aliases[$name];
  52.                 }
  53.                 if (isset($this->fileMap[$name])) {
  54.                     $wrappedInstance $this->load($this->fileMap[$name]);
  55.                 } else {
  56.                     $method $this->methodMap[$name] ?? 'get'.strtr($name$this->underscoreMap).'Service'// BC with DI v3.4
  57.                     $wrappedInstance $this->{$method}(false);
  58.                 }
  59.                 $manager->setProxyInitializer(null);
  60.                 return true;
  61.             },
  62.             $this->container,
  63.             Container::class
  64.         ));
  65.     }
  66. }