defaults example

<?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);
};
<?php
namespace Symfony\Component\Routing\Loader\Configurator;

return function DRoutingConfigurator $routes) {
    $collection = $routes->collection();
    $collection
        ->methods(['GET'])
        ->defaults(['attribute' => true])
        ->stateless();

    $collection->add('defaultsA', '/defaultsA')
        ->locale('en')
        ->format('html');

    $collection->add('defaultsB', '/defaultsB')
        ->methods(['POST'])
        ->stateless(false)
        ->locale('en')
        ->format('html');
};
<?php
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);
};
use Symfony\Component\DependencyInjection\Reference;

require_once __DIR__.'/../includes/classes.php';
require_once __DIR__.'/../includes/foo.php';

return function DContainerConfigurator $c) {
    $p = $c->parameters();
    $p->set('baz_class', 'BazClass');
    $p->set('foo_class', FooClass::class)
      ->set('foo', 'bar');

    $s = $c->services()->defaults()->public();
    $s->set('foo')
        ->args(['foo', service('foo.baz')['%foo%' => 'foo is %foo%', 'foobar' => '%foo%'], true, service('service_container')])
        ->class(FooClass::class)
        ->tag('foo', ['foo' => 'foo'])
        ->tag('foo', ['bar' => 'bar', 'baz' => 'baz'])
        ->tag('foo', ['name' => 'bar', 'baz' => 'baz'])
        ->factory([FooClass::class, 'getInstance'])
        ->property('foo', 'bar')
        ->property('moo', service('foo.baz'))
        ->property('qux', ['%foo%' => 'foo is %foo%', 'foobar' => '%foo%'])
        ->call('setBar', [service('bar')])
        
<?php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

return function DContainerConfigurator $c) {
    $s = $c->services()->defaults()->public();

    $s->set('foo', 'Foo');

    $s->set('service_closure', 'Bar')
        ->args([service_closure('foo')]);

    $s->set('service_closure_invalid', 'Bar')
        ->args([service_closure('invalid_service')->nullOnInvalid()]);
};


        $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;

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

return function DContainerConfigurator $c) {
    $c->parameters()
        ('foo', 'Foo')
        ('bar', 'Bar')
    ;
    $c->services()->defaults()->public()
        (Foo::class)
            ->arg('$bar', service('bar'))
            ->public()
        ('bar', Foo::class)
            ->call('setFoo')
    ;
};
<?php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\StaticConstructor\PrototypeStaticConstructor;
use Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\StaticConstructor\PrototypeStaticConstructorInterface;

return function DContainerConfigurator $c) {
    $s = $c->services()->defaults()->public();
    $s->instanceof(PrototypeStaticConstructorInterface::class)
        ->constructor('create');

    $s->set('foo', PrototypeStaticConstructor::class);
};
<?php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

return function DContainerConfigurator $c) {
    $services = $c->services()->defaults()->public();

    $services
        ->set('foo', FooService::class)
        ->remove('foo')

        ->set('baz', BazService::class)
        ->alias('baz-alias', 'baz')
        ->remove('baz-alias')

        ->remove('bat'); // noop };
<?php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Bar\FooClass;
use stdClass;
use Symfony\Component\DependencyInjection\Tests\Fixtures\StdClassDecorator;

return function DContainerConfigurator $c) {
    $s = $c->services()->defaults()->public();

    $s->set('decorated', stdClass::class);

    $s->set(null, StdClassDecorator::class)
        ->decorate('decorated', 'decorator42')
        ->args([service('decorator42')]);

    $s->set('listener_aggregator', FooClass::class)->public()->args([tagged_iterator('listener')]);

    $s->set(null, stdClass::class)->tag('listener');
};
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Tests\Fixtures\FooClassWithEnumAttribute;
use Symfony\Component\DependencyInjection\Tests\Fixtures\FooUnitEnum;

return function DContainerConfigurator $container) {
    $container->parameters()
        ->set('unit_enum', FooUnitEnum::BAR)
        ->set('enum_array', [FooUnitEnum::BAR, FooUnitEnum::FOO]);

    $services = $container->services();

    $services->defaults()->public();

    $services->set('service_container', ContainerInterface::class)
        ->synthetic();

    $services->set(FooClassWithEnumAttribute::class)
        ->args([FooUnitEnum::BAR]);
};
<?php
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();
    
<?php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\StaticConstructor\PrototypeStaticConstructor;
use Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\StaticConstructor\PrototypeStaticConstructorAsArgument;

return function DContainerConfigurator $c) {
    $s = $c->services()->defaults()->public();
    $s->set('foo', PrototypeStaticConstructorAsArgument::class)
        ->args(
            [inline_service(PrototypeStaticConstructor::class)
                ->constructor('create')]
        );
};
<?php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use App\BarService;

return new class() {
    public function __invoke(ContainerConfigurator $c)
    {
        $s = $c->services()->defaults()->public();
        $s->set(BarService::class)
            ->args([inline_service('FooClass')]);
    }
};
$routes->import('php_dsl_sub.php')
        ->namePrefix('z_')
        ->prefix('/zub');

    $routes->import('php_dsl_sub_root.php')
        ->prefix('/bus', false);

    $routes->add('ouf', '/ouf')
        ->schemes(['https'])
        ->methods(['GET'])
        ->defaults(['id' => 0]);
};
Home | Imprint | This part of the site doesn't use cookies.