constructor example


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 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) {
    $s = $c->services()->defaults()->public();

    $s->set('foo', 'Bar\FooClass')->constructor('getInstance');
};
Home | Imprint | This part of the site doesn't use cookies.