services example



namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Bundle\FrameworkBundle\CacheWarmer\CachePoolClearerCacheWarmer;
use Symfony\Component\Cache\DataCollector\CacheDataCollector;

return static function DContainerConfigurator $container) {
    $container->services()
        // DataCollector (public to prevent inlining, made private in CacheCollectorPass)         ->set('data_collector.cache', CacheDataCollector::class)
            ->public()
            ->tag('data_collector', [
                'template' => '@WebProfiler/Collector/cache.html.twig',
                'id' => 'cache',
                'priority' => 275,
            ])

        // CacheWarmer used in dev to clear cache pool         ->set('cache_pool_clearer.cache_warmer', CachePoolClearerCacheWarmer::class)
            


namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Component\HttpKernel\EventListener\SurrogateListener;
use Symfony\Component\HttpKernel\HttpCache\Esi;

return static function DContainerConfigurator $container) {
    $container->services()
        ->set('esi', Esi::class)

        ->set('esi_listener', SurrogateListener::class)
            ->args([service('esi')->ignoreOnInvalid()])
            ->tag('kernel.event_subscriber')
    ;
};


namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer;

return static function DContainerConfigurator $container) {
    $container->services()
        ->set('error_handler.error_renderer.html', HtmlErrorRenderer::class)
            ->args([
                inline_service()
                    ->factory([HtmlErrorRenderer::class, 'isDebug'])
                    ->args([
                        service('request_stack'),
                        param('kernel.debug'),
                    ]),
                param('kernel.charset'),
                service('debug.file_link_formatter')->nullOnInvalid(),
                param('kernel.project_dir'),
                


namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Component\Uid\Factory\NameBasedUuidFactory;
use Symfony\Component\Uid\Factory\RandomBasedUuidFactory;
use Symfony\Component\Uid\Factory\TimeBasedUuidFactory;
use Symfony\Component\Uid\Factory\UlidFactory;
use Symfony\Component\Uid\Factory\UuidFactory;

return static function DContainerConfigurator $container) {
    $container->services()
        ->set('ulid.factory', UlidFactory::class)
        ->alias(UlidFactory::class, 'ulid.factory')

        ->set('uuid.factory', UuidFactory::class)
        ->alias(UuidFactory::class, 'uuid.factory')

        ->set('name_based_uuid.factory', NameBasedUuidFactory::class)
            ->factory([service('uuid.factory'), 'nameBased'])
            ->args([abstract_arg('Please set the "framework.uid.name_based_uuid_namespace" configuration option to use the "name_based_uuid.factory" service')])
        ->alias(NameBasedUuidFactory::class, 'name_based_uuid.factory')

        


namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Bridge\Twig\Extension\LogoutUrlExtension;
use Symfony\Bridge\Twig\Extension\SecurityExtension;

return static function DContainerConfigurator $container) {
    $container->services()
        ->set('twig.extension.logout_url', LogoutUrlExtension::class)
            ->args([
                service('security.logout_url_generator'),
            ])
            ->tag('twig.extension')

        ->set('twig.extension.security', SecurityExtension::class)
            ->args([
                service('security.authorization_checker')->ignoreOnInvalid(),
                service('security.impersonate_url_generator')->ignoreOnInvalid(),
            ])
            

        $container->extension('framework', [
            'router' => ['utf8' => true],
            'secret' => 'for your eyes only',
            'test' => true,
            'annotations' => false,
            'http_method_override' => false,
            'handle_all_throwables' => true,
            'php_errors' => ['log' => true],
        ]);

        $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)
            
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Component\Mailer\Bridge\Mailgun\RemoteEvent\MailgunPayloadConverter;
use Symfony\Component\Mailer\Bridge\Mailgun\Webhook\MailgunRequestParser;
use Symfony\Component\Mailer\Bridge\Postmark\RemoteEvent\PostmarkPayloadConverter;
use Symfony\Component\Mailer\Bridge\Postmark\Webhook\PostmarkRequestParser;
use Symfony\Component\Mailer\Bridge\Sendgrid\RemoteEvent\SendgridPayloadConverter;
use Symfony\Component\Mailer\Bridge\Sendgrid\Webhook\SendgridRequestParser;

return static function DContainerConfigurator $container) {
    $container->services()
        ->set('mailer.payload_converter.mailgun', MailgunPayloadConverter::class)
        ->set('mailer.webhook.request_parser.mailgun', MailgunRequestParser::class)
            ->args([service('mailer.payload_converter.mailgun')])
        ->alias(MailgunRequestParser::class, 'mailer.webhook.request_parser.mailgun')

        ->set('mailer.payload_converter.postmark', PostmarkPayloadConverter::class)
        ->set('mailer.webhook.request_parser.postmark', PostmarkRequestParser::class)
            ->args([service('mailer.payload_converter.postmark')])
        ->alias(PostmarkRequestParser::class, 'mailer.webhook.request_parser.postmark')

        ->set('mailer.payload_converter.sendgrid', SendgridPayloadConverter::class)
        


namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Component\HttpKernel\Controller\ArgumentResolver\NotTaggedControllerValueResolver;
use Symfony\Component\HttpKernel\Controller\TraceableArgumentResolver;
use Symfony\Component\HttpKernel\Controller\TraceableControllerResolver;
use Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher;

return static function DContainerConfigurator $container) {
    $container->services()
        ->set('debug.event_dispatcher', TraceableEventDispatcher::class)
            ->decorate('event_dispatcher')
            ->args([
                service('debug.event_dispatcher.inner'),
                service('debug.stopwatch'),
                service('logger')->nullOnInvalid(),
                service('request_stack')->nullOnInvalid(),
            ])
            ->tag('monolog.logger', ['channel' => 'event'])
            ->tag('kernel.reset', ['method' => 'reset'])

        


namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Component\Notifier\Bridge;
use Symfony\Component\Notifier\Transport\AbstractTransportFactory;
use Symfony\Component\Notifier\Transport\NullTransportFactory;

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

        ->set('notifier.transport_factory.abstract', AbstractTransportFactory::class)
            ->abstract()
            ->args([service('event_dispatcher')service('http_client')->ignoreOnInvalid()])

        ->set('notifier.transport_factory.brevo', Bridge\Brevo\BrevoTransportFactory::class)
            ->parent('notifier.transport_factory.abstract')
            ->tag('texter.transport_factory')

        ->set('notifier.transport_factory.slack', Bridge\Slack\SlackTransportFactory::class)
            ->parent('notifier.transport_factory.abstract')
            


namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Component\Semaphore\SemaphoreFactory;

return static function DContainerConfigurator $container) {
    $container->services()
        ->set('semaphore.factory.abstract', SemaphoreFactory::class)->abstract()
            ->args([abstract_arg('Store')])
            ->call('setLogger', [service('logger')->ignoreOnInvalid()])
            ->tag('monolog.logger', ['channel' => 'semaphore'])
    ;
};
<?php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

return function DContainerConfigurator $c) {
    $di = $c->services()->defaults()->public();
    $di->set('foo', 'stdClass')->lazy('SomeInterface');
};
<?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')]);
};
use Symfony\Component\Mailer\Bridge\Postmark\Transport\PostmarkTransportFactory;
use Symfony\Component\Mailer\Bridge\Scaleway\Transport\ScalewayTransportFactory;
use Symfony\Component\Mailer\Bridge\Sendgrid\Transport\SendgridTransportFactory;
use Symfony\Component\Mailer\Bridge\Sendinblue\Transport\SendinblueTransportFactory;
use Symfony\Component\Mailer\Transport\AbstractTransportFactory;
use Symfony\Component\Mailer\Transport\NativeTransportFactory;
use Symfony\Component\Mailer\Transport\NullTransportFactory;
use Symfony\Component\Mailer\Transport\SendmailTransportFactory;
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransportFactory;

