vendor/friendsofphp/proxy-manager-lts/src/ProxyManager/Factory/LazyLoadingValueHolderFactory.php line 46

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace ProxyManager\Factory;
  4. use Closure;
  5. use ProxyManager\Configuration;
  6. use ProxyManager\Proxy\ValueHolderInterface;
  7. use ProxyManager\Proxy\VirtualProxyInterface;
  8. use ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator;
  9. use ProxyManager\ProxyGenerator\ProxyGeneratorInterface;
  10. /**
  11.  * Factory responsible of producing virtual proxy instances
  12.  */
  13. class LazyLoadingValueHolderFactory extends AbstractBaseFactory
  14. {
  15.     private $generator;
  16.     public function __construct(?Configuration $configuration null)
  17.     {
  18.         parent::__construct($configuration);
  19.         $this->generator = new LazyLoadingValueHolderGenerator();
  20.     }
  21.     /**
  22.      * @param array<string, mixed> $proxyOptions
  23.      * @psalm-param class-string<RealObjectType> $className
  24.      * @psalm-param Closure(
  25.      *   RealObjectType|null=,
  26.      *   RealObjectType&ValueHolderInterface<RealObjectType>&VirtualProxyInterface=,
  27.      *   string=,
  28.      *   array<string, mixed>=,
  29.      *   ?Closure=
  30.      * ) : bool $initializer
  31.      * @psalm-param array{skipDestructor?: bool, fluentSafe?: bool} $proxyOptions
  32.      *
  33.      * @psalm-return RealObjectType&ValueHolderInterface<RealObjectType>&VirtualProxyInterface
  34.      *
  35.      * @psalm-template RealObjectType of object
  36.      * @psalm-suppress MixedInferredReturnType We ignore type checks here, since `staticProxyConstructor` is not
  37.      *                                         interfaced (by design)
  38.      */
  39.     public function createProxy(
  40.         string $className,
  41.         Closure $initializer,
  42.         array $proxyOptions = []
  43.     ): VirtualProxyInterface {
  44.         $proxyClassName $this->generateProxy($className$proxyOptions);
  45.         /**
  46.          * We ignore type checks here, since `staticProxyConstructor` is not interfaced (by design)
  47.          *
  48.          * @psalm-suppress MixedMethodCall
  49.          * @psalm-suppress MixedReturnStatement
  50.          */
  51.         return $proxyClassName::staticProxyConstructor($initializer);
  52.     }
  53.     protected function getGenerator(): ProxyGeneratorInterface
  54.     {
  55.         return $this->generator;
  56.     }
  57. }