share example

return static function DContainerConfigurator $container) {
    $container->parameters()->set('test.client.parameters', []);

    $container->services()
        ->set('test.client', KernelBrowser::class)
            ->args([
                service('kernel'),
                param('test.client.parameters'),
                service('test.client.history'),
                service('test.client.cookiejar'),
            ])
            ->share(false)
            ->public()

        ->set('test.client.history', History::class)->share(false)
        ->set('test.client.cookiejar', CookieJar::class)->share(false)

        ->set('test.session.listener', SessionListener::class)
            ->args([
                service_locator([
                    'session_factory' => service('session.factory')->ignoreOnInvalid(),
                ]),
                param('kernel.debug'),
                
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use App\FooService;
use Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype;

return function DContainerConfigurator $c) {
    $s = $c->services()->defaults()->public();
    $s->instanceof(Prototype\Foo::class)
        ->property('p', 0)
        ->call('setFoo', [service('foo')])
        ->tag('tag', ['k' => 'v'])
        ->share(false)
        ->lazy()
        ->configurator('c')
        ->property('p', 1);

    $s->load(Prototype::class.'\\', '../Prototype')->exclude('../Prototype/*/*');

    $s->set('foo', FooService::class);
};
$s->set('foo.baz', '%baz_class%')
        ->factory(['%baz_class%', 'getInstance'])
        ->configurator(['%baz_class%', 'configureStatic1']);

    $s->set('bar', FooClass::class)
        ->args(['foo', service('foo.baz')new Parameter('foo_bar')])
        ->configurator([service('foo.baz'), 'configure']);

    $s->set('foo_bar', '%foo_class%')
        ->args([service('deprecated_service')])
        ->share(false);

    $s->set('method_call1', 'Bar\FooClass')
        ->file(realpath(__DIR__.'/../includes/foo.php'))
        ->call('setBar', [service('foo')])
        ->call('setBar', [service('foo2')->nullOnInvalid()])
        ->call('setBar', [service('foo3')->ignoreOnInvalid()])
        ->call('setBar', [service('foobaz')->ignoreOnInvalid()])
        ->call('setBar', [expr('service("foo").foo() ~ (container.hasParameter("foo") ? parameter("foo") : "default")')]);

    $s->set('foo_with_inline', 'Foo')
        ->call('setBar', [service('inlined')]);

    

            ->tag('console.command')

        ->set('console.command.secrets_encrypt_from_local', SecretsEncryptFromLocalCommand::class)
            ->args([
                service('secrets.vault'),
                service('secrets.local_vault')->ignoreOnInvalid(),
            ])
            ->tag('console.command')

        ->set('console.messenger.application', Application::class)
            ->share(false)
            ->call('setAutoExit', [false])
            ->args([
                service('kernel'),
            ])

        ->set('console.messenger.execute_command_handler', RunCommandMessageHandler::class)
            ->args([
                service('console.messenger.application'),
            ])
            ->tag('messenger.message_handler')
    ;
};
Home | Imprint | This part of the site doesn't use cookies.