return static function DContainerConfigurator $container) {
    $container->services()
        ->set('mailer.transport_factory.abstract', AbstractTransportFactory::class)
            ->abstract()
            ->args([
                service('event_dispatcher'),
                service('http_client')->ignoreOnInvalid(),
                service('logger')->ignoreOnInvalid(),
            ])
            ->tag('monolog.logger', ['channel' => 'mailer'])

        ->set('mailer.transport_factory.amazon', SesTransportFactory::class)
            ->parent('mailer.transport_factory.abstract')
            


namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Component\RemoteEvent\Messenger\ConsumeRemoteEventHandler;

return static function DContainerConfigurator $container) {
    $container->services()
        ->set('remote_event.messenger.handler', ConsumeRemoteEventHandler::class)
            ->args([
                tagged_locator('remote_event.consumer', 'consumer'),
            ])
            ->tag('messenger.message_handler')
    ;
};


namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Bundle\SecurityBundle\DataCollector\SecurityDataCollector;

return static function DContainerConfigurator $container) {
    $container->services()
        ->set('data_collector.security', SecurityDataCollector::class)
            ->args([
                service('security.untracked_token_storage'),
                service('security.role_hierarchy'),
                service('security.logout_url_generator'),
                service('security.access.decision_manager'),
                service('security.firewall.map'),
                service('debug.security.firewall')->nullOnInvalid(),
            ])
            ->tag('data_collector', [
                'template' => '@Security/Collector/security.html.twig',
                
Home | Imprint | This part of the site doesn't use cookies.