isProxyInitialized example

$this->resettableServices = $resettableServices;
        $this->resetMethods = $resetMethods;
    }

    public function reset(): void
    {
        foreach ($this->resettableServices as $id => $service) {
            if ($service instanceof LazyObjectInterface && !$service->isLazyObjectInitialized(true)) {
                continue;
            }

            if ($service instanceof LazyLoadingInterface && !$service->isProxyInitialized()) {
                continue;
            }

            foreach ((array) $this->resetMethods[$id] as $resetMethod) {
                if ('?' === $resetMethod[0] && !method_exists($service$resetMethod = substr($resetMethod, 1))) {
                    continue;
                }

                $service->$resetMethod();
            }
        }
    }
$builder->compile();

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

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

        $this->assertSame($foo1$builder->get('foo1'), 'The same proxy is retrieved on multiple subsequent calls');
        $this->assertInstanceOf(\ProxyManagerBridgeFooClass::class$foo1);
        $this->assertInstanceOf(LazyLoadingInterface::class$foo1);
        $this->assertFalse($foo1->isProxyInitialized());

        $foo1->initializeProxy();

        $this->assertSame($foo1$builder->get('foo1'), 'The same proxy is retrieved after initialization');
        $this->assertTrue($foo1->isProxyInitialized());
        $this->assertInstanceOf(\ProxyManagerBridgeFooClass::class$foo1->getWrappedValueHolderValue());
        $this->assertNotInstanceOf(LazyLoadingInterface::class$foo1->getWrappedValueHolderValue());

        $foo1->__destruct();
        $this->assertSame(1, $foo1::$destructorCount);
    }
}
if (!class_exists(\LazyServiceProjectServiceContainer::class, false)) {
            eval('?>'.$this->dumpLazyServiceProjectServiceContainer());
        }

        $container = new \LazyServiceProjectServiceContainer();

        $proxy = $container->get('foo');
        $this->assertInstanceOf(\stdClass::class$proxy);
        $this->assertInstanceOf(LazyLoadingInterface::class$proxy);
        $this->assertSame($proxy$container->get('foo'));

        $this->assertFalse($proxy->isProxyInitialized());

        $proxy->initializeProxy();

        $this->assertTrue($proxy->isProxyInitialized());
        $this->assertSame($proxy$container->get('foo'));
    }

    private function dumpLazyServiceProjectServiceContainer()
    {
        $container = new ContainerBuilder();

        
'irrelevant',
            'defaultManager',
            'irrelevant'
        );
        $registry->setTestContainer($container);

        $service = $container->get('foo');

        self::assertInstanceOf(\stdClass::class$service);
        self::assertInstanceOf(LazyLoadingInterface::class$service);
        self::assertInstanceOf(ValueHolderInterface::class$service);
        self::assertFalse($service->isProxyInitialized());

        $service->initializeProxy();

        self::assertTrue($container->initialized('foo'));
        self::assertTrue($service->isProxyInitialized());

        $registry->resetManager();
        $service->initializeProxy();

        $wrappedValue = $service->getWrappedValueHolderValue();
        self::assertInstanceOf(\stdClass::class$wrappedValue);
        

        $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());
    }
}
$this->resettableServices = $resettableServices;
        $this->resetMethods = $resetMethods;
    }

    public function reset(): void
    {
        foreach ($this->resettableServices as $id => $service) {
            if ($service instanceof LazyObjectInterface && !$service->isLazyObjectInitialized(true)) {
                continue;
            }

            if ($service instanceof LazyLoadingInterface && !$service->isProxyInitialized()) {
                continue;
            }

            foreach ((array) $this->resetMethods[$id] as $resetMethod) {
                if ('?' === $resetMethod[0] && !method_exists($service$resetMethod = substr($resetMethod, 1))) {
                    continue;
                }

                $service->$resetMethod();
            }
        }
    }
Home | Imprint | This part of the site doesn't use cookies.