vendor/ocramius/proxy-manager/src/ProxyManager/Factory/LazyLoadingValueHolderFactory.php line 29

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace ProxyManager\Factory;
  4. use ProxyManager\Proxy\VirtualProxyInterface;
  5. use ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator;
  6. use ProxyManager\ProxyGenerator\ProxyGeneratorInterface;
  7. /**
  8.  * Factory responsible of producing virtual proxy instances
  9.  *
  10.  * @author Marco Pivetta <ocramius@gmail.com>
  11.  * @license MIT
  12.  */
  13. class LazyLoadingValueHolderFactory extends AbstractBaseFactory
  14. {
  15.     /**
  16.      * @var \ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator|null
  17.      */
  18.     private $generator;
  19.     public function createProxy(
  20.         string $className,
  21.         \Closure $initializer,
  22.         array $proxyOptions = []
  23.     ) : VirtualProxyInterface {
  24.         $proxyClassName $this->generateProxy($className$proxyOptions);
  25.         return $proxyClassName::staticProxyConstructor($initializer);
  26.     }
  27.     /**
  28.      * {@inheritDoc}
  29.      */
  30.     protected function getGenerator() : ProxyGeneratorInterface
  31.     {
  32.         return $this->generator ?: $this->generator = new LazyLoadingValueHolderGenerator();
  33.     }
  34. }