InlineServiceDefinitionsPass example

new CheckReferenceValidityPass(),
            new CheckArgumentsValidityPass(false),
        ]];

        $this->removingPasses = [[
            new RemovePrivateAliasesPass(),
            new ReplaceAliasByActualDefinitionPass(),
            new RemoveAbstractDefinitionsPass(),
            new RemoveUnusedDefinitionsPass(),
            new AnalyzeServiceReferencesPass(),
            new CheckExceptionOnInvalidReferenceBehaviorPass(),
            new InlineServiceDefinitionsPass(new AnalyzeServiceReferencesPass()),
            new AnalyzeServiceReferencesPass(),
            new DefinitionErrorExceptionPass(),
        ]];

        $this->afterRemovingPasses = [
            0 => [
                new ResolveHotPathPass(),
                new ResolveNoPreloadPass(),
                new AliasDeprecatedPublicServicesPass(),
            ],
            // Let build parameters be available as late as possible


    public function testWithErroredServiceLocator()
    {
        $this->expectException(ServiceNotFoundException::class);
        $this->expectExceptionMessage('The service "foo" in the container provided to "bar" has a dependency on a non-existent service "baz".');
        $container = new ContainerBuilder();

        ServiceLocatorTagPass::register($container['foo' => new Reference('baz')], 'bar');

        (new AnalyzeServiceReferencesPass())->process($container);
        (new InlineServiceDefinitionsPass())->process($container);
        $this->process($container);
    }

    public function testWithErroredHiddenService()
    {
        $this->expectException(ServiceNotFoundException::class);
        $this->expectExceptionMessage('The service "bar" has a dependency on a non-existent service "foo".');
        $container = new ContainerBuilder();

        ServiceLocatorTagPass::register($container['foo' => new Reference('foo')], 'bar');

        (
new CheckReferenceValidityPass(),
            new CheckArgumentsValidityPass(false),
        ]];

        $this->removingPasses = [[
            new RemovePrivateAliasesPass(),
            new ReplaceAliasByActualDefinitionPass(),
            new RemoveAbstractDefinitionsPass(),
            new RemoveUnusedDefinitionsPass(),
            new AnalyzeServiceReferencesPass(),
            new CheckExceptionOnInvalidReferenceBehaviorPass(),
            new InlineServiceDefinitionsPass(new AnalyzeServiceReferencesPass()),
            new AnalyzeServiceReferencesPass(),
            new DefinitionErrorExceptionPass(),
        ]];

        $this->afterRemovingPasses = [
            0 => [
                new ResolveHotPathPass(),
                new ResolveNoPreloadPass(),
                new AliasDeprecatedPublicServicesPass(),
            ],
            // Let build parameters be available as late as possible
$container->compile();

        $this->assertFalse($container->hasAlias('alias2'));
        $this->assertEquals(new Reference('decorated2')$container->getDefinition('s2')->getProperties()['inner']);
        $this->assertEquals(new Reference('s1.inner')$container->getDefinition('s1')->getProperties()['inner']);
        $this->assertSame('decorated2', $container->getDefinition('decorated2')->getClass());
        $this->assertSame('decorated1', $container->getDefinition('s1.inner')->getClass());
    }

    protected function process(ContainerBuilder $container)
    {
        (new InlineServiceDefinitionsPass(new AnalyzeServiceReferencesPass()))->process($container);
    }
}
Home | Imprint | This part of the site doesn't use cookies.