RuntimeInstantiator example


class ContainerBuilderTest extends TestCase
{
    public function testCreateProxyServiceWithRuntimeInstantiator()
    {
        $builder = new ContainerBuilder();
        $builder->setProxyInstantiator(new RuntimeInstantiator());

        $builder->register('foo1', \ProxyManagerBridgeFooClass::class)->setFile(__DIR__.'/Fixtures/includes/foo.php')->setPublic(true);
        $builder->getDefinition('foo1')->setLazy(true)->addTag('proxy', ['interface' => \ProxyManagerBridgeFooClass::class]);

        $builder->compile();

        /* @var $foo1 \ProxyManager\Proxy\LazyLoadingInterface|\ProxyManager\Proxy\ValueHolderInterface */
        $foo1 = $builder->get('foo1');

        $foo1->__destruct();
        $this->assertSame(0, $foo1::$destructorCount);

        

class RuntimeInstantiatorTest extends TestCase
{
    protected RuntimeInstantiator $instantiator;

    protected function setUp(): void
    {
        $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);

        
Home | Imprint | This part of the site doesn't use cookies.