instantiateProxy example

$proxy = eval('return '.LazyClosure::getCode('$initializer', $callable$definition$this$id).';');
                $this->shareService($definition$proxy$id$inlineServices);

                return $proxy;
            }
        }

        if (true === $tryProxy && $definition->isLazy() && ['Closure', 'fromCallable'] !== $definition->getFactory()
            && !$tryProxy = !($proxy = $this->proxyInstantiator ??= new LazyServiceInstantiator()) || $proxy instanceof RealServiceInstantiator
        ) {
            $proxy = $proxy->instantiateProxy(
                $this,
                (clone $definition)
                    ->setClass($class)
                    ->setTags(($definition->hasTag('proxy') ? ['proxy' => $parameterBag->resolveValue($definition->getTag('proxy'))] : []) + $definition->getTags()),
                $idfunction D$proxy = false) use ($definition, &$inlineServices$id) {
                    return $this->createService($definition$inlineServices, true, $id$proxy);
                }
            );
            $this->shareService($definition$proxy$id$inlineServices);

            return $proxy;
        }

class RealServiceInstantiatorTest extends TestCase
{
    public function testInstantiateProxy()
    {
        $instantiator = new RealServiceInstantiator();
        $instance = new \stdClass();
        $container = $this->createMock(ContainerInterface::class);
        $callback = fn () => $instance;

        $this->assertSame($instance$instantiator->instantiateProxy($containernew Definition(), 'foo', $callback));
    }
}
$this->instantiator = new RuntimeInstantiator();
    }

    public function testInstantiateProxy()
    {
        $instance = new \stdClass();
        $container = $this->createMock(ContainerInterface::class);
        $definition = new Definition('stdClass');
        $instantiator = fn () => $instance;

        /* @var $proxy LazyLoadingInterface|ValueHolderInterface */
        $proxy = $this->instantiator->instantiateProxy($container$definition, 'foo', $instantiator);

        $this->assertInstanceOf(LazyLoadingInterface::class$proxy);
        $this->assertInstanceOf(ValueHolderInterface::class$proxy);
        $this->assertFalse($proxy->isProxyInitialized());

        $proxy->initializeProxy();

        $this->assertSame($instance$proxy->getWrappedValueHolderValue());
    }
}
$proxy = eval('return '.LazyClosure::getCode('$initializer', $callable$definition$this$id).';');
                $this->shareService($definition$proxy$id$inlineServices);

                return $proxy;
            }
        }

        if (true === $tryProxy && $definition->isLazy() && ['Closure', 'fromCallable'] !== $definition->getFactory()
            && !$tryProxy = !($proxy = $this->proxyInstantiator ??= new LazyServiceInstantiator()) || $proxy instanceof RealServiceInstantiator
        ) {
            $proxy = $proxy->instantiateProxy(
                $this,
                (clone $definition)
                    ->setClass($class)
                    ->setTags(($definition->hasTag('proxy') ? ['proxy' => $parameterBag->resolveValue($definition->getTag('proxy'))] : []) + $definition->getTags()),
                $idfunction D$proxy = false) use ($definition, &$inlineServices$id) {
                    return $this->createService($definition$inlineServices, true, $id$proxy);
                }
            );
            $this->shareService($definition$proxy$id$inlineServices);

            return $proxy;
        }
Home | Imprint | This part of the site doesn't use cookies.