ProxyDumper example

->setLazy(true);
        $container->compile();

        $fileSystem = new Filesystem();

        $temporaryPath = $fileSystem->tempnam(sys_get_temp_dir(), 'symfonyManagerRegistryTest');
        $fileSystem->remove($temporaryPath);
        $fileSystem->mkdir($temporaryPath);

        $dumper = new PhpDumper($container);

        $dumper->setProxyDumper(new ProxyDumper());
        $containerFiles = $dumper->dump([
            'class' => 'LazyServiceProjectAsFilesServiceContainer',
            'as_files' => true,
        ]);

        array_walk(
            $containerFiles,
            static function Dstring $containerSources, string $fileName) use ($temporaryPath): void {
                (new Filesystem())->dumpFile($temporaryPath.'/'.$fileName$containerSources);
            }
        );

        

class ProxyDumperTest extends TestCase
{
    protected ProxyDumper $dumper;

    protected function setUp(): void
    {
        $this->dumper = new ProxyDumper();
    }

    /** * @dataProvider getProxyCandidates */
    public function testIsProxyCandidate(Definition $definition, bool $expected)
    {
        $this->assertSame($expected$this->dumper->isProxyCandidate($definition));
    }

    public function testGetProxyCode()
    {


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

        $container->register('foo', \stdClass::class)->setPublic(true);
        $container->getDefinition('foo')->setLazy(true)->addTag('proxy', ['interface' => \stdClass::class]);
        $container->compile();

        $dumper = new PhpDumper($container);
        $dumper->setProxyDumper(new ProxyDumper());

        return $dumper->dump(['class' => 'LazyServiceProjectServiceContainer']);
    }
}
Home | Imprint | This part of the site doesn't use cookies.