Repository: symfony/symfony
File: src/Symfony/Bundle/FrameworkBundle/Resources/config/messenger.php (PHP)

Code before:
            ->call('setLogger', [service('logger')->ignoreOnInvalid()])
            ->tag('monolog.logger', ['channel' => 'messenger'])

        // Message encoding/decoding
        ->set('messenger.transport.symfony_serializer', Serializer::class)
            ->args([
                service('serializer'),
                abstract_arg('format'),
                abstract_arg('context'),
            ])

        ->set('serializer.normalizer.flatten_exception', FlattenExceptionNormalizer::class)
            ->tag('serializer.normalizer', ['built_in' => true, 'priority' => -880])

        ->set('messenger.transport.native_php_serializer', PhpSerializer::class)
        ->alias('messenger.default_serializer', 'messenger.transport.native_php_serializer')
        ->alias(SerializerInterface::class, 'messenger.default_serializer')

        ->set('messenger.signing_serializer', SigningSerializer::class)
            ->abstract()
            ->args([
                service('.inner'),
                inline_service('string') // wrap the signing key in a lazy string to prevent a hard dependency on the kernel.secret parameter
                    ->factory(class_exists(LazyString::class) ? [LazyString::class, 'fromCallable'] : 'current')
                    ->args([
                        class_exists(LazyString::class) ? service_closure('.messenger.signing_serializer.signing_key') : [new Parameter('kernel.secret')],
                    ]),
                abstract_arg('message types to serializers'), // read and replaced by MessengerPass
            ])
        ->set('.messenger.signing_serializer.signing_key', 'string')
            ->factory('current')
            ->args([[new Parameter('kernel.secret')]])

        // Middleware
        ->set('messenger.middleware.handle_message', HandleMessageMiddleware::class)
            ->abstract()
            ->args([
                abstract_arg('bus handler resolver'),
            ])
            ->tag('monolog.logger', ['channel' => 'messenger'])
            ->call('setLogger', [service('logger')->ignoreOnInvalid()])

        ->set('messenger.middleware.deduplicate_middleware', DeduplicateMiddleware::class)
            ->args([
                service('lock.factory'),
            ])

        ->set('messenger.middleware.add_default_stamps_middleware', AddDefaultStampsMiddleware::class)

        ->set('messenger.middleware.add_bus_name_stamp_middleware', AddBusNameStampMiddleware::class)
            ->abstract()

Review comment (security):
No need to trigger the autoloader twice.
```suggestion
                        class_exists(LazyString::class, false) ? service_closure('.messenger.signing_serializer.signing_key') : [new Parameter('kernel.secret')],
```

Code after:
            ->call('setLogger', [service('logger')->ignoreOnInvalid()])
            ->tag('monolog.logger', ['channel' => 'messenger'])

        // Message encoding/decoding
        ->set('messenger.transport.symfony_serializer', Serializer::class)
            ->args([
                service('serializer'),
                abstract_arg('format'),
                abstract_arg('context'),
            ])

        ->set('serializer.normalizer.flatten_exception', FlattenExceptionNormalizer::class)
            ->tag('serializer.normalizer', ['built_in' => true, 'priority' => -880])

        ->set('messenger.transport.native_php_serializer', PhpSerializer::class)
        ->alias('messenger.default_serializer', 'messenger.transport.native_php_serializer')
        ->alias(SerializerInterface::class, 'messenger.default_serializer')

        ->set('messenger.signing_serializer', SigningSerializer::class)
            ->abstract()
            ->args([
                service('.inner'),
                inline_service('string') // wrap the signing key in a lazy string to prevent a hard dependency on the kernel.secret parameter
                    ->factory(class_exists(LazyString::class) ? [LazyString::class, 'fromCallable'] : 'current')
                    ->args([
                        class_exists(LazyString::class, false) ? service_closure('.messenger.signing_serializer.signing_key') : [new Parameter('kernel.secret')],
                    ]),
                abstract_arg('message types to serializers'), // read and replaced by MessengerPass
            ])
        ->set('.messenger.signing_serializer.signing_key', 'string')
            ->factory('current')
            ->args([[new Parameter('kernel.secret')]])

        // Middleware
        ->set('messenger.middleware.handle_message', HandleMessageMiddleware::class)
            ->abstract()
            ->args([
                abstract_arg('bus handler resolver'),
            ])
            ->tag('monolog.logger', ['channel' => 'messenger'])
            ->call('setLogger', [service('logger')->ignoreOnInvalid()])

        ->set('messenger.middleware.deduplicate_middleware', DeduplicateMiddleware::class)
            ->args([
                service('lock.factory'),
            ])

        ->set('messenger.middleware.add_default_stamps_middleware', AddDefaultStampsMiddleware::class)

        ->set('messenger.middleware.add_bus_name_stamp_middleware', AddBusNameStampMiddleware::class)
            ->abstract()