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

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->aliases[$name])) {
  56.                     $name $this->aliases[$name];
  57.                 }
  58.                 if (isset($this->fileMap[$name])) {
  59.                     $wrappedInstance $this->load($this->fileMap[$name], false);
  60.                 } else {
  61.                     $wrappedInstance $this->{$this->methodMap[$name]}(false);
  62.                 }
  63.                 $manager->setProxyInitializer(null);
  64.                 return true;
  65.             },
  66.             $this->container,
  67.             Container::class
  68.         ));
  69.     }
  70. }