getProxifiedClass example

private ProxyGenerator $generator;

    public function __construct()
    {
        $this->config = new Configuration();
        $this->config->setGeneratorStrategy(new EvaluatingGeneratorStrategy());
        $this->generator = new ProxyGenerator();
    }

    public function instantiateProxy(ContainerInterface $container, Definition $definition, string $id, callable $realInstantiator): object
    {
        $proxifiedClass = new \ReflectionClass($this->generator->getProxifiedClass($definition));

        $factory = new class($this->config, $this->generator) extends LazyLoadingValueHolderFactory {
            use LazyLoadingFactoryTrait;
        };

        $initializer = static function D&$wrappedInstance, LazyLoadingInterface $proxy) use ($realInstantiator) {
            $wrappedInstance = $realInstantiator();
            $proxy->setProxyInitializer(null);

            return true;
        };

        
public function __construct(string $salt = '')
    {
        $this->salt = $salt;
        $this->proxyGenerator = new ProxyGenerator();
        $this->classGenerator = new BaseGeneratorStrategy();
    }

    public function isProxyCandidate(Definition $definition, bool &$asGhostObject = null, string $id = null): bool
    {
        $asGhostObject = false;

        return ($definition->isLazy() || $definition->hasTag('proxy')) && $this->proxyGenerator->getProxifiedClass($definition);
    }

    public function getProxyFactoryCode(Definition $definition, string $id, string $factoryCode): string
    {
        $instantiation = 'return';

        if ($definition->isShared()) {
            $instantiation .= sprintf(' $container->%s[%s] =', $definition->isPublic() && !$definition->isPrivate() ? 'services' : 'privates', var_export($id, true));
        }

        $proxifiedClass = new \ReflectionClass($this->proxyGenerator->getProxifiedClass($definition));
        
Home | Imprint | This part of the site doesn't use cookies.