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 <[email protected]>
  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. use Symfony\Component\VarExporter\LazyObjectInterface;
  17. /**
  18.  * References Doctrine connections and entity/document managers.
  19.  *
  20.  * @author Lukas Kahwe Smith <[email protected]>
  21.  */
  22. abstract class ManagerRegistry extends AbstractManagerRegistry
  23. {
  24.     /**
  25.      * @var Container
  26.      */
  27.     protected $container;
  28.     /**
  29.      * {@inheritdoc}
  30.      *
  31.      * @return object
  32.      */
  33.     protected function getService($name)
  34.     {
  35.         return $this->container->get($name);
  36.     }
  37.     /**
  38.      * {@inheritdoc}
  39.      *
  40.      * @return void
  41.      */
  42.     protected function resetService($name)
  43.     {
  44.         if (!$this->container->initialized($name)) {
  45.             return;
  46.         }
  47.         $manager $this->container->get($name);
  48.         if ($manager instanceof LazyObjectInterface) {
  49.             if (!$manager->resetLazyObject()) {
  50.                 throw new \LogicException(sprintf('Resetting a non-lazy manager service is not supported. Declare the "%s" service as lazy.'$name));
  51.             }
  52.             return;
  53.         }
  54.         if (!$manager instanceof LazyLoadingInterface) {
  55.             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".'));
  56.         }
  57.         if ($manager instanceof GhostObjectInterface) {
  58.             throw new \LogicException('Resetting a lazy-ghost-object manager service is not supported.');
  59.         }
  60.         $manager->setProxyInitializer(\Closure::bind(
  61.             function (&$wrappedInstanceLazyLoadingInterface $manager) use ($name) {
  62.                 if (isset($this->aliases[$name])) {
  63.                     $name $this->aliases[$name];
  64.                 }
  65.                 if (isset($this->fileMap[$name])) {
  66.                     $wrappedInstance $this->load($this->fileMap[$name], false);
  67.                 } elseif ((new \ReflectionMethod($this$this->methodMap[$name]))->isStatic()) {
  68.                     $wrappedInstance $this->{$this->methodMap[$name]}($thisfalse);
  69.                 } else {
  70.                     $wrappedInstance $this->{$this->methodMap[$name]}(false);
  71.                 }
  72.                 $manager->setProxyInitializer(null);
  73.                 return true;
  74.             },
  75.             $this->container,
  76.             Container::class
  77.         ));
  78.     }
  79. }