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

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