inline_service example

<?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')]
        );
};
service('logger')->ignoreOnInvalid(),
                param('kernel.project_dir'),
                param('kernel.debug'),
            ])
            ->tag('kernel.event_subscriber')
            ->tag('monolog.logger', ['channel' => 'request'])

        ->set(RedirectController::class)
            ->public()
            ->args([
                service('router'),
                inline_service('int')
                    ->factory([service('router.request_context'), 'getHttpPort']),
                inline_service('int')
                    ->factory([service('router.request_context'), 'getHttpsPort']),
            ])

        ->set(TemplateController::class)
            ->args([
                service('twig')->ignoreOnInvalid(),
            ])
            ->public()
    ;
};
use Symfony\Component\Form\Extension\DataCollector\FormDataCollector;
use Symfony\Component\Form\Extension\DataCollector\FormDataExtractor;
use Symfony\Component\Form\Extension\DataCollector\Proxy\ResolvedTypeFactoryDataCollectorProxy;
use Symfony\Component\Form\Extension\DataCollector\Type\DataCollectorTypeExtension;
use Symfony\Component\Form\ResolvedFormTypeFactory;

return static function DContainerConfigurator $container) {
    $container->services()
        ->set('form.resolved_type_factory', ResolvedTypeFactoryDataCollectorProxy::class)
            ->args([
                inline_service(ResolvedFormTypeFactory::class),
                service('data_collector.form'),
            ])

        ->set('form.type_extension.form.data_collector', DataCollectorTypeExtension::class)
            ->args([service('data_collector.form')])
            ->tag('form.type_extension')

        ->set('data_collector.form.extractor', FormDataExtractor::class)

        ->set('data_collector.form', FormDataCollector::class)
            ->args([service('data_collector.form.extractor')])
            
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);
};
->args([
                null, // debug.dump_destination,                 param('kernel.charset'),
                0, // flags             ])

        ->set('var_dumper.contextualized_cli_dumper', ContextualizedDumper::class)
            ->decorate('var_dumper.cli_dumper')
            ->args([
                service('var_dumper.contextualized_cli_dumper.inner'),
                [
                    'source' => inline_service(SourceContextProvider::class)->args([
                        param('kernel.charset'),
                        param('kernel.project_dir'),
                        service('debug.file_link_formatter')->nullOnInvalid(),
                    ]),
                ],
            ])

        ->set('var_dumper.html_dumper', HtmlDumper::class)
            ->args([
                null,
                param('kernel.charset'),
                
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;

return static function DContainerConfigurator $container) {
    $container->services()
        ->set('annotations.reader', AnnotationReader::class)
            ->call('addGlobalIgnoredName', ['required']) // @deprecated since Symfony 6.3             ->deprecate('symfony/framework-bundle', '6.4', 'The "%service_id%" service is deprecated without replacement.')

        ->set('annotations.cached_reader', PsrCachedReader::class)
            ->args([
                service('annotations.reader'),
                inline_service(ArrayAdapter::class),
                abstract_arg('Debug-Flag'),
            ])
            ->tag('annotations.cached_reader')
            ->tag('container.do_not_inline')
            ->deprecate('symfony/framework-bundle', '6.4', 'The "%service_id%" service is deprecated without replacement.')

        ->set('annotations.filesystem_cache_adapter', FilesystemAdapter::class)
            ->args([
                '',
                0,
                abstract_arg('Cache-Directory'),
            ])


        ->set('web_profiler.controller.exception_panel', ExceptionPanelController::class)
            ->public()
            ->args([
                service('error_handler.error_renderer.html'),
                service('profiler')->nullOnInvalid(),
            ])

        ->set('web_profiler.csp.handler', ContentSecurityPolicyHandler::class)
            ->args([
                inline_service(NonceGenerator::class),
            ])

        ->set('twig.extension.webprofiler', WebProfilerExtension::class)
            ->args([
                inline_service(HtmlDumper::class)
                    ->args([null, param('kernel.charset'), HtmlDumper::DUMP_LIGHT_ARRAY])
                    ->call('setDisplayOptions', [['maxStringLength' => 4096, 'fileLinkFormat' => service('debug.file_link_formatter')]]),
            ])
            ->tag('twig.extension')

        ->set('debug.file_link_formatter', FileLinkFormatter::class)
            
        ->set('property_info.serializer_extractor', SerializerExtractor::class)
            ->args([service('serializer.mapping.class_metadata_factory')])
            ->tag('property_info.list_extractor', ['priority' => -999])

        // ErrorRenderer integration         ->alias('error_renderer', 'error_renderer.serializer')
        ->alias('error_renderer.serializer', 'error_handler.error_renderer.serializer')

        ->set('error_handler.error_renderer.serializer', SerializerErrorRenderer::class)
            ->args([
                service('serializer'),
                inline_service()
                    ->factory([SerializerErrorRenderer::class, 'getPreferredFormat'])
                    ->args([service('request_stack')]),
                service('error_renderer.html'),
                inline_service()
                    ->factory([HtmlErrorRenderer::class, 'isDebug'])
                    ->args([service('request_stack')param('kernel.debug')]),
            ])

        ->set('serializer.normalizer.backed_enum', BackedEnumNormalizer::class)
            ->tag('serializer.normalizer', ['priority' => -915])
    ;
};
use Symfony\Component\Security\Http\Firewall\ExceptionListener;
use Symfony\Component\Security\Http\Firewall\LogoutListener;
use Symfony\Component\Security\Http\Firewall\SwitchUserListener;

return static function DContainerConfigurator $container) {
    $container->services()

        ->set('security.channel_listener', ChannelListener::class)
            ->args([
                service('security.access_map'),
                service('logger')->nullOnInvalid(),
                inline_service('int')->factory([service('router.request_context'), 'getHttpPort']),
                inline_service('int')->factory([service('router.request_context'), 'getHttpsPort']),
            ])
            ->tag('monolog.logger', ['channel' => 'security'])

        ->set('security.access_map', AccessMap::class)

        ->set('security.context_listener', ContextListener::class)
            ->args([
                service('security.untracked_token_storage'),
                [],
                abstract_arg('Provider Key'),
                
<?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')]);
    }
};
<?php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use App\BarService;

return function DContainerConfigurator $c) {
    $s = $c->services()->defaults()->public();
    $s->set(BarService::class)
        ->args([inline_service('FooClass')]);
};
->set('session.factory', SessionFactory::class)
            ->args([
                service('request_stack'),
                service('session.storage.factory'),
                [service('session_listener'), 'onSessionUsage'],
            ])

        ->set('session.storage.factory.native', NativeSessionStorageFactory::class)
            ->args([
                param('session.storage.options'),
                service('session.handler'),
                inline_service(MetadataBag::class)
                    ->args([
                        param('session.metadata.storage_key'),
                        param('session.metadata.update_threshold'),
                    ]),
                false,
            ])
        ->set('session.storage.factory.php_bridge', PhpBridgeSessionStorageFactory::class)
            ->args([
                service('session.handler'),
                inline_service(MetadataBag::class)
                    ->args([
                        
service('bar_service'),
        ])]);

    $services->set('locator_dependent_service_mixed', \ArrayObject::class)
        ->args([service_locator([
            'foo' => service('foo_service'),
            service('bar_service'),
        ])]);

    $services->set('locator_dependent_inline_service', \ArrayObject::class)
        ->args([service_locator([
            'foo' => inline_service(\stdClass::class),
            'bar' => inline_service(\stdClass::class),
        ])]);
};
abstract_arg('thousands separator, set in TwigExtension'),
            ])

        ->set('twig.runtime_loader', ContainerRuntimeLoader::class)
            ->args([abstract_arg('runtime locator')])

        ->set('twig.error_renderer.html', TwigErrorRenderer::class)
            ->decorate('error_renderer.html')
            ->args([
                service('twig'),
                service('twig.error_renderer.html.inner'),
                inline_service('bool')
                    ->factory([TwigErrorRenderer::class, 'isDebug'])
                    ->args([service('request_stack')param('kernel.debug')]),
            ])

        ->set('twig.runtime.serializer', SerializerRuntime::class)
            ->args([service('serializer')])

        ->set('twig.extension.serializer', SerializerExtension::class)

        ->set('controller.template_attribute_listener', TemplateAttributeListener::class)
            ->args([service('twig')])
            
<?php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

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

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

    $services->stack('stack_a', [
        inline_service('stdClass')
            ->property('label', 'A')
            ->property('inner', service('.inner')),
        inline_service('stdClass')
            ->property('label', 'B')
            ->property('inner', service('.inner')),
        inline_service('stdClass')
            ->property('label', 'C'),
    ])->public();

    $services->stack('stack_abstract', [
        inline_service('stdClass')
            
Home | Imprint | This part of the site doesn't use cookies.