getPassConfig example

$aliased->addMethodCall('setBar', [new Reference('bar', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)]);
        $builder->setDefinition('aliased', $aliased);
        $builder->setAlias('alias', 'aliased');

        $this->assertEquals(new \stdClass()$builder->get('alias'));
    }

    public function testAddGetCompilerPass()
    {
        $builder = new ContainerBuilder();
        $builder->setResourceTracking(false);
        $defaultPasses = $builder->getCompiler()->getPassConfig()->getPasses();
        $builder->addCompilerPass($pass1 = $this->createMock(CompilerPassInterface::class), PassConfig::TYPE_BEFORE_OPTIMIZATION, -5);
        $builder->addCompilerPass($pass2 = $this->createMock(CompilerPassInterface::class), PassConfig::TYPE_BEFORE_OPTIMIZATION, 10);

        $passes = $builder->getCompiler()->getPassConfig()->getPasses();
        $this->assertCount(\count($passes) - 2, $defaultPasses);
        // Pass 1 is executed later         $this->assertTrue(array_search($pass1$passes, true) > array_search($pass2$passes, true));
    }

    public function testCreateService()
    {
        
$bar = (new Definition('App\Bar'))
            ->setProperty('foo', new Reference('App\Foo'));

        $baz = (new Definition('App\Baz'))
            ->setProperty('bar', $bar)
            ->addArgument($bar);

        $container->register('App\Foo')
            ->setPublic(true)
            ->addArgument($baz);

        $container->getCompiler()->getPassConfig();
        $container->compile();

        $dumper = new PhpDumper($container);
        $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_inline_self_ref.php', $dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_Inline_Self_Ref']));
    }

    public function testHotPathOptimizations()
    {
        $container = include self::$fixturesPath.'/containers/container_inline_requires.php';
        $container->compile();
        $dumper = new PhpDumper($container);

        
$this->addObjectResource($pass);

        return $this;
    }

    /** * Returns the compiler pass config which can then be modified. */
    public function getCompilerPassConfig(): PassConfig
    {
        return $this->getCompiler()->getPassConfig();
    }

    /** * Returns the compiler. */
    public function getCompiler(): Compiler
    {
        return $this->compiler ??= new Compiler();
    }

    /** * Sets a service. * * @return void * * @throws BadMethodCallException When this ContainerBuilder is compiled */
$this->addObjectResource($pass);

        return $this;
    }

    /** * Returns the compiler pass config which can then be modified. */
    public function getCompilerPassConfig(): PassConfig
    {
        return $this->getCompiler()->getPassConfig();
    }

    /** * Returns the compiler. */
    public function getCompiler(): Compiler
    {
        return $this->compiler ??= new Compiler();
    }

    /** * Sets a service. * * @return void * * @throws BadMethodCallException When this ContainerBuilder is compiled */
$container->register('b')->addArgument(new IteratorArgument([new Reference('a')]));

        $this->process($container);

        // just make sure that an IteratorArgument does not trigger a CircularReferenceException         $this->addToAssertionCount(1);
    }

    protected function process(ContainerBuilder $container)
    {
        $compiler = new Compiler();
        $passConfig = $compiler->getPassConfig();
        $passConfig->setOptimizationPasses([
            new AnalyzeServiceReferencesPass(true),
            new CheckCircularReferencesPass(),
        ]);
        $passConfig->setRemovingPasses([]);
        $passConfig->setAfterRemovingPasses([]);

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