ProxyGenerator example


class RuntimeInstantiator implements InstantiatorInterface
{
    private Configuration $config;
    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) {
            

class ProxyDumper implements DumperInterface
{
    private string $salt;
    private ProxyGenerator $proxyGenerator;
    private BaseGeneratorStrategy $classGenerator;

    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
    {
Home | Imprint | This part of the site doesn't use cookies.