autoconfigure example

<?php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

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

return function DContainerConfigurator $c) {
    $di = $c->services()->defaults()
        ->tag('baz');
    $di->load(Prototype::class.'\\', '../Prototype')
        ->public()
        ->autoconfigure()
        ->exclude('../Prototype/{OtherDir,BadClasses,SinglyImplementedInterface,StaticConstructor}')
        ->factory('f')
        ->deprecate('vendor/package', '1.1', '%service_id%')
        ->args([0])
        ->args([1])
        ->autoconfigure(false)
        ->tag('foo')
        ->parent('foo');
    $di->set('foo')->lazy()->abstract()->public();
    $di->get(Prototype\Foo::class)->lazy(false);
};

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo;

return function DContainerConfigurator $c) {
    $c->import('basic.php');

    $s = $c->services()->defaults()
        ->public()
        ->private()
        ->autoconfigure()
        ->autowire()
        ->tag('t', ['a' => 'b'])
        ->bind(Foo::classservice('bar'))
        ->bind('iterable $foo', tagged_iterator('foo'))
        ->public();

    $s->set(Foo::class)->args([service('bar')])->public();
    $s->set('bar', Foo::class)->call('setFoo')->autoconfigure(false);
};


        $container->services()
            ->set('nyholm.psr_factory', Psr17Factory::class)
            ->alias(ResponseFactoryInterface::class, 'nyholm.psr_factory')
            ->alias(ServerRequestFactoryInterface::class, 'nyholm.psr_factory')
            ->alias(StreamFactoryInterface::class, 'nyholm.psr_factory')
            ->alias(UploadedFileFactoryInterface::class, 'nyholm.psr_factory')
        ;

        $container->services()
            ->defaults()->autowire()->autoconfigure()
            ->set(HttpFoundationFactoryInterface::class, HttpFoundationFactory::class)
            ->set(HttpMessageFactoryInterface::class, PsrHttpFactory::class)
            ->set(PsrResponseListener::class)
            ->set(PsrServerRequestResolver::class)
        ;

        $container->services()
            ->set('logger', NullLogger::class)
            ->set(PsrRequestController::class)->public()->autowire()
        ;
    }
}
<?php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

return function DContainerConfigurator $c) {
    $c->services()->defaults()->public()
        ->set('parent_service', \stdClass::class)
        ->set('child_service')->parent('parent_service')->autoconfigure(true);
};

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo;

return function DContainerConfigurator $c) {
    $c->import('basic.php');

    $s = $c->services()->defaults()
        ->public()
        ->private()
        ->autoconfigure()
        ->autowire()
        ->tag('t', ['a' => 'b'])
        ->bind(Foo::classservice('bar'))
        ->bind('iterable $foo', tagged_iterator('foo'))
        ->bind('object $baz', inline_service('Baz'))
        ->public();

    $s->set(Foo::class)->args([service('bar')])->public();
    $s->set('bar', Foo::class)->call('setFoo')->autoconfigure(false);
};
<?php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

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

return function DContainerConfigurator $c) {
    $di = $c->services()->defaults()
        ->tag('baz');
    $di->load(Prototype::class.'\\', '../Prototype')
        ->public()
        ->autoconfigure()
        ->exclude(['../Prototype/OtherDir', '../Prototype/BadClasses', '../Prototype/SinglyImplementedInterface', '../Prototype/StaticConstructor'])
        ->factory('f')
        ->deprecate('vendor/package', '1.1', '%service_id%')
        ->args([0])
        ->args([1])
        ->autoconfigure(false)
        ->tag('foo')
        ->parent('foo');
    $di->set('foo')->lazy()->abstract()->public();
    $di->get(Prototype\Foo::class)->lazy(false);
};
Home | Imprint | This part of the site doesn't use cookies.