vendor/symfony/framework-bundle/DependencyInjection/FrameworkExtension.php line 353

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Bundle\FrameworkBundle\DependencyInjection;
  11. use Composer\InstalledVersions;
  12. use Doctrine\Common\Annotations\AnnotationRegistry;
  13. use Doctrine\Common\Annotations\Reader;
  14. use Http\Client\HttpClient;
  15. use phpDocumentor\Reflection\DocBlockFactoryInterface;
  16. use phpDocumentor\Reflection\Types\ContextFactory;
  17. use PHPStan\PhpDocParser\Parser\PhpDocParser;
  18. use Psr\Cache\CacheItemPoolInterface;
  19. use Psr\Container\ContainerInterface as PsrContainerInterface;
  20. use Psr\EventDispatcher\EventDispatcherInterface as PsrEventDispatcherInterface;
  21. use Psr\Http\Client\ClientInterface;
  22. use Psr\Log\LoggerAwareInterface;
  23. use Symfony\Bridge\Monolog\Processor\DebugProcessor;
  24. use Symfony\Bridge\Twig\Extension\CsrfExtension;
  25. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  26. use Symfony\Bundle\FrameworkBundle\Routing\AnnotatedRouteControllerLoader;
  27. use Symfony\Bundle\FrameworkBundle\Routing\RouteLoaderInterface;
  28. use Symfony\Bundle\FullStack;
  29. use Symfony\Bundle\MercureBundle\MercureBundle;
  30. use Symfony\Component\Asset\PackageInterface;
  31. use Symfony\Component\BrowserKit\AbstractBrowser;
  32. use Symfony\Component\Cache\Adapter\AdapterInterface;
  33. use Symfony\Component\Cache\Adapter\ArrayAdapter;
  34. use Symfony\Component\Cache\Adapter\ChainAdapter;
  35. use Symfony\Component\Cache\Adapter\DoctrineAdapter;
  36. use Symfony\Component\Cache\Adapter\DoctrineDbalAdapter;
  37. use Symfony\Component\Cache\Adapter\TagAwareAdapter;
  38. use Symfony\Component\Cache\DependencyInjection\CachePoolPass;
  39. use Symfony\Component\Cache\Marshaller\DefaultMarshaller;
  40. use Symfony\Component\Cache\Marshaller\MarshallerInterface;
  41. use Symfony\Component\Cache\ResettableInterface;
  42. use Symfony\Component\Config\FileLocator;
  43. use Symfony\Component\Config\Loader\LoaderInterface;
  44. use Symfony\Component\Config\Resource\DirectoryResource;
  45. use Symfony\Component\Config\ResourceCheckerInterface;
  46. use Symfony\Component\Console\Application;
  47. use Symfony\Component\Console\Command\Command;
  48. use Symfony\Component\DependencyInjection\Alias;
  49. use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
  50. use Symfony\Component\DependencyInjection\ChildDefinition;
  51. use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
  52. use Symfony\Component\DependencyInjection\ContainerBuilder;
  53. use Symfony\Component\DependencyInjection\ContainerInterface;
  54. use Symfony\Component\DependencyInjection\Definition;
  55. use Symfony\Component\DependencyInjection\EnvVarLoaderInterface;
  56. use Symfony\Component\DependencyInjection\EnvVarProcessorInterface;
  57. use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
  58. use Symfony\Component\DependencyInjection\Exception\LogicException;
  59. use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
  60. use Symfony\Component\DependencyInjection\Parameter;
  61. use Symfony\Component\DependencyInjection\Reference;
  62. use Symfony\Component\DependencyInjection\ServiceLocator;
  63. use Symfony\Component\Dotenv\Command\DebugCommand;
  64. use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
  65. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  66. use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
  67. use Symfony\Component\Finder\Finder;
  68. use Symfony\Component\Form\ChoiceList\Factory\CachingFactoryDecorator;
  69. use Symfony\Component\Form\Form;
  70. use Symfony\Component\Form\FormTypeExtensionInterface;
  71. use Symfony\Component\Form\FormTypeGuesserInterface;
  72. use Symfony\Component\Form\FormTypeInterface;
  73. use Symfony\Component\HttpClient\MockHttpClient;
  74. use Symfony\Component\HttpClient\Retry\GenericRetryStrategy;
  75. use Symfony\Component\HttpClient\RetryableHttpClient;
  76. use Symfony\Component\HttpClient\ScopingHttpClient;
  77. use Symfony\Component\HttpFoundation\Request;
  78. use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface;
  79. use Symfony\Component\HttpKernel\Attribute\AsController;
  80. use Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface;
  81. use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
  82. use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
  83. use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface;
  84. use Symfony\Component\HttpKernel\DependencyInjection\Extension;
  85. use Symfony\Component\Lock\Lock;
  86. use Symfony\Component\Lock\LockFactory;
  87. use Symfony\Component\Lock\LockInterface;
  88. use Symfony\Component\Lock\PersistingStoreInterface;
  89. use Symfony\Component\Lock\Store\StoreFactory;
  90. use Symfony\Component\Lock\StoreInterface;
  91. use Symfony\Component\Mailer\Bridge\Amazon\Transport\SesTransportFactory;
  92. use Symfony\Component\Mailer\Bridge\Google\Transport\GmailTransportFactory;
  93. use Symfony\Component\Mailer\Bridge\Mailchimp\Transport\MandrillTransportFactory;
  94. use Symfony\Component\Mailer\Bridge\Mailgun\Transport\MailgunTransportFactory;
  95. use Symfony\Component\Mailer\Bridge\Mailjet\Transport\MailjetTransportFactory;
  96. use Symfony\Component\Mailer\Bridge\OhMySmtp\Transport\OhMySmtpTransportFactory;
  97. use Symfony\Component\Mailer\Bridge\Postmark\Transport\PostmarkTransportFactory;
  98. use Symfony\Component\Mailer\Bridge\Sendgrid\Transport\SendgridTransportFactory;
  99. use Symfony\Component\Mailer\Bridge\Sendinblue\Transport\SendinblueTransportFactory;
  100. use Symfony\Component\Mailer\Mailer;
  101. use Symfony\Component\Mercure\HubRegistry;
  102. use Symfony\Component\Messenger\Attribute\AsMessageHandler;
  103. use Symfony\Component\Messenger\Bridge\AmazonSqs\Transport\AmazonSqsTransportFactory;
  104. use Symfony\Component\Messenger\Bridge\Amqp\Transport\AmqpTransportFactory;
  105. use Symfony\Component\Messenger\Bridge\Beanstalkd\Transport\BeanstalkdTransportFactory;
  106. use Symfony\Component\Messenger\Bridge\Redis\Transport\RedisTransportFactory;
  107. use Symfony\Component\Messenger\Handler\BatchHandlerInterface;
  108. use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
  109. use Symfony\Component\Messenger\MessageBus;
  110. use Symfony\Component\Messenger\MessageBusInterface;
  111. use Symfony\Component\Messenger\Middleware\RouterContextMiddleware;
  112. use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
  113. use Symfony\Component\Messenger\Transport\TransportFactoryInterface;
  114. use Symfony\Component\Messenger\Transport\TransportInterface;
  115. use Symfony\Component\Mime\Header\Headers;
  116. use Symfony\Component\Mime\MimeTypeGuesserInterface;
  117. use Symfony\Component\Mime\MimeTypes;
  118. use Symfony\Component\Notifier\Bridge\AllMySms\AllMySmsTransportFactory;
  119. use Symfony\Component\Notifier\Bridge\AmazonSns\AmazonSnsTransportFactory;
  120. use Symfony\Component\Notifier\Bridge\Clickatell\ClickatellTransportFactory;
  121. use Symfony\Component\Notifier\Bridge\Discord\DiscordTransportFactory;
  122. use Symfony\Component\Notifier\Bridge\Esendex\EsendexTransportFactory;
  123. use Symfony\Component\Notifier\Bridge\Expo\ExpoTransportFactory;
  124. use Symfony\Component\Notifier\Bridge\FakeChat\FakeChatTransportFactory;
  125. use Symfony\Component\Notifier\Bridge\FakeSms\FakeSmsTransportFactory;
  126. use Symfony\Component\Notifier\Bridge\Firebase\FirebaseTransportFactory;
  127. use Symfony\Component\Notifier\Bridge\FreeMobile\FreeMobileTransportFactory;
  128. use Symfony\Component\Notifier\Bridge\GatewayApi\GatewayApiTransportFactory;
  129. use Symfony\Component\Notifier\Bridge\Gitter\GitterTransportFactory;
  130. use Symfony\Component\Notifier\Bridge\GoogleChat\GoogleChatTransportFactory;
  131. use Symfony\Component\Notifier\Bridge\Infobip\InfobipTransportFactory;
  132. use Symfony\Component\Notifier\Bridge\Iqsms\IqsmsTransportFactory;
  133. use Symfony\Component\Notifier\Bridge\LightSms\LightSmsTransportFactory;
  134. use Symfony\Component\Notifier\Bridge\LinkedIn\LinkedInTransportFactory;
  135. use Symfony\Component\Notifier\Bridge\Mailjet\MailjetTransportFactory as MailjetNotifierTransportFactory;
  136. use Symfony\Component\Notifier\Bridge\Mattermost\MattermostTransportFactory;
  137. use Symfony\Component\Notifier\Bridge\Mercure\MercureTransportFactory;
  138. use Symfony\Component\Notifier\Bridge\MessageBird\MessageBirdTransport;
  139. use Symfony\Component\Notifier\Bridge\MessageMedia\MessageMediaTransportFactory;
  140. use Symfony\Component\Notifier\Bridge\MicrosoftTeams\MicrosoftTeamsTransportFactory;
  141. use Symfony\Component\Notifier\Bridge\Mobyt\MobytTransportFactory;
  142. use Symfony\Component\Notifier\Bridge\Nexmo\NexmoTransportFactory;
  143. use Symfony\Component\Notifier\Bridge\Octopush\OctopushTransportFactory;
  144. use Symfony\Component\Notifier\Bridge\OneSignal\OneSignalTransportFactory;
  145. use Symfony\Component\Notifier\Bridge\OvhCloud\OvhCloudTransportFactory;
  146. use Symfony\Component\Notifier\Bridge\RocketChat\RocketChatTransportFactory;
  147. use Symfony\Component\Notifier\Bridge\Sendinblue\SendinblueTransportFactory as SendinblueNotifierTransportFactory;
  148. use Symfony\Component\Notifier\Bridge\Sinch\SinchTransportFactory;
  149. use Symfony\Component\Notifier\Bridge\Slack\SlackTransportFactory;
  150. use Symfony\Component\Notifier\Bridge\Sms77\Sms77TransportFactory;
  151. use Symfony\Component\Notifier\Bridge\Smsapi\SmsapiTransportFactory;
  152. use Symfony\Component\Notifier\Bridge\SmsBiuras\SmsBiurasTransportFactory;
  153. use Symfony\Component\Notifier\Bridge\Smsc\SmscTransportFactory;
  154. use Symfony\Component\Notifier\Bridge\SpotHit\SpotHitTransportFactory;
  155. use Symfony\Component\Notifier\Bridge\Telegram\TelegramTransportFactory;
  156. use Symfony\Component\Notifier\Bridge\Telnyx\TelnyxTransportFactory;
  157. use Symfony\Component\Notifier\Bridge\TurboSms\TurboSmsTransport;
  158. use Symfony\Component\Notifier\Bridge\Twilio\TwilioTransportFactory;
  159. use Symfony\Component\Notifier\Bridge\Vonage\VonageTransportFactory;
  160. use Symfony\Component\Notifier\Bridge\Yunpian\YunpianTransportFactory;
  161. use Symfony\Component\Notifier\Bridge\Zulip\ZulipTransportFactory;
  162. use Symfony\Component\Notifier\Notifier;
  163. use Symfony\Component\Notifier\Recipient\Recipient;
  164. use Symfony\Component\Notifier\Transport\TransportFactoryInterface as NotifierTransportFactoryInterface;
  165. use Symfony\Component\PropertyAccess\PropertyAccessor;
  166. use Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor;
  167. use Symfony\Component\PropertyInfo\PropertyAccessExtractorInterface;
  168. use Symfony\Component\PropertyInfo\PropertyDescriptionExtractorInterface;
  169. use Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface;
  170. use Symfony\Component\PropertyInfo\PropertyInitializableExtractorInterface;
  171. use Symfony\Component\PropertyInfo\PropertyListExtractorInterface;
  172. use Symfony\Component\PropertyInfo\PropertyReadInfoExtractorInterface;
  173. use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface;
  174. use Symfony\Component\PropertyInfo\PropertyWriteInfoExtractorInterface;
  175. use Symfony\Component\RateLimiter\LimiterInterface;
  176. use Symfony\Component\RateLimiter\RateLimiterFactory;
  177. use Symfony\Component\RateLimiter\Storage\CacheStorage;
  178. use Symfony\Component\Routing\Loader\AnnotationDirectoryLoader;
  179. use Symfony\Component\Routing\Loader\AnnotationFileLoader;
  180. use Symfony\Component\Security\Core\Exception\AuthenticationException;
  181. use Symfony\Component\Security\Core\Security;
  182. use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
  183. use Symfony\Component\Serializer\Encoder\DecoderInterface;
  184. use Symfony\Component\Serializer\Encoder\EncoderInterface;
  185. use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
  186. use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
  187. use Symfony\Component\Serializer\Normalizer\UnwrappingDenormalizer;
  188. use Symfony\Component\Stopwatch\Stopwatch;
  189. use Symfony\Component\String\LazyString;
  190. use Symfony\Component\String\Slugger\SluggerInterface;
  191. use Symfony\Component\Translation\Bridge\Crowdin\CrowdinProviderFactory;
  192. use Symfony\Component\Translation\Bridge\Loco\LocoProviderFactory;
  193. use Symfony\Component\Translation\Bridge\Lokalise\LokaliseProviderFactory;
  194. use Symfony\Component\Translation\Command\XliffLintCommand as BaseXliffLintCommand;
  195. use Symfony\Component\Translation\PseudoLocalizationTranslator;
  196. use Symfony\Component\Translation\Translator;
  197. use Symfony\Component\Uid\Factory\UuidFactory;
  198. use Symfony\Component\Uid\UuidV4;
  199. use Symfony\Component\Validator\ConstraintValidatorInterface;
  200. use Symfony\Component\Validator\Mapping\Loader\PropertyInfoLoader;
  201. use Symfony\Component\Validator\ObjectInitializerInterface;
  202. use Symfony\Component\Validator\Validation;
  203. use Symfony\Component\WebLink\HttpHeaderSerializer;
  204. use Symfony\Component\Workflow;
  205. use Symfony\Component\Workflow\WorkflowInterface;
  206. use Symfony\Component\Yaml\Command\LintCommand as BaseYamlLintCommand;
  207. use Symfony\Component\Yaml\Yaml;
  208. use Symfony\Contracts\Cache\CacheInterface;
  209. use Symfony\Contracts\Cache\CallbackInterface;
  210. use Symfony\Contracts\Cache\TagAwareCacheInterface;
  211. use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
  212. use Symfony\Contracts\HttpClient\HttpClientInterface;
  213. use Symfony\Contracts\Service\ResetInterface;
  214. use Symfony\Contracts\Service\ServiceSubscriberInterface;
  215. use Symfony\Contracts\Translation\LocaleAwareInterface;
  216. /**
  217.  * Process the configuration and prepare the dependency injection container with
  218.  * parameters and services.
  219.  */
  220. class FrameworkExtension extends Extension
  221. {
  222.     private $formConfigEnabled false;
  223.     private $translationConfigEnabled false;
  224.     private $sessionConfigEnabled false;
  225.     private $annotationsConfigEnabled false;
  226.     private $validatorConfigEnabled false;
  227.     private $messengerConfigEnabled false;
  228.     private $mailerConfigEnabled false;
  229.     private $httpClientConfigEnabled false;
  230.     private $notifierConfigEnabled false;
  231.     private $propertyAccessConfigEnabled false;
  232.     private static $lockConfigEnabled false;
  233.     /**
  234.      * Responds to the app.config configuration parameter.
  235.      *
  236.      * @throws LogicException
  237.      */
  238.     public function load(array $configsContainerBuilder $container)
  239.     {
  240.         if (!class_exists(InstalledVersions::class)) {
  241.             trigger_deprecation('symfony/framework-bundle''5.4''Configuring Symfony without the Composer Runtime API is deprecated. Consider upgrading to Composer 2.1 or later.');
  242.         }
  243.         $loader = new PhpFileLoader($container, new FileLocator(\dirname(__DIR__).'/Resources/config'));
  244.         $loader->load('web.php');
  245.         $loader->load('services.php');
  246.         $loader->load('fragment_renderer.php');
  247.         $loader->load('error_renderer.php');
  248.         if (ContainerBuilder::willBeAvailable('psr/event-dispatcher'PsrEventDispatcherInterface::class, ['symfony/framework-bundle'], true)) {
  249.             $container->setAlias(PsrEventDispatcherInterface::class, 'event_dispatcher');
  250.         }
  251.         $container->registerAliasForArgument('parameter_bag'PsrContainerInterface::class);
  252.         if ($this->hasConsole()) {
  253.             $loader->load('console.php');
  254.             if (!class_exists(BaseXliffLintCommand::class)) {
  255.                 $container->removeDefinition('console.command.xliff_lint');
  256.             }
  257.             if (!class_exists(BaseYamlLintCommand::class)) {
  258.                 $container->removeDefinition('console.command.yaml_lint');
  259.             }
  260.             if (!class_exists(DebugCommand::class)) {
  261.                 $container->removeDefinition('console.command.dotenv_debug');
  262.             }
  263.         }
  264.         // Load Cache configuration first as it is used by other components
  265.         $loader->load('cache.php');
  266.         $configuration $this->getConfiguration($configs$container);
  267.         $config $this->processConfiguration($configuration$configs);
  268.         $this->annotationsConfigEnabled $this->isConfigEnabled($container$config['annotations']);
  269.         $this->translationConfigEnabled $this->isConfigEnabled($container$config['translator']);
  270.         // A translator must always be registered (as support is included by
  271.         // default in the Form and Validator component). If disabled, an identity
  272.         // translator will be used and everything will still work as expected.
  273.         if ($this->isConfigEnabled($container$config['translator']) || $this->isConfigEnabled($container$config['form']) || $this->isConfigEnabled($container$config['validation'])) {
  274.             if (!class_exists(Translator::class) && $this->isConfigEnabled($container$config['translator'])) {
  275.                 throw new LogicException('Translation support cannot be enabled as the Translation component is not installed. Try running "composer require symfony/translation".');
  276.             }
  277.             if (class_exists(Translator::class)) {
  278.                 $loader->load('identity_translator.php');
  279.             }
  280.         }
  281.         $container->getDefinition('locale_listener')->replaceArgument(3$config['set_locale_from_accept_language']);
  282.         $container->getDefinition('response_listener')->replaceArgument(1$config['set_content_language_from_locale']);
  283.         // If the slugger is used but the String component is not available, we should throw an error
  284.         if (!ContainerBuilder::willBeAvailable('symfony/string'SluggerInterface::class, ['symfony/framework-bundle'], true)) {
  285.             $container->register('slugger''stdClass')
  286.                 ->addError('You cannot use the "slugger" service since the String component is not installed. Try running "composer require symfony/string".');
  287.         } else {
  288.             if (!ContainerBuilder::willBeAvailable('symfony/translation'LocaleAwareInterface::class, ['symfony/framework-bundle'], true)) {
  289.                 $container->register('slugger''stdClass')
  290.                     ->addError('You cannot use the "slugger" service since the Translation contracts are not installed. Try running "composer require symfony/translation".');
  291.             }
  292.             if (!\extension_loaded('intl') && !\defined('PHPUNIT_COMPOSER_INSTALL')) {
  293.                 trigger_deprecation('''''Please install the "intl" PHP extension for best performance.');
  294.             }
  295.         }
  296.         if (isset($config['secret'])) {
  297.             $container->setParameter('kernel.secret'$config['secret']);
  298.         }
  299.         $container->setParameter('kernel.http_method_override'$config['http_method_override']);
  300.         $container->setParameter('kernel.trusted_hosts'$config['trusted_hosts']);
  301.         $container->setParameter('kernel.default_locale'$config['default_locale']);
  302.         $container->setParameter('kernel.enabled_locales'$config['enabled_locales']);
  303.         $container->setParameter('kernel.error_controller'$config['error_controller']);
  304.         if (($config['trusted_proxies'] ?? false) && ($config['trusted_headers'] ?? false)) {
  305.             $container->setParameter('kernel.trusted_proxies'$config['trusted_proxies']);
  306.             $container->setParameter('kernel.trusted_headers'$this->resolveTrustedHeaders($config['trusted_headers']));
  307.         }
  308.         if (!$container->hasParameter('debug.file_link_format')) {
  309.             $container->setParameter('debug.file_link_format'$config['ide']);
  310.         }
  311.         if (!empty($config['test'])) {
  312.             $loader->load('test.php');
  313.             if (!class_exists(AbstractBrowser::class)) {
  314.                 $container->removeDefinition('test.client');
  315.             }
  316.         }
  317.         // register cache before session so both can share the connection services
  318.         $this->registerCacheConfiguration($config['cache'], $container);
  319.         if ($this->isConfigEnabled($container$config['session'])) {
  320.             if (!\extension_loaded('session')) {
  321.                 throw new LogicException('Session support cannot be enabled as the session extension is not installed. See https://php.net/session.installation for instructions.');
  322.             }
  323.             $this->sessionConfigEnabled true;
  324.             $this->registerSessionConfiguration($config['session'], $container$loader);
  325.             if (!empty($config['test'])) {
  326.                 // test listener will replace the existing session listener
  327.                 // as we are aliasing to avoid duplicated registered events
  328.                 $container->setAlias('session_listener''test.session.listener');
  329.             }
  330.         } elseif (!empty($config['test'])) {
  331.             $container->removeDefinition('test.session.listener');
  332.         }
  333.         if ($this->isConfigEnabled($container$config['request'])) {
  334.             $this->registerRequestConfiguration($config['request'], $container$loader);
  335.         }
  336.         if (null === $config['csrf_protection']['enabled']) {
  337.             $config['csrf_protection']['enabled'] = $this->sessionConfigEnabled && !class_exists(FullStack::class) && ContainerBuilder::willBeAvailable('symfony/security-csrf'CsrfTokenManagerInterface::class, ['symfony/framework-bundle'], true);
  338.         }
  339.         $this->registerSecurityCsrfConfiguration($config['csrf_protection'], $container$loader);
  340.         if ($this->isConfigEnabled($container$config['form'])) {
  341.             if (!class_exists(Form::class)) {
  342.                 throw new LogicException('Form support cannot be enabled as the Form component is not installed. Try running "composer require symfony/form".');
  343.             }
  344.             $this->formConfigEnabled true;
  345.             $this->registerFormConfiguration($config$container$loader);
  346.             if (ContainerBuilder::willBeAvailable('symfony/validator'Validation::class, ['symfony/framework-bundle''symfony/form'], true)) {
  347.                 $config['validation']['enabled'] = true;
  348.             } else {
  349.                 $container->setParameter('validator.translation_domain''validators');
  350.                 $container->removeDefinition('form.type_extension.form.validator');
  351.                 $container->removeDefinition('form.type_guesser.validator');
  352.             }
  353.         } else {
  354.             $container->removeDefinition('console.command.form_debug');
  355.         }
  356.         if ($this->isConfigEnabled($container$config['assets'])) {
  357.             if (!class_exists(\Symfony\Component\Asset\Package::class)) {
  358.                 throw new LogicException('Asset support cannot be enabled as the Asset component is not installed. Try running "composer require symfony/asset".');
  359.             }
  360.             $this->registerAssetsConfiguration($config['assets'], $container$loader);
  361.         }
  362.         if ($this->messengerConfigEnabled $this->isConfigEnabled($container$config['messenger'])) {
  363.             $this->registerMessengerConfiguration($config['messenger'], $container$loader$config['validation']);
  364.         } else {
  365.             $container->removeDefinition('console.command.messenger_consume_messages');
  366.             $container->removeDefinition('console.command.messenger_debug');
  367.             $container->removeDefinition('console.command.messenger_stop_workers');
  368.             $container->removeDefinition('console.command.messenger_setup_transports');
  369.             $container->removeDefinition('console.command.messenger_failed_messages_retry');
  370.             $container->removeDefinition('console.command.messenger_failed_messages_show');
  371.             $container->removeDefinition('console.command.messenger_failed_messages_remove');
  372.             $container->removeDefinition('cache.messenger.restart_workers_signal');
  373.             if ($container->hasDefinition('messenger.transport.amqp.factory') && !class_exists(AmqpTransportFactory::class)) {
  374.                 if (class_exists(\Symfony\Component\Messenger\Transport\AmqpExt\AmqpTransportFactory::class)) {
  375.                     $container->getDefinition('messenger.transport.amqp.factory')
  376.                         ->setClass(\Symfony\Component\Messenger\Transport\AmqpExt\AmqpTransportFactory::class)
  377.                         ->addTag('messenger.transport_factory');
  378.                 } else {
  379.                     $container->removeDefinition('messenger.transport.amqp.factory');
  380.                 }
  381.             }
  382.             if ($container->hasDefinition('messenger.transport.redis.factory') && !class_exists(RedisTransportFactory::class)) {
  383.                 if (class_exists(\Symfony\Component\Messenger\Transport\RedisExt\RedisTransportFactory::class)) {
  384.                     $container->getDefinition('messenger.transport.redis.factory')
  385.                         ->setClass(\Symfony\Component\Messenger\Transport\RedisExt\RedisTransportFactory::class)
  386.                         ->addTag('messenger.transport_factory');
  387.                 } else {
  388.                     $container->removeDefinition('messenger.transport.redis.factory');
  389.                 }
  390.             }
  391.         }
  392.         if ($this->httpClientConfigEnabled $this->isConfigEnabled($container$config['http_client'])) {
  393.             $this->registerHttpClientConfiguration($config['http_client'], $container$loader$config['profiler']);
  394.         }
  395.         if ($this->mailerConfigEnabled $this->isConfigEnabled($container$config['mailer'])) {
  396.             $this->registerMailerConfiguration($config['mailer'], $container$loader);
  397.         }
  398.         if ($this->notifierConfigEnabled $this->isConfigEnabled($container$config['notifier'])) {
  399.             $this->registerNotifierConfiguration($config['notifier'], $container$loader);
  400.         }
  401.         $propertyInfoEnabled $this->isConfigEnabled($container$config['property_info']);
  402.         $this->registerValidationConfiguration($config['validation'], $container$loader$propertyInfoEnabled);
  403.         $this->registerHttpCacheConfiguration($config['http_cache'], $container$config['http_method_override']);
  404.         $this->registerEsiConfiguration($config['esi'], $container$loader);
  405.         $this->registerSsiConfiguration($config['ssi'], $container$loader);
  406.         $this->registerFragmentsConfiguration($config['fragments'], $container$loader);
  407.         $this->registerTranslatorConfiguration($config['translator'], $container$loader$config['default_locale'], $config['enabled_locales']);
  408.         $this->registerProfilerConfiguration($config['profiler'], $container$loader);
  409.         $this->registerWorkflowConfiguration($config['workflows'], $container$loader);
  410.         $this->registerDebugConfiguration($config['php_errors'], $container$loader);
  411.         // @deprecated since Symfony 5.4, in 6.0 change to:
  412.         // $this->registerRouterConfiguration($config['router'], $container, $loader, $config['enabled_locales']);
  413.         $this->registerRouterConfiguration($config['router'], $container$loader$config['translator']['enabled_locales'] ?: $config['enabled_locales']);
  414.         $this->registerAnnotationsConfiguration($config['annotations'], $container$loader);
  415.         $this->registerPropertyAccessConfiguration($config['property_access'], $container$loader);
  416.         $this->registerSecretsConfiguration($config['secrets'], $container$loader);
  417.         $container->getDefinition('exception_listener')->replaceArgument(3$config['exceptions']);
  418.         if ($this->isConfigEnabled($container$config['serializer'])) {
  419.             if (!class_exists(\Symfony\Component\Serializer\Serializer::class)) {
  420.                 throw new LogicException('Serializer support cannot be enabled as the Serializer component is not installed. Try running "composer require symfony/serializer-pack".');
  421.             }
  422.             $this->registerSerializerConfiguration($config['serializer'], $container$loader);
  423.         }
  424.         if ($propertyInfoEnabled) {
  425.             $this->registerPropertyInfoConfiguration($container$loader);
  426.         }
  427.         if (self::$lockConfigEnabled $this->isConfigEnabled($container$config['lock'])) {
  428.             $this->registerLockConfiguration($config['lock'], $container$loader);
  429.         }
  430.         if ($this->isConfigEnabled($container$config['rate_limiter'])) {
  431.             if (!interface_exists(LimiterInterface::class)) {
  432.                 throw new LogicException('Rate limiter support cannot be enabled as the RateLimiter component is not installed. Try running "composer require symfony/rate-limiter".');
  433.             }
  434.             $this->registerRateLimiterConfiguration($config['rate_limiter'], $container$loader);
  435.         }
  436.         if ($this->isConfigEnabled($container$config['web_link'])) {
  437.             if (!class_exists(HttpHeaderSerializer::class)) {
  438.                 throw new LogicException('WebLink support cannot be enabled as the WebLink component is not installed. Try running "composer require symfony/weblink".');
  439.             }
  440.             $loader->load('web_link.php');
  441.         }
  442.         if ($this->isConfigEnabled($container$config['uid'])) {
  443.             if (!class_exists(UuidFactory::class)) {
  444.                 throw new LogicException('Uid support cannot be enabled as the Uid component is not installed. Try running "composer require symfony/uid".');
  445.             }
  446.             $this->registerUidConfiguration($config['uid'], $container$loader);
  447.         }
  448.         $this->addAnnotatedClassesToCompile([
  449.             '**\\Controller\\',
  450.             '**\\Entity\\',
  451.             // Added explicitly so that we don't rely on the class map being dumped to make it work
  452.             'Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController',
  453.         ]);
  454.         if (ContainerBuilder::willBeAvailable('symfony/mime'MimeTypes::class, ['symfony/framework-bundle'], true)) {
  455.             $loader->load('mime_type.php');
  456.         }
  457.         $container->registerForAutoconfiguration(PackageInterface::class)
  458.             ->addTag('assets.package');
  459.         $container->registerForAutoconfiguration(Command::class)
  460.             ->addTag('console.command');
  461.         $container->registerForAutoconfiguration(ResourceCheckerInterface::class)
  462.             ->addTag('config_cache.resource_checker');
  463.         $container->registerForAutoconfiguration(EnvVarLoaderInterface::class)
  464.             ->addTag('container.env_var_loader');
  465.         $container->registerForAutoconfiguration(EnvVarProcessorInterface::class)
  466.             ->addTag('container.env_var_processor');
  467.         $container->registerForAutoconfiguration(CallbackInterface::class)
  468.             ->addTag('container.reversible');
  469.         $container->registerForAutoconfiguration(ServiceLocator::class)
  470.             ->addTag('container.service_locator');
  471.         $container->registerForAutoconfiguration(ServiceSubscriberInterface::class)
  472.             ->addTag('container.service_subscriber');
  473.         $container->registerForAutoconfiguration(ArgumentValueResolverInterface::class)
  474.             ->addTag('controller.argument_value_resolver');
  475.         $container->registerForAutoconfiguration(AbstractController::class)
  476.             ->addTag('controller.service_arguments');
  477.         $container->registerForAutoconfiguration(DataCollectorInterface::class)
  478.             ->addTag('data_collector');
  479.         $container->registerForAutoconfiguration(FormTypeInterface::class)
  480.             ->addTag('form.type');
  481.         $container->registerForAutoconfiguration(FormTypeGuesserInterface::class)
  482.             ->addTag('form.type_guesser');
  483.         $container->registerForAutoconfiguration(FormTypeExtensionInterface::class)
  484.             ->addTag('form.type_extension');
  485.         $container->registerForAutoconfiguration(CacheClearerInterface::class)
  486.             ->addTag('kernel.cache_clearer');
  487.         $container->registerForAutoconfiguration(CacheWarmerInterface::class)
  488.             ->addTag('kernel.cache_warmer');
  489.         $container->registerForAutoconfiguration(EventDispatcherInterface::class)
  490.             ->addTag('event_dispatcher.dispatcher');
  491.         $container->registerForAutoconfiguration(EventSubscriberInterface::class)
  492.             ->addTag('kernel.event_subscriber');
  493.         $container->registerForAutoconfiguration(LocaleAwareInterface::class)
  494.             ->addTag('kernel.locale_aware');
  495.         $container->registerForAutoconfiguration(ResetInterface::class)
  496.             ->addTag('kernel.reset', ['method' => 'reset']);
  497.         if (!interface_exists(MarshallerInterface::class)) {
  498.             $container->registerForAutoconfiguration(ResettableInterface::class)
  499.                 ->addTag('kernel.reset', ['method' => 'reset']);
  500.         }
  501.         $container->registerForAutoconfiguration(PropertyListExtractorInterface::class)
  502.             ->addTag('property_info.list_extractor');
  503.         $container->registerForAutoconfiguration(PropertyTypeExtractorInterface::class)
  504.             ->addTag('property_info.type_extractor');
  505.         $container->registerForAutoconfiguration(PropertyDescriptionExtractorInterface::class)
  506.             ->addTag('property_info.description_extractor');
  507.         $container->registerForAutoconfiguration(PropertyAccessExtractorInterface::class)
  508.             ->addTag('property_info.access_extractor');
  509.         $container->registerForAutoconfiguration(PropertyInitializableExtractorInterface::class)
  510.             ->addTag('property_info.initializable_extractor');
  511.         $container->registerForAutoconfiguration(EncoderInterface::class)
  512.             ->addTag('serializer.encoder');
  513.         $container->registerForAutoconfiguration(DecoderInterface::class)
  514.             ->addTag('serializer.encoder');
  515.         $container->registerForAutoconfiguration(NormalizerInterface::class)
  516.             ->addTag('serializer.normalizer');
  517.         $container->registerForAutoconfiguration(DenormalizerInterface::class)
  518.             ->addTag('serializer.normalizer');
  519.         $container->registerForAutoconfiguration(ConstraintValidatorInterface::class)
  520.             ->addTag('validator.constraint_validator');
  521.         $container->registerForAutoconfiguration(ObjectInitializerInterface::class)
  522.             ->addTag('validator.initializer');
  523.         $container->registerForAutoconfiguration(MessageHandlerInterface::class)
  524.             ->addTag('messenger.message_handler');
  525.         $container->registerForAutoconfiguration(BatchHandlerInterface::class)
  526.             ->addTag('messenger.message_handler');
  527.         $container->registerForAutoconfiguration(TransportFactoryInterface::class)
  528.             ->addTag('messenger.transport_factory');
  529.         $container->registerForAutoconfiguration(MimeTypeGuesserInterface::class)
  530.             ->addTag('mime.mime_type_guesser');
  531.         $container->registerForAutoconfiguration(LoggerAwareInterface::class)
  532.             ->addMethodCall('setLogger', [new Reference('logger')]);
  533.         $container->registerAttributeForAutoconfiguration(AsEventListener::class, static function (ChildDefinition $definitionAsEventListener $attribute\Reflector $reflector) {
  534.             $tagAttributes get_object_vars($attribute);
  535.             if ($reflector instanceof \ReflectionMethod) {
  536.                 if (isset($tagAttributes['method'])) {
  537.                     throw new LogicException(sprintf('AsEventListener attribute cannot declare a method on "%s::%s()".'$reflector->class$reflector->name));
  538.                 }
  539.                 $tagAttributes['method'] = $reflector->getName();
  540.             }
  541.             $definition->addTag('kernel.event_listener'$tagAttributes);
  542.         });
  543.         $container->registerAttributeForAutoconfiguration(AsController::class, static function (ChildDefinition $definitionAsController $attribute): void {
  544.             $definition->addTag('controller.service_arguments');
  545.         });
  546.         $container->registerAttributeForAutoconfiguration(AsMessageHandler::class, static function (ChildDefinition $definitionAsMessageHandler $attribute): void {
  547.             $tagAttributes get_object_vars($attribute);
  548.             $tagAttributes['from_transport'] = $tagAttributes['fromTransport'];
  549.             unset($tagAttributes['fromTransport']);
  550.             $definition->addTag('messenger.message_handler'$tagAttributes);
  551.         });
  552.         if (!$container->getParameter('kernel.debug')) {
  553.             // remove tagged iterator argument for resource checkers
  554.             $container->getDefinition('config_cache_factory')->setArguments([]);
  555.         }
  556.         if (!$config['disallow_search_engine_index'] ?? false) {
  557.             $container->removeDefinition('disallow_search_engine_index_response_listener');
  558.         }
  559.         $container->registerForAutoconfiguration(RouteLoaderInterface::class)
  560.             ->addTag('routing.route_loader');
  561.         $container->setParameter('container.behavior_describing_tags', [
  562.             'container.service_locator',
  563.             'container.service_subscriber',
  564.             'kernel.event_subscriber',
  565.             'kernel.locale_aware',
  566.             'kernel.reset',
  567.         ]);
  568.     }
  569.     /**
  570.      * {@inheritdoc}
  571.      */
  572.     public function getConfiguration(array $configContainerBuilder $container)
  573.     {
  574.         return new Configuration($container->getParameter('kernel.debug'));
  575.     }
  576.     protected function hasConsole(): bool
  577.     {
  578.         return class_exists(Application::class);
  579.     }
  580.     private function registerFormConfiguration(array $configContainerBuilder $containerPhpFileLoader $loader)
  581.     {
  582.         $loader->load('form.php');
  583.         $container->getDefinition('form.type_extension.form.validator')->setArgument(1$config['form']['legacy_error_messages']);
  584.         if (null === $config['form']['csrf_protection']['enabled']) {
  585.             $config['form']['csrf_protection']['enabled'] = $config['csrf_protection']['enabled'];
  586.         }
  587.         if ($this->isConfigEnabled($container$config['form']['csrf_protection'])) {
  588.             $loader->load('form_csrf.php');
  589.             $container->setParameter('form.type_extension.csrf.enabled'true);
  590.             $container->setParameter('form.type_extension.csrf.field_name'$config['form']['csrf_protection']['field_name']);
  591.         } else {
  592.             $container->setParameter('form.type_extension.csrf.enabled'false);
  593.         }
  594.         if (!ContainerBuilder::willBeAvailable('symfony/translation'Translator::class, ['symfony/framework-bundle''symfony/form'], true)) {
  595.             $container->removeDefinition('form.type_extension.upload.validator');
  596.         }
  597.         if (!method_exists(CachingFactoryDecorator::class, 'reset')) {
  598.             $container->getDefinition('form.choice_list_factory.cached')
  599.                 ->clearTag('kernel.reset')
  600.             ;
  601.         }
  602.     }
  603.     private function registerHttpCacheConfiguration(array $configContainerBuilder $containerbool $httpMethodOverride)
  604.     {
  605.         $options $config;
  606.         unset($options['enabled']);
  607.         if (!$options['private_headers']) {
  608.             unset($options['private_headers']);
  609.         }
  610.         $container->getDefinition('http_cache')
  611.             ->setPublic($config['enabled'])
  612.             ->replaceArgument(3$options);
  613.         if ($httpMethodOverride) {
  614.             $container->getDefinition('http_cache')
  615.                   ->addArgument((new Definition('void'))
  616.                       ->setFactory([Request::class, 'enableHttpMethodParameterOverride'])
  617.                   );
  618.         }
  619.     }
  620.     private function registerEsiConfiguration(array $configContainerBuilder $containerPhpFileLoader $loader)
  621.     {
  622.         if (!$this->isConfigEnabled($container$config)) {
  623.             $container->removeDefinition('fragment.renderer.esi');
  624.             return;
  625.         }
  626.         $loader->load('esi.php');
  627.     }
  628.     private function registerSsiConfiguration(array $configContainerBuilder $containerPhpFileLoader $loader)
  629.     {
  630.         if (!$this->isConfigEnabled($container$config)) {
  631.             $container->removeDefinition('fragment.renderer.ssi');
  632.             return;
  633.         }
  634.         $loader->load('ssi.php');
  635.     }
  636.     private function registerFragmentsConfiguration(array $configContainerBuilder $containerPhpFileLoader $loader)
  637.     {
  638.         if (!$this->isConfigEnabled($container$config)) {
  639.             $container->removeDefinition('fragment.renderer.hinclude');
  640.             return;
  641.         }
  642.         $container->setParameter('fragment.renderer.hinclude.global_template'$config['hinclude_default_template']);
  643.         $loader->load('fragment_listener.php');
  644.         $container->setParameter('fragment.path'$config['path']);
  645.     }
  646.     private function registerProfilerConfiguration(array $configContainerBuilder $containerPhpFileLoader $loader)
  647.     {
  648.         if (!$this->isConfigEnabled($container$config)) {
  649.             // this is needed for the WebProfiler to work even if the profiler is disabled
  650.             $container->setParameter('data_collector.templates', []);
  651.             return;
  652.         }
  653.         $loader->load('profiling.php');
  654.         $loader->load('collectors.php');
  655.         $loader->load('cache_debug.php');
  656.         if ($this->formConfigEnabled) {
  657.             $loader->load('form_debug.php');
  658.         }
  659.         if ($this->validatorConfigEnabled) {
  660.             $loader->load('validator_debug.php');
  661.         }
  662.         if ($this->translationConfigEnabled) {
  663.             $loader->load('translation_debug.php');
  664.             $container->getDefinition('translator.data_collector')->setDecoratedService('translator');
  665.         }
  666.         if ($this->messengerConfigEnabled) {
  667.             $loader->load('messenger_debug.php');
  668.         }
  669.         if ($this->mailerConfigEnabled) {
  670.             $loader->load('mailer_debug.php');
  671.         }
  672.         if ($this->httpClientConfigEnabled) {
  673.             $loader->load('http_client_debug.php');
  674.         }
  675.         if ($this->notifierConfigEnabled) {
  676.             $loader->load('notifier_debug.php');
  677.         }
  678.         $container->setParameter('profiler_listener.only_exceptions'$config['only_exceptions']);
  679.         $container->setParameter('profiler_listener.only_main_requests'$config['only_main_requests'] || $config['only_master_requests']);
  680.         // Choose storage class based on the DSN
  681.         [$class] = explode(':'$config['dsn'], 2);
  682.         if ('file' !== $class) {
  683.             throw new \LogicException(sprintf('Driver "%s" is not supported for the profiler.'$class));
  684.         }
  685.         $container->setParameter('profiler.storage.dsn'$config['dsn']);
  686.         $container->getDefinition('profiler')
  687.             ->addArgument($config['collect'])
  688.             ->addTag('kernel.reset', ['method' => 'reset']);
  689.         $container->getDefinition('profiler_listener')
  690.             ->addArgument($config['collect_parameter']);
  691.     }
  692.     private function registerWorkflowConfiguration(array $configContainerBuilder $containerPhpFileLoader $loader)
  693.     {
  694.         if (!$config['enabled']) {
  695.             $container->removeDefinition('console.command.workflow_dump');
  696.             return;
  697.         }
  698.         if (!class_exists(Workflow\Workflow::class)) {
  699.             throw new LogicException('Workflow support cannot be enabled as the Workflow component is not installed. Try running "composer require symfony/workflow".');
  700.         }
  701.         $loader->load('workflow.php');
  702.         $registryDefinition $container->getDefinition('workflow.registry');
  703.         $workflows = [];
  704.         foreach ($config['workflows'] as $name => $workflow) {
  705.             $type $workflow['type'];
  706.             $workflowId sprintf('%s.%s'$type$name);
  707.             // Process Metadata (workflow + places (transition is done in the "create transition" block))
  708.             $metadataStoreDefinition = new Definition(Workflow\Metadata\InMemoryMetadataStore::class, [[], [], null]);
  709.             if ($workflow['metadata']) {
  710.                 $metadataStoreDefinition->replaceArgument(0$workflow['metadata']);
  711.             }
  712.             $placesMetadata = [];
  713.             foreach ($workflow['places'] as $place) {
  714.                 if ($place['metadata']) {
  715.                     $placesMetadata[$place['name']] = $place['metadata'];
  716.                 }
  717.             }
  718.             if ($placesMetadata) {
  719.                 $metadataStoreDefinition->replaceArgument(1$placesMetadata);
  720.             }
  721.             // Create transitions
  722.             $transitions = [];
  723.             $guardsConfiguration = [];
  724.             $transitionsMetadataDefinition = new Definition(\SplObjectStorage::class);
  725.             // Global transition counter per workflow
  726.             $transitionCounter 0;
  727.             foreach ($workflow['transitions'] as $transition) {
  728.                 if ('workflow' === $type) {
  729.                     $transitionDefinition = new Definition(Workflow\Transition::class, [$transition['name'], $transition['from'], $transition['to']]);
  730.                     $transitionDefinition->setPublic(false);
  731.                     $transitionId sprintf('.%s.transition.%s'$workflowId$transitionCounter++);
  732.                     $container->setDefinition($transitionId$transitionDefinition);
  733.                     $transitions[] = new Reference($transitionId);
  734.                     if (isset($transition['guard'])) {
  735.                         $configuration = new Definition(Workflow\EventListener\GuardExpression::class);
  736.                         $configuration->addArgument(new Reference($transitionId));
  737.                         $configuration->addArgument($transition['guard']);
  738.                         $configuration->setPublic(false);
  739.                         $eventName sprintf('workflow.%s.guard.%s'$name$transition['name']);
  740.                         $guardsConfiguration[$eventName][] = $configuration;
  741.                     }
  742.                     if ($transition['metadata']) {
  743.                         $transitionsMetadataDefinition->addMethodCall('attach', [
  744.                             new Reference($transitionId),
  745.                             $transition['metadata'],
  746.                         ]);
  747.                     }
  748.                 } elseif ('state_machine' === $type) {
  749.                     foreach ($transition['from'] as $from) {
  750.                         foreach ($transition['to'] as $to) {
  751.                             $transitionDefinition = new Definition(Workflow\Transition::class, [$transition['name'], $from$to]);
  752.                             $transitionDefinition->setPublic(false);
  753.                             $transitionId sprintf('.%s.transition.%s'$workflowId$transitionCounter++);
  754.                             $container->setDefinition($transitionId$transitionDefinition);
  755.                             $transitions[] = new Reference($transitionId);
  756.                             if (isset($transition['guard'])) {
  757.                                 $configuration = new Definition(Workflow\EventListener\GuardExpression::class);
  758.                                 $configuration->addArgument(new Reference($transitionId));
  759.                                 $configuration->addArgument($transition['guard']);
  760.                                 $configuration->setPublic(false);
  761.                                 $eventName sprintf('workflow.%s.guard.%s'$name$transition['name']);
  762.                                 $guardsConfiguration[$eventName][] = $configuration;
  763.                             }
  764.                             if ($transition['metadata']) {
  765.                                 $transitionsMetadataDefinition->addMethodCall('attach', [
  766.                                     new Reference($transitionId),
  767.                                     $transition['metadata'],
  768.                                 ]);
  769.                             }
  770.                         }
  771.                     }
  772.                 }
  773.             }
  774.             $metadataStoreDefinition->replaceArgument(2$transitionsMetadataDefinition);
  775.             $container->setDefinition(sprintf('%s.metadata_store'$workflowId), $metadataStoreDefinition);
  776.             // Create places
  777.             $places array_column($workflow['places'], 'name');
  778.             $initialMarking $workflow['initial_marking'] ?? [];
  779.             // Create a Definition
  780.             $definitionDefinition = new Definition(Workflow\Definition::class);
  781.             $definitionDefinition->setPublic(false);
  782.             $definitionDefinition->addArgument($places);
  783.             $definitionDefinition->addArgument($transitions);
  784.             $definitionDefinition->addArgument($initialMarking);
  785.             $definitionDefinition->addArgument(new Reference(sprintf('%s.metadata_store'$workflowId)));
  786.             $workflows[$workflowId] = $definitionDefinition;
  787.             // Create MarkingStore
  788.             if (isset($workflow['marking_store']['type'])) {
  789.                 $markingStoreDefinition = new ChildDefinition('workflow.marking_store.method');
  790.                 $markingStoreDefinition->setArguments([
  791.                     'state_machine' === $type//single state
  792.                     $workflow['marking_store']['property'],
  793.                 ]);
  794.             } elseif (isset($workflow['marking_store']['service'])) {
  795.                 $markingStoreDefinition = new Reference($workflow['marking_store']['service']);
  796.             }
  797.             // Create Workflow
  798.             $workflowDefinition = new ChildDefinition(sprintf('%s.abstract'$type));
  799.             $workflowDefinition->replaceArgument(0, new Reference(sprintf('%s.definition'$workflowId)));
  800.             $workflowDefinition->replaceArgument(1$markingStoreDefinition ?? null);
  801.             $workflowDefinition->replaceArgument(3$name);
  802.             $workflowDefinition->replaceArgument(4$workflow['events_to_dispatch']);
  803.             $workflowDefinition->addTag('container.private', [
  804.                 'package' => 'symfony/framework-bundle',
  805.                 'version' => '5.3',
  806.             ]);
  807.             // Store to container
  808.             $container->setDefinition($workflowId$workflowDefinition);
  809.             $container->setDefinition(sprintf('%s.definition'$workflowId), $definitionDefinition);
  810.             $container->registerAliasForArgument($workflowIdWorkflowInterface::class, $name.'.'.$type);
  811.             // Validate Workflow
  812.             if ('state_machine' === $workflow['type']) {
  813.                 $validator = new Workflow\Validator\StateMachineValidator();
  814.             } else {
  815.                 $validator = new Workflow\Validator\WorkflowValidator();
  816.             }
  817.             $trs array_map(function (Reference $ref) use ($container): Workflow\Transition {
  818.                 return $container->get((string) $ref);
  819.             }, $transitions);
  820.             $realDefinition = new Workflow\Definition($places$trs$initialMarking);
  821.             $validator->validate($realDefinition$name);
  822.             // Add workflow to Registry
  823.             if ($workflow['supports']) {
  824.                 foreach ($workflow['supports'] as $supportedClassName) {
  825.                     $strategyDefinition = new Definition(Workflow\SupportStrategy\InstanceOfSupportStrategy::class, [$supportedClassName]);
  826.                     $strategyDefinition->setPublic(false);
  827.                     $registryDefinition->addMethodCall('addWorkflow', [new Reference($workflowId), $strategyDefinition]);
  828.                 }
  829.             } elseif (isset($workflow['support_strategy'])) {
  830.                 $registryDefinition->addMethodCall('addWorkflow', [new Reference($workflowId), new Reference($workflow['support_strategy'])]);
  831.             }
  832.             // Enable the AuditTrail
  833.             if ($workflow['audit_trail']['enabled']) {
  834.                 $listener = new Definition(Workflow\EventListener\AuditTrailListener::class);
  835.                 $listener->addTag('monolog.logger', ['channel' => 'workflow']);
  836.                 $listener->addTag('kernel.event_listener', ['event' => sprintf('workflow.%s.leave'$name), 'method' => 'onLeave']);
  837.                 $listener->addTag('kernel.event_listener', ['event' => sprintf('workflow.%s.transition'$name), 'method' => 'onTransition']);
  838.                 $listener->addTag('kernel.event_listener', ['event' => sprintf('workflow.%s.enter'$name), 'method' => 'onEnter']);
  839.                 $listener->addArgument(new Reference('logger'));
  840.                 $container->setDefinition(sprintf('.%s.listener.audit_trail'$workflowId), $listener);
  841.             }
  842.             // Add Guard Listener
  843.             if ($guardsConfiguration) {
  844.                 if (!class_exists(ExpressionLanguage::class)) {
  845.                     throw new LogicException('Cannot guard workflows as the ExpressionLanguage component is not installed. Try running "composer require symfony/expression-language".');
  846.                 }
  847.                 if (!class_exists(Security::class)) {
  848.                     throw new LogicException('Cannot guard workflows as the Security component is not installed. Try running "composer require symfony/security-core".');
  849.                 }
  850.                 $guard = new Definition(Workflow\EventListener\GuardListener::class);
  851.                 $guard->setArguments([
  852.                     $guardsConfiguration,
  853.                     new Reference('workflow.security.expression_language'),
  854.                     new Reference('security.token_storage'),
  855.                     new Reference('security.authorization_checker'),
  856.                     new Reference('security.authentication.trust_resolver'),
  857.                     new Reference('security.role_hierarchy'),
  858.                     new Reference('validator'ContainerInterface::NULL_ON_INVALID_REFERENCE),
  859.                 ]);
  860.                 foreach ($guardsConfiguration as $eventName => $config) {
  861.                     $guard->addTag('kernel.event_listener', ['event' => $eventName'method' => 'onTransition']);
  862.                 }
  863.                 $container->setDefinition(sprintf('.%s.listener.guard'$workflowId), $guard);
  864.                 $container->setParameter('workflow.has_guard_listeners'true);
  865.             }
  866.         }
  867.         $commandDumpDefinition $container->getDefinition('console.command.workflow_dump');
  868.         $commandDumpDefinition->setArgument(0$workflows);
  869.     }
  870.     private function registerDebugConfiguration(array $configContainerBuilder $containerPhpFileLoader $loader)
  871.     {
  872.         $loader->load('debug_prod.php');
  873.         if (class_exists(Stopwatch::class)) {
  874.             $container->register('debug.stopwatch'Stopwatch::class)
  875.                 ->addArgument(true)
  876.                 ->addTag('kernel.reset', ['method' => 'reset']);
  877.             $container->setAlias(Stopwatch::class, new Alias('debug.stopwatch'false));
  878.         }
  879.         $debug $container->getParameter('kernel.debug');
  880.         if ($debug) {
  881.             $container->setParameter('debug.container.dump''%kernel.build_dir%/%kernel.container_class%.xml');
  882.         }
  883.         if ($debug && class_exists(Stopwatch::class)) {
  884.             $loader->load('debug.php');
  885.         }
  886.         $definition $container->findDefinition('debug.debug_handlers_listener');
  887.         if (false === $config['log']) {
  888.             $definition->replaceArgument(1null);
  889.         } elseif (true !== $config['log']) {
  890.             $definition->replaceArgument(2$config['log']);
  891.         }
  892.         if (!$config['throw']) {
  893.             $container->setParameter('debug.error_handler.throw_at'0);
  894.         }
  895.         if ($debug && class_exists(DebugProcessor::class)) {
  896.             $definition = new Definition(DebugProcessor::class);
  897.             $definition->setPublic(false);
  898.             $definition->addArgument(new Reference('request_stack'));
  899.             $container->setDefinition('debug.log_processor'$definition);
  900.         }
  901.     }
  902.     private function registerRouterConfiguration(array $configContainerBuilder $containerPhpFileLoader $loader, array $enabledLocales = [])
  903.     {
  904.         if (!$this->isConfigEnabled($container$config)) {
  905.             $container->removeDefinition('console.command.router_debug');
  906.             $container->removeDefinition('console.command.router_match');
  907.             $container->removeDefinition('messenger.middleware.router_context');
  908.             return;
  909.         }
  910.         if (!class_exists(RouterContextMiddleware::class)) {
  911.             $container->removeDefinition('messenger.middleware.router_context');
  912.         }
  913.         $loader->load('routing.php');
  914.         if (null === $config['utf8']) {
  915.             trigger_deprecation('symfony/framework-bundle''5.1''Not setting the "framework.router.utf8" configuration option is deprecated, it will default to "true" in version 6.0.');
  916.         }
  917.         if ($config['utf8']) {
  918.             $container->getDefinition('routing.loader')->replaceArgument(1, ['utf8' => true]);
  919.         }
  920.         if ($enabledLocales) {
  921.             $enabledLocales implode('|'array_map('preg_quote'$enabledLocales));
  922.             $container->getDefinition('routing.loader')->replaceArgument(2, ['_locale' => $enabledLocales]);
  923.         }
  924.         if (!ContainerBuilder::willBeAvailable('symfony/expression-language'ExpressionLanguage::class, ['symfony/framework-bundle''symfony/routing'], true)) {
  925.             $container->removeDefinition('router.expression_language_provider');
  926.         }
  927.         $container->setParameter('router.resource'$config['resource']);
  928.         $router $container->findDefinition('router.default');
  929.         $argument $router->getArgument(2);
  930.         $argument['strict_requirements'] = $config['strict_requirements'];
  931.         if (isset($config['type'])) {
  932.             $argument['resource_type'] = $config['type'];
  933.         }
  934.         $router->replaceArgument(2$argument);
  935.         $container->setParameter('request_listener.http_port'$config['http_port']);
  936.         $container->setParameter('request_listener.https_port'$config['https_port']);
  937.         if (null !== $config['default_uri']) {
  938.             $container->getDefinition('router.request_context')
  939.                 ->replaceArgument(0$config['default_uri']);
  940.         }
  941.         if (\PHP_VERSION_ID 80000 && !$this->annotationsConfigEnabled) {
  942.             return;
  943.         }
  944.         $container->register('routing.loader.annotation'AnnotatedRouteControllerLoader::class)
  945.             ->setPublic(false)
  946.             ->addTag('routing.loader', ['priority' => -10])
  947.             ->setArguments([
  948.                 new Reference('annotation_reader'ContainerInterface::NULL_ON_INVALID_REFERENCE),
  949.                 '%kernel.environment%',
  950.             ]);
  951.         $container->register('routing.loader.annotation.directory'AnnotationDirectoryLoader::class)
  952.             ->setPublic(false)
  953.             ->addTag('routing.loader', ['priority' => -10])
  954.             ->setArguments([
  955.                 new Reference('file_locator'),
  956.                 new Reference('routing.loader.annotation'),
  957.             ]);
  958.         $container->register('routing.loader.annotation.file'AnnotationFileLoader::class)
  959.             ->setPublic(false)
  960.             ->addTag('routing.loader', ['priority' => -10])
  961.             ->setArguments([
  962.                 new Reference('file_locator'),
  963.                 new Reference('routing.loader.annotation'),
  964.             ]);
  965.     }
  966.     private function registerSessionConfiguration(array $configContainerBuilder $containerPhpFileLoader $loader)
  967.     {
  968.         $loader->load('session.php');
  969.         // session storage
  970.         if (null === $config['storage_factory_id']) {
  971.             trigger_deprecation('symfony/framework-bundle''5.3''Not setting the "framework.session.storage_factory_id" configuration option is deprecated, it will default to "session.storage.factory.native" and will replace the "framework.session.storage_id" configuration option in version 6.0.');
  972.             $container->setAlias('session.storage'$config['storage_id']);
  973.             $container->setAlias('session.storage.factory''session.storage.factory.service');
  974.         } else {
  975.             $container->setAlias('session.storage.factory'$config['storage_factory_id']);
  976.             $container->removeAlias(SessionStorageInterface::class);
  977.             $container->removeDefinition('session.storage.metadata_bag');
  978.             $container->removeDefinition('session.storage.native');
  979.             $container->removeDefinition('session.storage.php_bridge');
  980.             $container->removeDefinition('session.storage.mock_file');
  981.             $container->removeAlias('session.storage.filesystem');
  982.         }
  983.         $options = ['cache_limiter' => '0'];
  984.         foreach (['name''cookie_lifetime''cookie_path''cookie_domain''cookie_secure''cookie_httponly''cookie_samesite''use_cookies''gc_maxlifetime''gc_probability''gc_divisor''sid_length''sid_bits_per_character'] as $key) {
  985.             if (isset($config[$key])) {
  986.                 $options[$key] = $config[$key];
  987.             }
  988.         }
  989.         if ('auto' === ($options['cookie_secure'] ?? null)) {
  990.             if (null === $config['storage_factory_id']) {
  991.                 $locator $container->getDefinition('session_listener')->getArgument(0);
  992.                 $locator->setValues($locator->getValues() + [
  993.                     'session_storage' => new Reference('session.storage'ContainerInterface::IGNORE_ON_INVALID_REFERENCE),
  994.                     'request_stack' => new Reference('request_stack'),
  995.                 ]);
  996.             } else {
  997.                 $container->getDefinition('session.storage.factory.native')->replaceArgument(3true);
  998.                 $container->getDefinition('session.storage.factory.php_bridge')->replaceArgument(2true);
  999.             }
  1000.         }
  1001.         $container->setParameter('session.storage.options'$options);
  1002.         // session handler (the internal callback registered with PHP session management)
  1003.         if (null === $config['handler_id']) {
  1004.             // Set the handler class to be null
  1005.             if ($container->hasDefinition('session.storage.native')) {
  1006.                 $container->getDefinition('session.storage.native')->replaceArgument(1null);
  1007.                 $container->getDefinition('session.storage.php_bridge')->replaceArgument(0null);
  1008.             } else {
  1009.                 $container->getDefinition('session.storage.factory.native')->replaceArgument(1null);
  1010.                 $container->getDefinition('session.storage.factory.php_bridge')->replaceArgument(0null);
  1011.             }
  1012.             $container->setAlias('session.handler''session.handler.native_file');
  1013.         } else {
  1014.             $container->resolveEnvPlaceholders($config['handler_id'], null$usedEnvs);
  1015.             if ($usedEnvs || preg_match('#^[a-z]++://#'$config['handler_id'])) {
  1016.                 $id '.cache_connection.'.ContainerBuilder::hash($config['handler_id']);
  1017.                 $container->getDefinition('session.abstract_handler')
  1018.                     ->replaceArgument(0$container->hasDefinition($id) ? new Reference($id) : $config['handler_id']);
  1019.                 $container->setAlias('session.handler''session.abstract_handler');
  1020.             } else {
  1021.                 $container->setAlias('session.handler'$config['handler_id']);
  1022.             }
  1023.         }
  1024.         $container->setParameter('session.save_path'$config['save_path']);
  1025.         $container->setParameter('session.metadata.update_threshold'$config['metadata_update_threshold']);
  1026.     }
  1027.     private function registerRequestConfiguration(array $configContainerBuilder $containerPhpFileLoader $loader)
  1028.     {
  1029.         if ($config['formats']) {
  1030.             $loader->load('request.php');
  1031.             $listener $container->getDefinition('request.add_request_formats_listener');
  1032.             $listener->replaceArgument(0$config['formats']);
  1033.         }
  1034.     }
  1035.     private function registerAssetsConfiguration(array $configContainerBuilder $containerPhpFileLoader $loader)
  1036.     {
  1037.         $loader->load('assets.php');
  1038.         if ($config['version_strategy']) {
  1039.             $defaultVersion = new Reference($config['version_strategy']);
  1040.         } else {
  1041.             $defaultVersion $this->createVersion($container$config['version'], $config['version_format'], $config['json_manifest_path'], '_default'$config['strict_mode']);
  1042.         }
  1043.         $defaultPackage $this->createPackageDefinition($config['base_path'], $config['base_urls'], $defaultVersion);
  1044.         $container->setDefinition('assets._default_package'$defaultPackage);
  1045.         foreach ($config['packages'] as $name => $package) {
  1046.             if (null !== $package['version_strategy']) {
  1047.                 $version = new Reference($package['version_strategy']);
  1048.             } elseif (!\array_key_exists('version'$package) && null === $package['json_manifest_path']) {
  1049.                 // if neither version nor json_manifest_path are specified, use the default
  1050.                 $version $defaultVersion;
  1051.             } else {
  1052.                 // let format fallback to main version_format
  1053.                 $format $package['version_format'] ?: $config['version_format'];
  1054.                 $version $package['version'] ?? null;
  1055.                 $version $this->createVersion($container$version$format$package['json_manifest_path'], $name$package['strict_mode']);
  1056.             }
  1057.             $packageDefinition $this->createPackageDefinition($package['base_path'], $package['base_urls'], $version)
  1058.                 ->addTag('assets.package', ['package' => $name]);
  1059.             $container->setDefinition('assets._package_'.$name$packageDefinition);
  1060.             $container->registerAliasForArgument('assets._package_'.$namePackageInterface::class, $name.'.package');
  1061.         }
  1062.     }
  1063.     /**
  1064.      * Returns a definition for an asset package.
  1065.      */
  1066.     private function createPackageDefinition(?string $basePath, array $baseUrlsReference $version): Definition
  1067.     {
  1068.         if ($basePath && $baseUrls) {
  1069.             throw new \LogicException('An asset package cannot have base URLs and base paths.');
  1070.         }
  1071.         $package = new ChildDefinition($baseUrls 'assets.url_package' 'assets.path_package');
  1072.         $package
  1073.             ->setPublic(false)
  1074.             ->replaceArgument(0$baseUrls ?: $basePath)
  1075.             ->replaceArgument(1$version)
  1076.         ;
  1077.         return $package;
  1078.     }
  1079.     private function createVersion(ContainerBuilder $container, ?string $version, ?string $format, ?string $jsonManifestPathstring $namebool $strictMode): Reference
  1080.     {
  1081.         // Configuration prevents $version and $jsonManifestPath from being set
  1082.         if (null !== $version) {
  1083.             $def = new ChildDefinition('assets.static_version_strategy');
  1084.             $def
  1085.                 ->replaceArgument(0$version)
  1086.                 ->replaceArgument(1$format)
  1087.             ;
  1088.             $container->setDefinition('assets._version_'.$name$def);
  1089.             return new Reference('assets._version_'.$name);
  1090.         }
  1091.         if (null !== $jsonManifestPath) {
  1092.             $def = new ChildDefinition('assets.json_manifest_version_strategy');
  1093.             $def->replaceArgument(0$jsonManifestPath);
  1094.             $def->replaceArgument(2$strictMode);
  1095.             $container->setDefinition('assets._version_'.$name$def);
  1096.             return new Reference('assets._version_'.$name);
  1097.         }
  1098.         return new Reference('assets.empty_version_strategy');
  1099.     }
  1100.     private function registerTranslatorConfiguration(array $configContainerBuilder $containerLoaderInterface $loaderstring $defaultLocale, array $enabledLocales)
  1101.     {
  1102.         if (!$this->isConfigEnabled($container$config)) {
  1103.             $container->removeDefinition('console.command.translation_debug');
  1104.             $container->removeDefinition('console.command.translation_extract');
  1105.             $container->removeDefinition('console.command.translation_pull');
  1106.             $container->removeDefinition('console.command.translation_push');
  1107.             return;
  1108.         }
  1109.         $loader->load('translation.php');
  1110.         $loader->load('translation_providers.php');
  1111.         // Use the "real" translator instead of the identity default
  1112.         $container->setAlias('translator''translator.default')->setPublic(true);
  1113.         $container->setAlias('translator.formatter', new Alias($config['formatter'], false));
  1114.         $translator $container->findDefinition('translator.default');
  1115.         $translator->addMethodCall('setFallbackLocales', [$config['fallbacks'] ?: [$defaultLocale]]);
  1116.         $defaultOptions $translator->getArgument(4);
  1117.         $defaultOptions['cache_dir'] = $config['cache_dir'];
  1118.         $translator->setArgument(4$defaultOptions);
  1119.         // @deprecated since Symfony 5.4, in 6.0 change to:
  1120.         // $translator->setArgument(5, $enabledLocales);
  1121.         $translator->setArgument(5$config['enabled_locales'] ?: $enabledLocales);
  1122.         $container->setParameter('translator.logging'$config['logging']);
  1123.         $container->setParameter('translator.default_path'$config['default_path']);
  1124.         // Discover translation directories
  1125.         $dirs = [];
  1126.         $transPaths = [];
  1127.         $nonExistingDirs = [];
  1128.         if (ContainerBuilder::willBeAvailable('symfony/validator'Validation::class, ['symfony/framework-bundle''symfony/translation'], true)) {
  1129.             $r = new \ReflectionClass(Validation::class);
  1130.             $dirs[] = $transPaths[] = \dirname($r->getFileName()).'/Resources/translations';
  1131.         }
  1132.         if (ContainerBuilder::willBeAvailable('symfony/form'Form::class, ['symfony/framework-bundle''symfony/translation'], true)) {
  1133.             $r = new \ReflectionClass(Form::class);
  1134.             $dirs[] = $transPaths[] = \dirname($r->getFileName()).'/Resources/translations';
  1135.         }
  1136.         if (ContainerBuilder::willBeAvailable('symfony/security-core'AuthenticationException::class, ['symfony/framework-bundle''symfony/translation'], true)) {
  1137.             $r = new \ReflectionClass(AuthenticationException::class);
  1138.             $dirs[] = $transPaths[] = \dirname($r->getFileName(), 2).'/Resources/translations';
  1139.         }
  1140.         $defaultDir $container->getParameterBag()->resolveValue($config['default_path']);
  1141.         foreach ($container->getParameter('kernel.bundles_metadata') as $name => $bundle) {
  1142.             if ($container->fileExists($dir $bundle['path'].'/Resources/translations') || $container->fileExists($dir $bundle['path'].'/translations')) {
  1143.                 $dirs[] = $dir;
  1144.             } else {
  1145.                 $nonExistingDirs[] = $dir;
  1146.             }
  1147.         }
  1148.         foreach ($config['paths'] as $dir) {
  1149.             if ($container->fileExists($dir)) {
  1150.                 $dirs[] = $transPaths[] = $dir;
  1151.             } else {
  1152.                 throw new \UnexpectedValueException(sprintf('"%s" defined in translator.paths does not exist or is not a directory.'$dir));
  1153.             }
  1154.         }
  1155.         if ($container->hasDefinition('console.command.translation_debug')) {
  1156.             $container->getDefinition('console.command.translation_debug')->replaceArgument(5$transPaths);
  1157.         }
  1158.         if ($container->hasDefinition('console.command.translation_extract')) {
  1159.             $container->getDefinition('console.command.translation_extract')->replaceArgument(6$transPaths);
  1160.         }
  1161.         if (null === $defaultDir) {
  1162.             // allow null
  1163.         } elseif ($container->fileExists($defaultDir)) {
  1164.             $dirs[] = $defaultDir;
  1165.         } else {
  1166.             $nonExistingDirs[] = $defaultDir;
  1167.         }
  1168.         // Register translation resources
  1169.         if ($dirs) {
  1170.             $files = [];
  1171.             foreach ($dirs as $dir) {
  1172.                 $finder Finder::create()
  1173.                     ->followLinks()
  1174.                     ->files()
  1175.                     ->filter(function (\SplFileInfo $file) {
  1176.                         return <= substr_count($file->getBasename(), '.') && preg_match('/\.\w+$/'$file->getBasename());
  1177.                     })
  1178.                     ->in($dir)
  1179.                     ->sortByName()
  1180.                 ;
  1181.                 foreach ($finder as $file) {
  1182.                     $fileNameParts explode('.'basename($file));
  1183.                     $locale $fileNameParts[\count($fileNameParts) - 2];
  1184.                     if (!isset($files[$locale])) {
  1185.                         $files[$locale] = [];
  1186.                     }
  1187.                     $files[$locale][] = (string) $file;
  1188.                 }
  1189.             }
  1190.             $projectDir $container->getParameter('kernel.project_dir');
  1191.             $options array_merge(
  1192.                 $translator->getArgument(4),
  1193.                 [
  1194.                     'resource_files' => $files,
  1195.                     'scanned_directories' => $scannedDirectories array_merge($dirs$nonExistingDirs),
  1196.                     'cache_vary' => [
  1197.                         'scanned_directories' => array_map(static function (string $dir) use ($projectDir): string {
  1198.                             return str_starts_with($dir$projectDir.'/') ? substr($dir\strlen($projectDir)) : $dir;
  1199.                         }, $scannedDirectories),
  1200.                     ],
  1201.                 ]
  1202.             );
  1203.             $translator->replaceArgument(4$options);
  1204.         }
  1205.         if ($config['pseudo_localization']['enabled']) {
  1206.             $options $config['pseudo_localization'];
  1207.             unset($options['enabled']);
  1208.             $container
  1209.                 ->register('translator.pseudo'PseudoLocalizationTranslator::class)
  1210.                 ->setDecoratedService('translator'null, -1// Lower priority than "translator.data_collector"
  1211.                 ->setArguments([
  1212.                     new Reference('translator.pseudo.inner'),
  1213.                     $options,
  1214.                 ]);
  1215.         }
  1216.         $classToServices = [
  1217.             CrowdinProviderFactory::class => 'translation.provider_factory.crowdin',
  1218.             LocoProviderFactory::class => 'translation.provider_factory.loco',
  1219.             LokaliseProviderFactory::class => 'translation.provider_factory.lokalise',
  1220.         ];
  1221.         $parentPackages = ['symfony/framework-bundle''symfony/translation''symfony/http-client'];
  1222.         foreach ($classToServices as $class => $service) {
  1223.             $package substr($service\strlen('translation.provider_factory.'));
  1224.             if (!$container->hasDefinition('http_client') || !ContainerBuilder::willBeAvailable(sprintf('symfony/%s-translation-provider'$package), $class$parentPackagestrue)) {
  1225.                 $container->removeDefinition($service);
  1226.             }
  1227.         }
  1228.         if (!$config['providers']) {
  1229.             return;
  1230.         }
  1231.         // @deprecated since Symfony 5.4, in 6.0 change to:
  1232.         // $locales = $enabledLocales;
  1233.         $locales $config['enabled_locales'] ?: $enabledLocales;
  1234.         foreach ($config['providers'] as $provider) {
  1235.             if ($provider['locales']) {
  1236.                 $locales += $provider['locales'];
  1237.             }
  1238.         }
  1239.         $locales array_unique($locales);
  1240.         $container->getDefinition('console.command.translation_pull')
  1241.             ->replaceArgument(4array_merge($transPaths, [$config['default_path']]))
  1242.             ->replaceArgument(5$locales)
  1243.         ;
  1244.         $container->getDefinition('console.command.translation_push')
  1245.             ->replaceArgument(2array_merge($transPaths, [$config['default_path']]))
  1246.             ->replaceArgument(3$locales)
  1247.         ;
  1248.         $container->getDefinition('translation.provider_collection_factory')
  1249.             ->replaceArgument(1$locales)
  1250.         ;
  1251.         $container->getDefinition('translation.provider_collection')->setArgument(0$config['providers']);
  1252.     }
  1253.     private function registerValidationConfiguration(array $configContainerBuilder $containerPhpFileLoader $loaderbool $propertyInfoEnabled)
  1254.     {
  1255.         if (!$this->validatorConfigEnabled $this->isConfigEnabled($container$config)) {
  1256.             $container->removeDefinition('console.command.validator_debug');
  1257.             return;
  1258.         }
  1259.         if (!class_exists(Validation::class)) {
  1260.             throw new LogicException('Validation support cannot be enabled as the Validator component is not installed. Try running "composer require symfony/validator".');
  1261.         }
  1262.         if (!isset($config['email_validation_mode'])) {
  1263.             $config['email_validation_mode'] = 'loose';
  1264.         }
  1265.         $loader->load('validator.php');
  1266.         $validatorBuilder $container->getDefinition('validator.builder');
  1267.         $container->setParameter('validator.translation_domain'$config['translation_domain']);
  1268.         $files = ['xml' => [], 'yml' => []];
  1269.         $this->registerValidatorMapping($container$config$files);
  1270.         if (!empty($files['xml'])) {
  1271.             $validatorBuilder->addMethodCall('addXmlMappings', [$files['xml']]);
  1272.         }
  1273.         if (!empty($files['yml'])) {
  1274.             $validatorBuilder->addMethodCall('addYamlMappings', [$files['yml']]);
  1275.         }
  1276.         $definition $container->findDefinition('validator.email');
  1277.         $definition->replaceArgument(0$config['email_validation_mode']);
  1278.         if (\array_key_exists('enable_annotations'$config) && $config['enable_annotations']) {
  1279.             if (!$this->annotationsConfigEnabled && \PHP_VERSION_ID 80000) {
  1280.                 throw new \LogicException('"enable_annotations" on the validator cannot be set as the PHP version is lower than 8 and Doctrine Annotations support is disabled. Consider upgrading PHP.');
  1281.             }
  1282.             $validatorBuilder->addMethodCall('enableAnnotationMapping', [true]);
  1283.             if ($this->annotationsConfigEnabled) {
  1284.                 $validatorBuilder->addMethodCall('setDoctrineAnnotationReader', [new Reference('annotation_reader')]);
  1285.             }
  1286.         }
  1287.         if (\array_key_exists('static_method'$config) && $config['static_method']) {
  1288.             foreach ($config['static_method'] as $methodName) {
  1289.                 $validatorBuilder->addMethodCall('addMethodMapping', [$methodName]);
  1290.             }
  1291.         }
  1292.         if (!$container->getParameter('kernel.debug')) {
  1293.             $validatorBuilder->addMethodCall('setMappingCache', [new Reference('validator.mapping.cache.adapter')]);
  1294.         }
  1295.         $container->setParameter('validator.auto_mapping'$config['auto_mapping']);
  1296.         if (!$propertyInfoEnabled || !class_exists(PropertyInfoLoader::class)) {
  1297.             $container->removeDefinition('validator.property_info_loader');
  1298.         }
  1299.         $container
  1300.             ->getDefinition('validator.not_compromised_password')
  1301.             ->setArgument(2$config['not_compromised_password']['enabled'])
  1302.             ->setArgument(3$config['not_compromised_password']['endpoint'])
  1303.         ;
  1304.         if (!class_exists(ExpressionLanguage::class)) {
  1305.             $container->removeDefinition('validator.expression_language');
  1306.         }
  1307.     }
  1308.     private function registerValidatorMapping(ContainerBuilder $container, array $config, array &$files)
  1309.     {
  1310.         $fileRecorder = function ($extension$path) use (&$files) {
  1311.             $files['yaml' === $extension 'yml' $extension][] = $path;
  1312.         };
  1313.         if (ContainerBuilder::willBeAvailable('symfony/form'Form::class, ['symfony/framework-bundle''symfony/validator'], true)) {
  1314.             $reflClass = new \ReflectionClass(Form::class);
  1315.             $fileRecorder('xml'\dirname($reflClass->getFileName()).'/Resources/config/validation.xml');
  1316.         }
  1317.         foreach ($container->getParameter('kernel.bundles_metadata') as $bundle) {
  1318.             $configDir is_dir($bundle['path'].'/Resources/config') ? $bundle['path'].'/Resources/config' $bundle['path'].'/config';
  1319.             if (
  1320.                 $container->fileExists($file $configDir.'/validation.yaml'false) ||
  1321.                 $container->fileExists($file $configDir.'/validation.yml'false)
  1322.             ) {
  1323.                 $fileRecorder('yml'$file);
  1324.             }
  1325.             if ($container->fileExists($file $configDir.'/validation.xml'false)) {
  1326.                 $fileRecorder('xml'$file);
  1327.             }
  1328.             if ($container->fileExists($dir $configDir.'/validation''/^$/')) {
  1329.                 $this->registerMappingFilesFromDir($dir$fileRecorder);
  1330.             }
  1331.         }
  1332.         $projectDir $container->getParameter('kernel.project_dir');
  1333.         if ($container->fileExists($dir $projectDir.'/config/validator''/^$/')) {
  1334.             $this->registerMappingFilesFromDir($dir$fileRecorder);
  1335.         }
  1336.         $this->registerMappingFilesFromConfig($container$config$fileRecorder);
  1337.     }
  1338.     private function registerMappingFilesFromDir(string $dir, callable $fileRecorder)
  1339.     {
  1340.         foreach (Finder::create()->followLinks()->files()->in($dir)->name('/\.(xml|ya?ml)$/')->sortByName() as $file) {
  1341.             $fileRecorder($file->getExtension(), $file->getRealPath());
  1342.         }
  1343.     }
  1344.     private function registerMappingFilesFromConfig(ContainerBuilder $container, array $config, callable $fileRecorder)
  1345.     {
  1346.         foreach ($config['mapping']['paths'] as $path) {
  1347.             if (is_dir($path)) {
  1348.                 $this->registerMappingFilesFromDir($path$fileRecorder);
  1349.                 $container->addResource(new DirectoryResource($path'/^$/'));
  1350.             } elseif ($container->fileExists($pathfalse)) {
  1351.                 if (!preg_match('/\.(xml|ya?ml)$/'$path$matches)) {
  1352.                     throw new \RuntimeException(sprintf('Unsupported mapping type in "%s", supported types are XML & Yaml.'$path));
  1353.                 }
  1354.                 $fileRecorder($matches[1], $path);
  1355.             } else {
  1356.                 throw new \RuntimeException(sprintf('Could not open file or directory "%s".'$path));
  1357.             }
  1358.         }
  1359.     }
  1360.     private function registerAnnotationsConfiguration(array $configContainerBuilder $containerLoaderInterface $loader)
  1361.     {
  1362.         if (!$this->annotationsConfigEnabled) {
  1363.             return;
  1364.         }
  1365.         if (!class_exists(\Doctrine\Common\Annotations\Annotation::class)) {
  1366.             throw new LogicException('Annotations cannot be enabled as the Doctrine Annotation library is not installed. Try running "composer require doctrine/annotations".');
  1367.         }
  1368.         $loader->load('annotations.php');
  1369.         if (!method_exists(AnnotationRegistry::class, 'registerUniqueLoader')) {
  1370.             $container->getDefinition('annotations.dummy_registry')
  1371.                 ->setMethodCalls([['registerLoader', ['class_exists']]]);
  1372.         }
  1373.         if ('none' === $config['cache']) {
  1374.             $container->removeDefinition('annotations.cached_reader');
  1375.             return;
  1376.         }
  1377.         $cacheService $config['cache'];
  1378.         if (\in_array($config['cache'], ['php_array''file'])) {
  1379.             if ('php_array' === $config['cache']) {
  1380.                 $cacheService 'annotations.cache_adapter';
  1381.                 // Enable warmer only if PHP array is used for cache
  1382.                 $definition $container->findDefinition('annotations.cache_warmer');
  1383.                 $definition->addTag('kernel.cache_warmer');
  1384.             } elseif ('file' === $config['cache']) {
  1385.                 $cacheService 'annotations.filesystem_cache_adapter';
  1386.                 $cacheDir $container->getParameterBag()->resolveValue($config['file_cache_dir']);
  1387.                 if (!is_dir($cacheDir) && false === @mkdir($cacheDir0777true) && !is_dir($cacheDir)) {
  1388.                     throw new \RuntimeException(sprintf('Could not create cache directory "%s".'$cacheDir));
  1389.                 }
  1390.                 $container
  1391.                     ->getDefinition('annotations.filesystem_cache_adapter')
  1392.                     ->replaceArgument(2$cacheDir)
  1393.                 ;
  1394.             }
  1395.         } else {
  1396.             trigger_deprecation('symfony/framework-bundle''5.3''Using a custom service for "framework.annotation.cache" is deprecated, only values "none", "php_array" and "file" are valid in version 6.0.');
  1397.         }
  1398.         $container
  1399.             ->getDefinition('annotations.cached_reader')
  1400.             ->replaceArgument(2$config['debug'])
  1401.             // temporary property to lazy-reference the cache provider without using it until AddAnnotationsCachedReaderPass runs
  1402.             ->setProperty('cacheProviderBackup', new ServiceClosureArgument(new Reference($cacheService)))
  1403.             ->addTag('annotations.cached_reader')
  1404.         ;
  1405.         $container->setAlias('annotation_reader''annotations.cached_reader');
  1406.         $container->setAlias(Reader::class, new Alias('annotations.cached_reader'false));
  1407.         $container->removeDefinition('annotations.psr_cached_reader');
  1408.     }
  1409.     private function registerPropertyAccessConfiguration(array $configContainerBuilder $containerPhpFileLoader $loader)
  1410.     {
  1411.         if (!$this->propertyAccessConfigEnabled $this->isConfigEnabled($container$config)) {
  1412.             return;
  1413.         }
  1414.         $loader->load('property_access.php');
  1415.         $magicMethods PropertyAccessor::DISALLOW_MAGIC_METHODS;
  1416.         $magicMethods |= $config['magic_call'] ? PropertyAccessor::MAGIC_CALL 0;
  1417.         $magicMethods |= $config['magic_get'] ? PropertyAccessor::MAGIC_GET 0;
  1418.         $magicMethods |= $config['magic_set'] ? PropertyAccessor::MAGIC_SET 0;
  1419.         $throw PropertyAccessor::DO_NOT_THROW;
  1420.         $throw |= $config['throw_exception_on_invalid_index'] ? PropertyAccessor::THROW_ON_INVALID_INDEX 0;
  1421.         $throw |= $config['throw_exception_on_invalid_property_path'] ? PropertyAccessor::THROW_ON_INVALID_PROPERTY_PATH 0;
  1422.         $container
  1423.             ->getDefinition('property_accessor')
  1424.             ->replaceArgument(0$magicMethods)
  1425.             ->replaceArgument(1$throw)
  1426.             ->replaceArgument(3, new Reference(PropertyReadInfoExtractorInterface::class, ContainerInterface::NULL_ON_INVALID_REFERENCE))
  1427.             ->replaceArgument(4, new Reference(PropertyWriteInfoExtractorInterface::class, ContainerInterface::NULL_ON_INVALID_REFERENCE))
  1428.         ;
  1429.     }
  1430.     private function registerSecretsConfiguration(array $configContainerBuilder $containerPhpFileLoader $loader)
  1431.     {
  1432.         if (!$this->isConfigEnabled($container$config)) {
  1433.             $container->removeDefinition('console.command.secrets_set');
  1434.             $container->removeDefinition('console.command.secrets_list');
  1435.             $container->removeDefinition('console.command.secrets_remove');
  1436.             $container->removeDefinition('console.command.secrets_generate_key');
  1437.             $container->removeDefinition('console.command.secrets_decrypt_to_local');
  1438.             $container->removeDefinition('console.command.secrets_encrypt_from_local');
  1439.             return;
  1440.         }
  1441.         $loader->load('secrets.php');
  1442.         $container->getDefinition('secrets.vault')->replaceArgument(0$config['vault_directory']);
  1443.         if ($config['local_dotenv_file']) {
  1444.             $container->getDefinition('secrets.local_vault')->replaceArgument(0$config['local_dotenv_file']);
  1445.         } else {
  1446.             $container->removeDefinition('secrets.local_vault');
  1447.         }
  1448.         if ($config['decryption_env_var']) {
  1449.             if (!preg_match('/^(?:[-.\w]*+:)*+\w++$/'$config['decryption_env_var'])) {
  1450.                 throw new InvalidArgumentException(sprintf('Invalid value "%s" set as "decryption_env_var": only "word" characters are allowed.'$config['decryption_env_var']));
  1451.             }
  1452.             if (ContainerBuilder::willBeAvailable('symfony/string'LazyString::class, ['symfony/framework-bundle'], true)) {
  1453.                 $container->getDefinition('secrets.decryption_key')->replaceArgument(1$config['decryption_env_var']);
  1454.             } else {
  1455.                 $container->getDefinition('secrets.vault')->replaceArgument(1"%env({$config['decryption_env_var']})%");
  1456.                 $container->removeDefinition('secrets.decryption_key');
  1457.             }
  1458.         } else {
  1459.             $container->getDefinition('secrets.vault')->replaceArgument(1null);
  1460.             $container->removeDefinition('secrets.decryption_key');
  1461.         }
  1462.     }
  1463.     private function registerSecurityCsrfConfiguration(array $configContainerBuilder $containerPhpFileLoader $loader)
  1464.     {
  1465.         if (!$this->isConfigEnabled($container$config)) {
  1466.             return;
  1467.         }
  1468.         if (!class_exists(\Symfony\Component\Security\Csrf\CsrfToken::class)) {
  1469.             throw new LogicException('CSRF support cannot be enabled as the Security CSRF component is not installed. Try running "composer require symfony/security-csrf".');
  1470.         }
  1471.         if (!$this->sessionConfigEnabled) {
  1472.             throw new \LogicException('CSRF protection needs sessions to be enabled.');
  1473.         }
  1474.         // Enable services for CSRF protection (even without forms)
  1475.         $loader->load('security_csrf.php');
  1476.         if (!class_exists(CsrfExtension::class)) {
  1477.             $container->removeDefinition('twig.extension.security_csrf');
  1478.         }
  1479.     }
  1480.     private function registerSerializerConfiguration(array $configContainerBuilder $containerPhpFileLoader $loader)
  1481.     {
  1482.         $loader->load('serializer.php');
  1483.         if ($container->getParameter('kernel.debug')) {
  1484.             $container->removeDefinition('serializer.mapping.cache_class_metadata_factory');
  1485.         }
  1486.         $chainLoader $container->getDefinition('serializer.mapping.chain_loader');
  1487.         if (!$this->propertyAccessConfigEnabled) {
  1488.             $container->removeAlias('serializer.property_accessor');
  1489.             $container->removeDefinition('serializer.normalizer.object');
  1490.         }
  1491.         if (!class_exists(Yaml::class)) {
  1492.             $container->removeDefinition('serializer.encoder.yaml');
  1493.         }
  1494.         if (!class_exists(UnwrappingDenormalizer::class) || !$this->propertyAccessConfigEnabled) {
  1495.             $container->removeDefinition('serializer.denormalizer.unwrapping');
  1496.         }
  1497.         if (!class_exists(Headers::class)) {
  1498.             $container->removeDefinition('serializer.normalizer.mime_message');
  1499.         }
  1500.         $serializerLoaders = [];
  1501.         if (isset($config['enable_annotations']) && $config['enable_annotations']) {
  1502.             if (\PHP_VERSION_ID 80000 && !$this->annotationsConfigEnabled) {
  1503.                 throw new \LogicException('"enable_annotations" on the serializer cannot be set as the PHP version is lower than 8 and Annotations support is disabled. Consider upgrading PHP.');
  1504.             }
  1505.             $annotationLoader = new Definition(
  1506.                 'Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader',
  1507.                 [new Reference('annotation_reader'ContainerInterface::NULL_ON_INVALID_REFERENCE)]
  1508.             );
  1509.             $annotationLoader->setPublic(false);
  1510.             $serializerLoaders[] = $annotationLoader;
  1511.         }
  1512.         $fileRecorder = function ($extension$path) use (&$serializerLoaders) {
  1513.             $definition = new Definition(\in_array($extension, ['yaml''yml']) ? 'Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader' 'Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader', [$path]);
  1514.             $definition->setPublic(false);
  1515.             $serializerLoaders[] = $definition;
  1516.         };
  1517.         foreach ($container->getParameter('kernel.bundles_metadata') as $bundle) {
  1518.             $configDir is_dir($bundle['path'].'/Resources/config') ? $bundle['path'].'/Resources/config' $bundle['path'].'/config';
  1519.             if ($container->fileExists($file $configDir.'/serialization.xml'false)) {
  1520.                 $fileRecorder('xml'$file);
  1521.             }
  1522.             if (
  1523.                 $container->fileExists($file $configDir.'/serialization.yaml'false) ||
  1524.                 $container->fileExists($file $configDir.'/serialization.yml'false)
  1525.             ) {
  1526.                 $fileRecorder('yml'$file);
  1527.             }
  1528.             if ($container->fileExists($dir $configDir.'/serialization''/^$/')) {
  1529.                 $this->registerMappingFilesFromDir($dir$fileRecorder);
  1530.             }
  1531.         }
  1532.         $projectDir $container->getParameter('kernel.project_dir');
  1533.         if ($container->fileExists($dir $projectDir.'/config/serializer''/^$/')) {
  1534.             $this->registerMappingFilesFromDir($dir$fileRecorder);
  1535.         }
  1536.         $this->registerMappingFilesFromConfig($container$config$fileRecorder);
  1537.         $chainLoader->replaceArgument(0$serializerLoaders);
  1538.         $container->getDefinition('serializer.mapping.cache_warmer')->replaceArgument(0$serializerLoaders);
  1539.         if (isset($config['name_converter']) && $config['name_converter']) {
  1540.             $container->getDefinition('serializer.name_converter.metadata_aware')->setArgument(1, new Reference($config['name_converter']));
  1541.         }
  1542.         if (isset($config['circular_reference_handler']) && $config['circular_reference_handler']) {
  1543.             $arguments $container->getDefinition('serializer.normalizer.object')->getArguments();
  1544.             $context = ($arguments[6] ?? []) + ['circular_reference_handler' => new Reference($config['circular_reference_handler'])];
  1545.             $container->getDefinition('serializer.normalizer.object')->setArgument(5null);
  1546.             $container->getDefinition('serializer.normalizer.object')->setArgument(6$context);
  1547.         }
  1548.         if ($config['max_depth_handler'] ?? false) {
  1549.             $defaultContext $container->getDefinition('serializer.normalizer.object')->getArgument(6);
  1550.             $defaultContext += ['max_depth_handler' => new Reference($config['max_depth_handler'])];
  1551.             $container->getDefinition('serializer.normalizer.object')->replaceArgument(6$defaultContext);
  1552.         }
  1553.         if (isset($config['default_context']) && $config['default_context']) {
  1554.             $container->setParameter('serializer.default_context'$config['default_context']);
  1555.         }
  1556.     }
  1557.     private function registerPropertyInfoConfiguration(ContainerBuilder $containerPhpFileLoader $loader)
  1558.     {
  1559.         if (!interface_exists(PropertyInfoExtractorInterface::class)) {
  1560.             throw new LogicException('PropertyInfo support cannot be enabled as the PropertyInfo component is not installed. Try running "composer require symfony/property-info".');
  1561.         }
  1562.         $loader->load('property_info.php');
  1563.         if (
  1564.             ContainerBuilder::willBeAvailable('phpstan/phpdoc-parser'PhpDocParser::class, ['symfony/framework-bundle''symfony/property-info'], true)
  1565.             && ContainerBuilder::willBeAvailable('phpdocumentor/type-resolver'ContextFactory::class, ['symfony/framework-bundle''symfony/property-info'], true)
  1566.         ) {
  1567.             $definition $container->register('property_info.phpstan_extractor'PhpStanExtractor::class);
  1568.             $definition->addTag('property_info.type_extractor', ['priority' => -1000]);
  1569.         }
  1570.         if (ContainerBuilder::willBeAvailable('phpdocumentor/reflection-docblock'DocBlockFactoryInterface::class, ['symfony/framework-bundle''symfony/property-info'], true)) {
  1571.             $definition $container->register('property_info.php_doc_extractor''Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor');
  1572.             $definition->addTag('property_info.description_extractor', ['priority' => -1000]);
  1573.             $definition->addTag('property_info.type_extractor', ['priority' => -1001]);
  1574.         }
  1575.         if ($container->getParameter('kernel.debug')) {
  1576.             $container->removeDefinition('property_info.cache');
  1577.         }
  1578.     }
  1579.     private function registerLockConfiguration(array $configContainerBuilder $containerPhpFileLoader $loader)
  1580.     {
  1581.         $loader->load('lock.php');
  1582.         foreach ($config['resources'] as $resourceName => $resourceStores) {
  1583.             if (=== \count($resourceStores)) {
  1584.                 continue;
  1585.             }
  1586.             // Generate stores
  1587.             $storeDefinitions = [];
  1588.             foreach ($resourceStores as $storeDsn) {
  1589.                 $storeDsn $container->resolveEnvPlaceholders($storeDsnnull$usedEnvs);
  1590.                 $storeDefinition = new Definition(interface_exists(StoreInterface::class) ? StoreInterface::class : PersistingStoreInterface::class);
  1591.                 $storeDefinition->setFactory([StoreFactory::class, 'createStore']);
  1592.                 $storeDefinition->setArguments([$storeDsn]);
  1593.                 $container->setDefinition($storeDefinitionId '.lock.'.$resourceName.'.store.'.$container->hash($storeDsn), $storeDefinition);
  1594.                 $storeDefinition = new Reference($storeDefinitionId);
  1595.                 $storeDefinitions[] = $storeDefinition;
  1596.             }
  1597.             // Wrap array of stores with CombinedStore
  1598.             if (\count($storeDefinitions) > 1) {
  1599.                 $combinedDefinition = new ChildDefinition('lock.store.combined.abstract');
  1600.                 $combinedDefinition->replaceArgument(0$storeDefinitions);
  1601.                 $container->setDefinition('lock.'.$resourceName.'.store'$combinedDefinition)->setDeprecated('symfony/framework-bundle''5.2''The "%service_id%" service is deprecated, use "lock.'.$resourceName.'.factory" instead.');
  1602.                 $container->setDefinition($storeDefinitionId '.lock.'.$resourceName.'.store.'.$container->hash($resourceStores), $combinedDefinition);
  1603.             } else {
  1604.                 $container->setAlias('lock.'.$resourceName.'.store', (new Alias($storeDefinitionIdfalse))->setDeprecated('symfony/framework-bundle''5.2''The "%alias_id%" alias is deprecated, use "lock.'.$resourceName.'.factory" instead.'));
  1605.             }
  1606.             // Generate factories for each resource
  1607.             $factoryDefinition = new ChildDefinition('lock.factory.abstract');
  1608.             $factoryDefinition->replaceArgument(0, new Reference($storeDefinitionId));
  1609.             $container->setDefinition('lock.'.$resourceName.'.factory'$factoryDefinition);
  1610.             // Generate services for lock instances
  1611.             $lockDefinition = new Definition(Lock::class);
  1612.             $lockDefinition->setPublic(false);
  1613.             $lockDefinition->setFactory([new Reference('lock.'.$resourceName.'.factory'), 'createLock']);
  1614.             $lockDefinition->setArguments([$resourceName]);
  1615.             $container->setDefinition('lock.'.$resourceName$lockDefinition)->setDeprecated('symfony/framework-bundle''5.2''The "%service_id%" service is deprecated, use "lock.'.$resourceName.'.factory" instead.');
  1616.             // provide alias for default resource
  1617.             if ('default' === $resourceName) {
  1618.                 $container->setAlias('lock.store', (new Alias($storeDefinitionIdfalse))->setDeprecated('symfony/framework-bundle''5.2''The "%alias_id%" alias is deprecated, use "lock.factory" instead.'));
  1619.                 $container->setAlias('lock.factory', new Alias('lock.'.$resourceName.'.factory'false));
  1620.                 $container->setAlias('lock', (new Alias('lock.'.$resourceNamefalse))->setDeprecated('symfony/framework-bundle''5.2''The "%alias_id%" alias is deprecated, use "lock.factory" instead.'));
  1621.                 $container->setAlias(PersistingStoreInterface::class, (new Alias($storeDefinitionIdfalse))->setDeprecated('symfony/framework-bundle''5.2''The "%alias_id%" alias is deprecated, use "'.LockFactory::class.'" instead.'));
  1622.                 $container->setAlias(LockFactory::class, new Alias('lock.factory'false));
  1623.                 $container->setAlias(LockInterface::class, (new Alias('lock.'.$resourceNamefalse))->setDeprecated('symfony/framework-bundle''5.2''The "%alias_id%" alias is deprecated, use "'.LockFactory::class.'" instead.'));
  1624.             } else {
  1625.                 $container->registerAliasForArgument($storeDefinitionIdPersistingStoreInterface::class, $resourceName.'.lock.store')->setDeprecated('symfony/framework-bundle''5.2''The "%alias_id%" alias is deprecated, use "'.LockFactory::class.' '.$resourceName.'LockFactory" instead.');
  1626.                 $container->registerAliasForArgument('lock.'.$resourceName.'.factory'LockFactory::class, $resourceName.'.lock.factory');
  1627.                 $container->registerAliasForArgument('lock.'.$resourceNameLockInterface::class, $resourceName.'.lock')->setDeprecated('symfony/framework-bundle''5.2''The "%alias_id%" alias is deprecated, use "'.LockFactory::class.' $'.$resourceName.'LockFactory" instead.');
  1628.             }
  1629.         }
  1630.     }
  1631.     private function registerMessengerConfiguration(array $configContainerBuilder $containerPhpFileLoader $loader, array $validationConfig)
  1632.     {
  1633.         if (!interface_exists(MessageBusInterface::class)) {
  1634.             throw new LogicException('Messenger support cannot be enabled as the Messenger component is not installed. Try running "composer require symfony/messenger".');
  1635.         }
  1636.         $loader->load('messenger.php');
  1637.         if (!interface_exists(DenormalizerInterface::class)) {
  1638.             $container->removeDefinition('serializer.normalizer.flatten_exception');
  1639.         }
  1640.         if (ContainerBuilder::willBeAvailable('symfony/amqp-messenger'AmqpTransportFactory::class, ['symfony/framework-bundle''symfony/messenger'], true)) {
  1641.             $container->getDefinition('messenger.transport.amqp.factory')->addTag('messenger.transport_factory');
  1642.         }
  1643.         if (ContainerBuilder::willBeAvailable('symfony/redis-messenger'RedisTransportFactory::class, ['symfony/framework-bundle''symfony/messenger'], true)) {
  1644.             $container->getDefinition('messenger.transport.redis.factory')->addTag('messenger.transport_factory');
  1645.         }
  1646.         if (ContainerBuilder::willBeAvailable('symfony/amazon-sqs-messenger'AmazonSqsTransportFactory::class, ['symfony/framework-bundle''symfony/messenger'], true)) {
  1647.             $container->getDefinition('messenger.transport.sqs.factory')->addTag('messenger.transport_factory');
  1648.         }
  1649.         if (ContainerBuilder::willBeAvailable('symfony/beanstalkd-messenger'BeanstalkdTransportFactory::class, ['symfony/framework-bundle''symfony/messenger'], true)) {
  1650.             $container->getDefinition('messenger.transport.beanstalkd.factory')->addTag('messenger.transport_factory');
  1651.         }
  1652.         if (null === $config['default_bus'] && === \count($config['buses'])) {
  1653.             $config['default_bus'] = key($config['buses']);
  1654.         }
  1655.         $defaultMiddleware = [
  1656.             'before' => [
  1657.                 ['id' => 'add_bus_name_stamp_middleware'],
  1658.                 ['id' => 'reject_redelivered_message_middleware'],
  1659.                 ['id' => 'dispatch_after_current_bus'],
  1660.                 ['id' => 'failed_message_processing_middleware'],
  1661.             ],
  1662.             'after' => [
  1663.                 ['id' => 'send_message'],
  1664.                 ['id' => 'handle_message'],
  1665.             ],
  1666.         ];
  1667.         foreach ($config['buses'] as $busId => $bus) {
  1668.             $middleware $bus['middleware'];
  1669.             if ($bus['default_middleware']) {
  1670.                 if ('allow_no_handlers' === $bus['default_middleware']) {
  1671.                     $defaultMiddleware['after'][1]['arguments'] = [true];
  1672.                 } else {
  1673.                     unset($defaultMiddleware['after'][1]['arguments']);
  1674.                 }
  1675.                 // argument to add_bus_name_stamp_middleware
  1676.                 $defaultMiddleware['before'][0]['arguments'] = [$busId];
  1677.                 $middleware array_merge($defaultMiddleware['before'], $middleware$defaultMiddleware['after']);
  1678.             }
  1679.             foreach ($middleware as $middlewareItem) {
  1680.                 if (!$validationConfig['enabled'] && \in_array($middlewareItem['id'], ['validation''messenger.middleware.validation'], true)) {
  1681.                     throw new LogicException('The Validation middleware is only available when the Validator component is installed and enabled. Try running "composer require symfony/validator".');
  1682.                 }
  1683.             }
  1684.             if ($container->getParameter('kernel.debug') && class_exists(Stopwatch::class)) {
  1685.                 array_unshift($middleware, ['id' => 'traceable''arguments' => [$busId]]);
  1686.             }
  1687.             $container->setParameter($busId.'.middleware'$middleware);
  1688.             $container->register($busIdMessageBus::class)->addArgument([])->addTag('messenger.bus');
  1689.             if ($busId === $config['default_bus']) {
  1690.                 $container->setAlias('messenger.default_bus'$busId)->setPublic(true);
  1691.                 $container->setAlias(MessageBusInterface::class, $busId);
  1692.             } else {
  1693.                 $container->registerAliasForArgument($busIdMessageBusInterface::class);
  1694.             }
  1695.         }
  1696.         if (empty($config['transports'])) {
  1697.             $container->removeDefinition('messenger.transport.symfony_serializer');
  1698.             $container->removeDefinition('messenger.transport.amqp.factory');
  1699.             $container->removeDefinition('messenger.transport.redis.factory');
  1700.             $container->removeDefinition('messenger.transport.sqs.factory');
  1701.             $container->removeDefinition('messenger.transport.beanstalkd.factory');
  1702.             $container->removeAlias(SerializerInterface::class);
  1703.         } else {
  1704.             $container->getDefinition('messenger.transport.symfony_serializer')
  1705.                 ->replaceArgument(1$config['serializer']['symfony_serializer']['format'])
  1706.                 ->replaceArgument(2$config['serializer']['symfony_serializer']['context']);
  1707.             $container->setAlias('messenger.default_serializer'$config['serializer']['default_serializer']);
  1708.         }
  1709.         $failureTransports = [];
  1710.         if ($config['failure_transport']) {
  1711.             if (!isset($config['transports'][$config['failure_transport']])) {
  1712.                 throw new LogicException(sprintf('Invalid Messenger configuration: the failure transport "%s" is not a valid transport or service id.'$config['failure_transport']));
  1713.             }
  1714.             $container->setAlias('messenger.failure_transports.default''messenger.transport.'.$config['failure_transport']);
  1715.             $failureTransports[] = $config['failure_transport'];
  1716.         }
  1717.         $failureTransportsByName = [];
  1718.         foreach ($config['transports'] as $name => $transport) {
  1719.             if ($transport['failure_transport']) {
  1720.                 $failureTransports[] = $transport['failure_transport'];
  1721.                 $failureTransportsByName[$name] = $transport['failure_transport'];
  1722.             } elseif ($config['failure_transport']) {
  1723.                 $failureTransportsByName[$name] = $config['failure_transport'];
  1724.             }
  1725.         }
  1726.         $senderAliases = [];
  1727.         $transportRetryReferences = [];
  1728.         foreach ($config['transports'] as $name => $transport) {
  1729.             $serializerId $transport['serializer'] ?? 'messenger.default_serializer';
  1730.             $transportDefinition = (new Definition(TransportInterface::class))
  1731.                 ->setFactory([new Reference('messenger.transport_factory'), 'createTransport'])
  1732.                 ->setArguments([$transport['dsn'], $transport['options'] + ['transport_name' => $name], new Reference($serializerId)])
  1733.                 ->addTag('messenger.receiver', [
  1734.                         'alias' => $name,
  1735.                         'is_failure_transport' => \in_array($name$failureTransports),
  1736.                     ]
  1737.                 )
  1738.             ;
  1739.             $container->setDefinition($transportId 'messenger.transport.'.$name$transportDefinition);
  1740.             $senderAliases[$name] = $transportId;
  1741.             if (null !== $transport['retry_strategy']['service']) {
  1742.                 $transportRetryReferences[$name] = new Reference($transport['retry_strategy']['service']);
  1743.             } else {
  1744.                 $retryServiceId sprintf('messenger.retry.multiplier_retry_strategy.%s'$name);
  1745.                 $retryDefinition = new ChildDefinition('messenger.retry.abstract_multiplier_retry_strategy');
  1746.                 $retryDefinition
  1747.                     ->replaceArgument(0$transport['retry_strategy']['max_retries'])
  1748.                     ->replaceArgument(1$transport['retry_strategy']['delay'])
  1749.                     ->replaceArgument(2$transport['retry_strategy']['multiplier'])
  1750.                     ->replaceArgument(3$transport['retry_strategy']['max_delay']);
  1751.                 $container->setDefinition($retryServiceId$retryDefinition);
  1752.                 $transportRetryReferences[$name] = new Reference($retryServiceId);
  1753.             }
  1754.         }
  1755.         $senderReferences = [];
  1756.         // alias => service_id
  1757.         foreach ($senderAliases as $alias => $serviceId) {
  1758.             $senderReferences[$alias] = new Reference($serviceId);
  1759.         }
  1760.         // service_id => service_id
  1761.         foreach ($senderAliases as $serviceId) {
  1762.             $senderReferences[$serviceId] = new Reference($serviceId);
  1763.         }
  1764.         foreach ($config['transports'] as $name => $transport) {
  1765.             if ($transport['failure_transport']) {
  1766.                 if (!isset($senderReferences[$transport['failure_transport']])) {
  1767.                     throw new LogicException(sprintf('Invalid Messenger configuration: the failure transport "%s" is not a valid transport or service id.'$transport['failure_transport']));
  1768.                 }
  1769.             }
  1770.         }
  1771.         $failureTransportReferencesByTransportName array_map(function ($failureTransportName) use ($senderReferences) {
  1772.             return $senderReferences[$failureTransportName];
  1773.         }, $failureTransportsByName);
  1774.         $messageToSendersMapping = [];
  1775.         foreach ($config['routing'] as $message => $messageConfiguration) {
  1776.             if ('*' !== $message && !class_exists($message) && !interface_exists($messagefalse)) {
  1777.                 throw new LogicException(sprintf('Invalid Messenger routing configuration: class or interface "%s" not found.'$message));
  1778.             }
  1779.             // make sure senderAliases contains all senders
  1780.             foreach ($messageConfiguration['senders'] as $sender) {
  1781.                 if (!isset($senderReferences[$sender])) {
  1782.                     throw new LogicException(sprintf('Invalid Messenger routing configuration: the "%s" class is being routed to a sender called "%s". This is not a valid transport or service id.'$message$sender));
  1783.                 }
  1784.             }
  1785.             $messageToSendersMapping[$message] = $messageConfiguration['senders'];
  1786.         }
  1787.         $sendersServiceLocator ServiceLocatorTagPass::register($container$senderReferences);
  1788.         $container->getDefinition('messenger.senders_locator')
  1789.             ->replaceArgument(0$messageToSendersMapping)
  1790.             ->replaceArgument(1$sendersServiceLocator)
  1791.         ;
  1792.         $container->getDefinition('messenger.retry.send_failed_message_for_retry_listener')
  1793.             ->replaceArgument(0$sendersServiceLocator)
  1794.         ;
  1795.         $container->getDefinition('messenger.retry_strategy_locator')
  1796.             ->replaceArgument(0$transportRetryReferences);
  1797.         if (\count($failureTransports) > 0) {
  1798.             $container->getDefinition('console.command.messenger_failed_messages_retry')
  1799.                 ->replaceArgument(0$config['failure_transport']);
  1800.             $container->getDefinition('console.command.messenger_failed_messages_show')
  1801.                 ->replaceArgument(0$config['failure_transport']);
  1802.             $container->getDefinition('console.command.messenger_failed_messages_remove')
  1803.                 ->replaceArgument(0$config['failure_transport']);
  1804.             $failureTransportsByTransportNameServiceLocator ServiceLocatorTagPass::register($container$failureTransportReferencesByTransportName);
  1805.             $container->getDefinition('messenger.failure.send_failed_message_to_failure_transport_listener')
  1806.                 ->replaceArgument(0$failureTransportsByTransportNameServiceLocator);
  1807.         } else {
  1808.             $container->removeDefinition('messenger.failure.send_failed_message_to_failure_transport_listener');
  1809.             $container->removeDefinition('console.command.messenger_failed_messages_retry');
  1810.             $container->removeDefinition('console.command.messenger_failed_messages_show');
  1811.             $container->removeDefinition('console.command.messenger_failed_messages_remove');
  1812.         }
  1813.         if (false === $config['reset_on_message']) {
  1814.             throw new LogicException('The "framework.messenger.reset_on_message" configuration option can be set to "true" only. To prevent services resetting after each message you can set the "--no-reset" option in "messenger:consume" command.');
  1815.         }
  1816.         if (!$container->hasDefinition('console.command.messenger_consume_messages')) {
  1817.             $container->removeDefinition('messenger.listener.reset_services');
  1818.         } elseif (null === $config['reset_on_message']) {
  1819.             trigger_deprecation('symfony/framework-bundle''5.4''Not setting the "framework.messenger.reset_on_message" configuration option is deprecated, it will default to "true" in version 6.0.');
  1820.             $container->getDefinition('console.command.messenger_consume_messages')->replaceArgument(5null);
  1821.             $container->removeDefinition('messenger.listener.reset_services');
  1822.         }
  1823.     }
  1824.     private function registerCacheConfiguration(array $configContainerBuilder $container)
  1825.     {
  1826.         if (!class_exists(DefaultMarshaller::class)) {
  1827.             $container->removeDefinition('cache.default_marshaller');
  1828.         }
  1829.         if (!class_exists(DoctrineAdapter::class)) {
  1830.             $container->removeDefinition('cache.adapter.doctrine');
  1831.         }
  1832.         if (!class_exists(DoctrineDbalAdapter::class)) {
  1833.             $container->removeDefinition('cache.adapter.doctrine_dbal');
  1834.         }
  1835.         $version = new Parameter('container.build_id');
  1836.         $container->getDefinition('cache.adapter.apcu')->replaceArgument(2$version);
  1837.         $container->getDefinition('cache.adapter.system')->replaceArgument(2$version);
  1838.         $container->getDefinition('cache.adapter.filesystem')->replaceArgument(2$config['directory']);
  1839.         if (isset($config['prefix_seed'])) {
  1840.             $container->setParameter('cache.prefix.seed'$config['prefix_seed']);
  1841.         }
  1842.         if ($container->hasParameter('cache.prefix.seed')) {
  1843.             // Inline any env vars referenced in the parameter
  1844.             $container->setParameter('cache.prefix.seed'$container->resolveEnvPlaceholders($container->getParameter('cache.prefix.seed'), true));
  1845.         }
  1846.         foreach (['doctrine''psr6''redis''memcached''doctrine_dbal''pdo'] as $name) {
  1847.             if (isset($config[$name 'default_'.$name.'_provider'])) {
  1848.                 $container->setAlias('cache.'.$name, new Alias(CachePoolPass::getServiceProvider($container$config[$name]), false));
  1849.             }
  1850.         }
  1851.         foreach (['app''system'] as $name) {
  1852.             $config['pools']['cache.'.$name] = [
  1853.                 'adapters' => [$config[$name]],
  1854.                 'public' => true,
  1855.                 'tags' => false,
  1856.             ];
  1857.         }
  1858.         foreach ($config['pools'] as $name => $pool) {
  1859.             $pool['adapters'] = $pool['adapters'] ?: ['cache.app'];
  1860.             $isRedisTagAware = ['cache.adapter.redis_tag_aware'] === $pool['adapters'];
  1861.             foreach ($pool['adapters'] as $provider => $adapter) {
  1862.                 if (($config['pools'][$adapter]['adapters'] ?? null) === ['cache.adapter.redis_tag_aware']) {
  1863.                     $isRedisTagAware true;
  1864.                 } elseif ($config['pools'][$adapter]['tags'] ?? false) {
  1865.                     $pool['adapters'][$provider] = $adapter '.'.$adapter.'.inner';
  1866.                 }
  1867.             }
  1868.             if (=== \count($pool['adapters'])) {
  1869.                 if (!isset($pool['provider']) && !\is_int($provider)) {
  1870.                     $pool['provider'] = $provider;
  1871.                 }
  1872.                 $definition = new ChildDefinition($adapter);
  1873.             } else {
  1874.                 $definition = new Definition(ChainAdapter::class, [$pool['adapters'], 0]);
  1875.                 $pool['reset'] = 'reset';
  1876.             }
  1877.             if ($isRedisTagAware && 'cache.app' === $name) {
  1878.                 $container->setAlias('cache.app.taggable'$name);
  1879.             } elseif ($isRedisTagAware) {
  1880.                 $tagAwareId $name;
  1881.                 $container->setAlias('.'.$name.'.inner'$name);
  1882.             } elseif ($pool['tags']) {
  1883.                 if (true !== $pool['tags'] && ($config['pools'][$pool['tags']]['tags'] ?? false)) {
  1884.                     $pool['tags'] = '.'.$pool['tags'].'.inner';
  1885.                 }
  1886.                 $container->register($nameTagAwareAdapter::class)
  1887.                     ->addArgument(new Reference('.'.$name.'.inner'))
  1888.                     ->addArgument(true !== $pool['tags'] ? new Reference($pool['tags']) : null)
  1889.                     ->setPublic($pool['public'])
  1890.                 ;
  1891.                 if (method_exists(TagAwareAdapter::class, 'setLogger')) {
  1892.                     $container
  1893.                         ->getDefinition($name)
  1894.                         ->addMethodCall('setLogger', [new Reference('logger'ContainerInterface::IGNORE_ON_INVALID_REFERENCE)]);
  1895.                 }
  1896.                 $pool['name'] = $tagAwareId $name;
  1897.                 $pool['public'] = false;
  1898.                 $name '.'.$name.'.inner';
  1899.             } elseif (!\in_array($name, ['cache.app''cache.system'], true)) {
  1900.                 $tagAwareId '.'.$name.'.taggable';
  1901.                 $container->register($tagAwareIdTagAwareAdapter::class)
  1902.                     ->addArgument(new Reference($name))
  1903.                 ;
  1904.             }
  1905.             if (!\in_array($name, ['cache.app''cache.system'], true)) {
  1906.                 $container->registerAliasForArgument($tagAwareIdTagAwareCacheInterface::class, $pool['name'] ?? $name);
  1907.                 $container->registerAliasForArgument($nameCacheInterface::class, $pool['name'] ?? $name);
  1908.                 $container->registerAliasForArgument($nameCacheItemPoolInterface::class, $pool['name'] ?? $name);
  1909.             }
  1910.             $definition->setPublic($pool['public']);
  1911.             unset($pool['adapters'], $pool['public'], $pool['tags']);
  1912.             $definition->addTag('cache.pool'$pool);
  1913.             $container->setDefinition($name$definition);
  1914.         }
  1915.         if (method_exists(PropertyAccessor::class, 'createCache')) {
  1916.             $propertyAccessDefinition $container->register('cache.property_access'AdapterInterface::class);
  1917.             $propertyAccessDefinition->setPublic(false);
  1918.             if (!$container->getParameter('kernel.debug')) {
  1919.                 $propertyAccessDefinition->setFactory([PropertyAccessor::class, 'createCache']);
  1920.                 $propertyAccessDefinition->setArguments([''0$version, new Reference('logger'ContainerInterface::IGNORE_ON_INVALID_REFERENCE)]);
  1921.                 $propertyAccessDefinition->addTag('cache.pool', ['clearer' => 'cache.system_clearer']);
  1922.                 $propertyAccessDefinition->addTag('monolog.logger', ['channel' => 'cache']);
  1923.             } else {
  1924.                 $propertyAccessDefinition->setClass(ArrayAdapter::class);
  1925.                 $propertyAccessDefinition->setArguments([0false]);
  1926.             }
  1927.         }
  1928.     }
  1929.     private function registerHttpClientConfiguration(array $configContainerBuilder $containerPhpFileLoader $loader, array $profilerConfig)
  1930.     {
  1931.         $loader->load('http_client.php');
  1932.         $options $config['default_options'] ?? [];
  1933.         $retryOptions $options['retry_failed'] ?? ['enabled' => false];
  1934.         unset($options['retry_failed']);
  1935.         $container->getDefinition('http_client')->setArguments([$options$config['max_host_connections'] ?? 6]);
  1936.         if (!$hasPsr18 ContainerBuilder::willBeAvailable('psr/http-client'ClientInterface::class, ['symfony/framework-bundle''symfony/http-client'], true)) {
  1937.             $container->removeDefinition('psr18.http_client');
  1938.             $container->removeAlias(ClientInterface::class);
  1939.         }
  1940.         if (!ContainerBuilder::willBeAvailable('php-http/httplug'HttpClient::class, ['symfony/framework-bundle''symfony/http-client'], true)) {
  1941.             $container->removeDefinition(HttpClient::class);
  1942.         }
  1943.         if ($this->isConfigEnabled($container$retryOptions)) {
  1944.             $this->registerRetryableHttpClient($retryOptions'http_client'$container);
  1945.         }
  1946.         $httpClientId = ($retryOptions['enabled'] ?? false) ? 'http_client.retryable.inner' : ($this->isConfigEnabled($container$profilerConfig) ? '.debug.http_client.inner' 'http_client');
  1947.         foreach ($config['scoped_clients'] as $name => $scopeConfig) {
  1948.             if ('http_client' === $name) {
  1949.                 throw new InvalidArgumentException(sprintf('Invalid scope name: "%s" is reserved.'$name));
  1950.             }
  1951.             $scope $scopeConfig['scope'] ?? null;
  1952.             unset($scopeConfig['scope']);
  1953.             $retryOptions $scopeConfig['retry_failed'] ?? ['enabled' => false];
  1954.             unset($scopeConfig['retry_failed']);
  1955.             if (null === $scope) {
  1956.                 $baseUri $scopeConfig['base_uri'];
  1957.                 unset($scopeConfig['base_uri']);
  1958.                 $container->register($nameScopingHttpClient::class)
  1959.                     ->setFactory([ScopingHttpClient::class, 'forBaseUri'])
  1960.                     ->setArguments([new Reference($httpClientId), $baseUri$scopeConfig])
  1961.                     ->addTag('http_client.client')
  1962.                 ;
  1963.             } else {
  1964.                 $container->register($nameScopingHttpClient::class)
  1965.                     ->setArguments([new Reference($httpClientId), [$scope => $scopeConfig], $scope])
  1966.                     ->addTag('http_client.client')
  1967.                 ;
  1968.             }
  1969.             if ($this->isConfigEnabled($container$retryOptions)) {
  1970.                 $this->registerRetryableHttpClient($retryOptions$name$container);
  1971.             }
  1972.             $container->registerAliasForArgument($nameHttpClientInterface::class);
  1973.             if ($hasPsr18) {
  1974.                 $container->setDefinition('psr18.'.$name, new ChildDefinition('psr18.http_client'))
  1975.                     ->replaceArgument(0, new Reference($name));
  1976.                 $container->registerAliasForArgument('psr18.'.$nameClientInterface::class, $name);
  1977.             }
  1978.         }
  1979.         if ($responseFactoryId $config['mock_response_factory'] ?? null) {
  1980.             $container->register($httpClientId.'.mock_client'MockHttpClient::class)
  1981.                 ->setDecoratedService($httpClientIdnull, -10// lower priority than TraceableHttpClient
  1982.                 ->setArguments([new Reference($responseFactoryId)]);
  1983.         }
  1984.     }
  1985.     private function registerRetryableHttpClient(array $optionsstring $nameContainerBuilder $container)
  1986.     {
  1987.         if (!class_exists(RetryableHttpClient::class)) {
  1988.             throw new LogicException('Support for retrying failed requests requires symfony/http-client 5.2 or higher, try upgrading.');
  1989.         }
  1990.         if (null !== $options['retry_strategy']) {
  1991.             $retryStrategy = new Reference($options['retry_strategy']);
  1992.         } else {
  1993.             $retryStrategy = new ChildDefinition('http_client.abstract_retry_strategy');
  1994.             $codes = [];
  1995.             foreach ($options['http_codes'] as $code => $codeOptions) {
  1996.                 if ($codeOptions['methods']) {
  1997.                     $codes[$code] = $codeOptions['methods'];
  1998.                 } else {
  1999.                     $codes[] = $code;
  2000.                 }
  2001.             }
  2002.             $retryStrategy
  2003.                 ->replaceArgument(0$codes ?: GenericRetryStrategy::DEFAULT_RETRY_STATUS_CODES)
  2004.                 ->replaceArgument(1$options['delay'])
  2005.                 ->replaceArgument(2$options['multiplier'])
  2006.                 ->replaceArgument(3$options['max_delay'])
  2007.                 ->replaceArgument(4$options['jitter']);
  2008.             $container->setDefinition($name.'.retry_strategy'$retryStrategy);
  2009.             $retryStrategy = new Reference($name.'.retry_strategy');
  2010.         }
  2011.         $container
  2012.             ->register($name.'.retryable'RetryableHttpClient::class)
  2013.             ->setDecoratedService($namenull10// higher priority than TraceableHttpClient
  2014.             ->setArguments([new Reference($name.'.retryable.inner'), $retryStrategy$options['max_retries'], new Reference('logger')])
  2015.             ->addTag('monolog.logger', ['channel' => 'http_client']);
  2016.     }
  2017.     private function registerMailerConfiguration(array $configContainerBuilder $containerPhpFileLoader $loader)
  2018.     {
  2019.         if (!class_exists(Mailer::class)) {
  2020.             throw new LogicException('Mailer support cannot be enabled as the component is not installed. Try running "composer require symfony/mailer".');
  2021.         }
  2022.         $loader->load('mailer.php');
  2023.         $loader->load('mailer_transports.php');
  2024.         if (!\count($config['transports']) && null === $config['dsn']) {
  2025.             $config['dsn'] = 'smtp://null';
  2026.         }
  2027.         $transports $config['dsn'] ? ['main' => $config['dsn']] : $config['transports'];
  2028.         $container->getDefinition('mailer.transports')->setArgument(0$transports);
  2029.         $container->getDefinition('mailer.default_transport')->setArgument(0current($transports));
  2030.         $container->removeDefinition('mailer.logger_message_listener');
  2031.         $container->setAlias('mailer.logger_message_listener', (new Alias('mailer.message_logger_listener'))->setDeprecated('symfony/framework-bundle''5.2''The "%alias_id%" alias is deprecated, use "mailer.message_logger_listener" instead.'));
  2032.         $mailer $container->getDefinition('mailer.mailer');
  2033.         if (false === $messageBus $config['message_bus']) {
  2034.             $mailer->replaceArgument(1null);
  2035.         } else {
  2036.             $mailer->replaceArgument(1$messageBus ? new Reference($messageBus) : new Reference('messenger.default_bus'ContainerInterface::NULL_ON_INVALID_REFERENCE));
  2037.         }
  2038.         $classToServices = [
  2039.             GmailTransportFactory::class => 'mailer.transport_factory.gmail',
  2040.             MailgunTransportFactory::class => 'mailer.transport_factory.mailgun',
  2041.             MailjetTransportFactory::class => 'mailer.transport_factory.mailjet',
  2042.             MandrillTransportFactory::class => 'mailer.transport_factory.mailchimp',
  2043.             PostmarkTransportFactory::class => 'mailer.transport_factory.postmark',
  2044.             SendgridTransportFactory::class => 'mailer.transport_factory.sendgrid',
  2045.             SendinblueTransportFactory::class => 'mailer.transport_factory.sendinblue',
  2046.             SesTransportFactory::class => 'mailer.transport_factory.amazon',
  2047.             OhMySmtpTransportFactory::class => 'mailer.transport_factory.ohmysmtp',
  2048.         ];
  2049.         foreach ($classToServices as $class => $service) {
  2050.             $package substr($service\strlen('mailer.transport_factory.'));
  2051.             if (!ContainerBuilder::willBeAvailable(sprintf('symfony/%s-mailer''gmail' === $package 'google' $package), $class, ['symfony/framework-bundle''symfony/mailer'], true)) {
  2052.                 $container->removeDefinition($service);
  2053.             }
  2054.         }
  2055.         $envelopeListener $container->getDefinition('mailer.envelope_listener');
  2056.         $envelopeListener->setArgument(0$config['envelope']['sender'] ?? null);
  2057.         $envelopeListener->setArgument(1$config['envelope']['recipients'] ?? null);
  2058.         if ($config['headers']) {
  2059.             $headers = new Definition(Headers::class);
  2060.             foreach ($config['headers'] as $name => $data) {
  2061.                 $value $data['value'];
  2062.                 if (\in_array(strtolower($name), ['from''to''cc''bcc''reply-to'])) {
  2063.                     $value = (array) $value;
  2064.                 }
  2065.                 $headers->addMethodCall('addHeader', [$name$value]);
  2066.             }
  2067.             $messageListener $container->getDefinition('mailer.message_listener');
  2068.             $messageListener->setArgument(0$headers);
  2069.         } else {
  2070.             $container->removeDefinition('mailer.message_listener');
  2071.         }
  2072.     }
  2073.     private function registerNotifierConfiguration(array $configContainerBuilder $containerPhpFileLoader $loader)
  2074.     {
  2075.         if (!class_exists(Notifier::class)) {
  2076.             throw new LogicException('Notifier support cannot be enabled as the component is not installed. Try running "composer require symfony/notifier".');
  2077.         }
  2078.         $loader->load('notifier.php');
  2079.         $loader->load('notifier_transports.php');
  2080.         if ($config['chatter_transports']) {
  2081.             $container->getDefinition('chatter.transports')->setArgument(0$config['chatter_transports']);
  2082.         } else {
  2083.             $container->removeDefinition('chatter');
  2084.         }
  2085.         if ($config['texter_transports']) {
  2086.             $container->getDefinition('texter.transports')->setArgument(0$config['texter_transports']);
  2087.         } else {
  2088.             $container->removeDefinition('texter');
  2089.         }
  2090.         if ($this->mailerConfigEnabled) {
  2091.             $sender $container->getDefinition('mailer.envelope_listener')->getArgument(0);
  2092.             $container->getDefinition('notifier.channel.email')->setArgument(2$sender);
  2093.         } else {
  2094.             $container->removeDefinition('notifier.channel.email');
  2095.         }
  2096.         if ($this->messengerConfigEnabled) {
  2097.             if ($config['notification_on_failed_messages']) {
  2098.                 $container->getDefinition('notifier.failed_message_listener')->addTag('kernel.event_subscriber');
  2099.             }
  2100.             // as we have a bus, the channels don't need the transports
  2101.             $container->getDefinition('notifier.channel.chat')->setArgument(0null);
  2102.             if ($container->hasDefinition('notifier.channel.email')) {
  2103.                 $container->getDefinition('notifier.channel.email')->setArgument(0null);
  2104.             }
  2105.             $container->getDefinition('notifier.channel.sms')->setArgument(0null);
  2106.             $container->getDefinition('notifier.channel.push')->setArgument(0null);
  2107.         }
  2108.         $container->getDefinition('notifier.channel_policy')->setArgument(0$config['channel_policy']);
  2109.         $container->registerForAutoconfiguration(NotifierTransportFactoryInterface::class)
  2110.             ->addTag('chatter.transport_factory');
  2111.         $container->registerForAutoconfiguration(NotifierTransportFactoryInterface::class)
  2112.             ->addTag('texter.transport_factory');
  2113.         $classToServices = [
  2114.             AllMySmsTransportFactory::class => 'notifier.transport_factory.all-my-sms',
  2115.             AmazonSnsTransportFactory::class => 'notifier.transport_factory.amazon-sns',
  2116.             ClickatellTransportFactory::class => 'notifier.transport_factory.clickatell',
  2117.             DiscordTransportFactory::class => 'notifier.transport_factory.discord',
  2118.             EsendexTransportFactory::class => 'notifier.transport_factory.esendex',
  2119.             ExpoTransportFactory::class => 'notifier.transport_factory.expo',
  2120.             FakeChatTransportFactory::class => 'notifier.transport_factory.fake-chat',
  2121.             FakeSmsTransportFactory::class => 'notifier.transport_factory.fake-sms',
  2122.             FirebaseTransportFactory::class => 'notifier.transport_factory.firebase',
  2123.             FreeMobileTransportFactory::class => 'notifier.transport_factory.free-mobile',
  2124.             GatewayApiTransportFactory::class => 'notifier.transport_factory.gateway-api',
  2125.             GitterTransportFactory::class => 'notifier.transport_factory.gitter',
  2126.             GoogleChatTransportFactory::class => 'notifier.transport_factory.google-chat',
  2127.             InfobipTransportFactory::class => 'notifier.transport_factory.infobip',
  2128.             IqsmsTransportFactory::class => 'notifier.transport_factory.iqsms',
  2129.             LightSmsTransportFactory::class => 'notifier.transport_factory.light-sms',
  2130.             LinkedInTransportFactory::class => 'notifier.transport_factory.linked-in',
  2131.             MailjetNotifierTransportFactory::class => 'notifier.transport_factory.mailjet',
  2132.             MattermostTransportFactory::class => 'notifier.transport_factory.mattermost',
  2133.             MercureTransportFactory::class => 'notifier.transport_factory.mercure',
  2134.             MessageBirdTransport::class => 'notifier.transport_factory.message-bird',
  2135.             MessageMediaTransportFactory::class => 'notifier.transport_factory.message-media',
  2136.             MicrosoftTeamsTransportFactory::class => 'notifier.transport_factory.microsoft-teams',
  2137.             MobytTransportFactory::class => 'notifier.transport_factory.mobyt',
  2138.             NexmoTransportFactory::class => 'notifier.transport_factory.nexmo',
  2139.             OctopushTransportFactory::class => 'notifier.transport_factory.octopush',
  2140.             OneSignalTransportFactory::class => 'notifier.transport_factory.one-signal',
  2141.             OvhCloudTransportFactory::class => 'notifier.transport_factory.ovh-cloud',
  2142.             RocketChatTransportFactory::class => 'notifier.transport_factory.rocket-chat',
  2143.             SendinblueNotifierTransportFactory::class => 'notifier.transport_factory.sendinblue',
  2144.             SinchTransportFactory::class => 'notifier.transport_factory.sinch',
  2145.             SlackTransportFactory::class => 'notifier.transport_factory.slack',
  2146.             Sms77TransportFactory::class => 'notifier.transport_factory.sms77',
  2147.             SmsapiTransportFactory::class => 'notifier.transport_factory.smsapi',
  2148.             SmsBiurasTransportFactory::class => 'notifier.transport_factory.sms-biuras',
  2149.             SmscTransportFactory::class => 'notifier.transport_factory.smsc',
  2150.             SpotHitTransportFactory::class => 'notifier.transport_factory.spot-hit',
  2151.             TelegramTransportFactory::class => 'notifier.transport_factory.telegram',
  2152.             TelnyxTransportFactory::class => 'notifier.transport_factory.telnyx',
  2153.             TurboSmsTransport::class => 'notifier.transport_factory.turbo-sms',
  2154.             TwilioTransportFactory::class => 'notifier.transport_factory.twilio',
  2155.             VonageTransportFactory::class => 'notifier.transport_factory.vonage',
  2156.             YunpianTransportFactory::class => 'notifier.transport_factory.yunpian',
  2157.             ZulipTransportFactory::class => 'notifier.transport_factory.zulip',
  2158.         ];
  2159.         $parentPackages = ['symfony/framework-bundle''symfony/notifier'];
  2160.         foreach ($classToServices as $class => $service) {
  2161.             $package substr($service\strlen('notifier.transport_factory.'));
  2162.             if (!ContainerBuilder::willBeAvailable(sprintf('symfony/%s-notifier'$package), $class$parentPackagestrue)) {
  2163.                 $container->removeDefinition($service);
  2164.                 $container->removeAlias(str_replace('-'''$service)); // @deprecated to be removed in 6.0
  2165.             }
  2166.         }
  2167.         if (ContainerBuilder::willBeAvailable('symfony/mercure-notifier'MercureTransportFactory::class, $parentPackagestrue) && ContainerBuilder::willBeAvailable('symfony/mercure-bundle'MercureBundle::class, $parentPackagestrue)) {
  2168.             $container->getDefinition($classToServices[MercureTransportFactory::class])
  2169.                 ->replaceArgument('$registry', new Reference(HubRegistry::class));
  2170.         } elseif (ContainerBuilder::willBeAvailable('symfony/mercure-notifier'MercureTransportFactory::class, $parentPackagestrue)) {
  2171.             $container->removeDefinition($classToServices[MercureTransportFactory::class]);
  2172.         }
  2173.         if (ContainerBuilder::willBeAvailable('symfony/fake-chat-notifier'FakeChatTransportFactory::class, ['symfony/framework-bundle''symfony/notifier''symfony/mailer'], true)) {
  2174.             $container->getDefinition($classToServices[FakeChatTransportFactory::class])
  2175.                 ->replaceArgument('$mailer', new Reference('mailer'))
  2176.                 ->replaceArgument('$logger', new Reference('logger'));
  2177.         }
  2178.         if (ContainerBuilder::willBeAvailable('symfony/fake-sms-notifier'FakeSmsTransportFactory::class, ['symfony/framework-bundle''symfony/notifier''symfony/mailer'], true)) {
  2179.             $container->getDefinition($classToServices[FakeSmsTransportFactory::class])
  2180.                 ->replaceArgument('$mailer', new Reference('mailer'))
  2181.                 ->replaceArgument('$logger', new Reference('logger'));
  2182.         }
  2183.         if (isset($config['admin_recipients'])) {
  2184.             $notifier $container->getDefinition('notifier');
  2185.             foreach ($config['admin_recipients'] as $i => $recipient) {
  2186.                 $id 'notifier.admin_recipient.'.$i;
  2187.                 $container->setDefinition($id, new Definition(Recipient::class, [$recipient['email'], $recipient['phone']]));
  2188.                 $notifier->addMethodCall('addAdminRecipient', [new Reference($id)]);
  2189.             }
  2190.         }
  2191.     }
  2192.     private function registerRateLimiterConfiguration(array $configContainerBuilder $containerPhpFileLoader $loader)
  2193.     {
  2194.         $loader->load('rate_limiter.php');
  2195.         foreach ($config['limiters'] as $name => $limiterConfig) {
  2196.             self::registerRateLimiter($container$name$limiterConfig);
  2197.         }
  2198.     }
  2199.     public static function registerRateLimiter(ContainerBuilder $containerstring $name, array $limiterConfig)
  2200.     {
  2201.         // default configuration (when used by other DI extensions)
  2202.         $limiterConfig += ['lock_factory' => 'lock.factory''cache_pool' => 'cache.rate_limiter'];
  2203.         $limiter $container->setDefinition($limiterId 'limiter.'.$name, new ChildDefinition('limiter'));
  2204.         if (null !== $limiterConfig['lock_factory']) {
  2205.             if (!self::$lockConfigEnabled) {
  2206.                 throw new LogicException(sprintf('Rate limiter "%s" requires the Lock component to be installed and configured.'$name));
  2207.             }
  2208.             $limiter->replaceArgument(2, new Reference($limiterConfig['lock_factory']));
  2209.         }
  2210.         unset($limiterConfig['lock_factory']);
  2211.         $storageId $limiterConfig['storage_service'] ?? null;
  2212.         if (null === $storageId) {
  2213.             $container->register($storageId 'limiter.storage.'.$nameCacheStorage::class)->addArgument(new Reference($limiterConfig['cache_pool']));
  2214.         }
  2215.         $limiter->replaceArgument(1, new Reference($storageId));
  2216.         unset($limiterConfig['storage_service']);
  2217.         unset($limiterConfig['cache_pool']);
  2218.         $limiterConfig['id'] = $name;
  2219.         $limiter->replaceArgument(0$limiterConfig);
  2220.         $container->registerAliasForArgument($limiterIdRateLimiterFactory::class, $name.'.limiter');
  2221.     }
  2222.     private function registerUidConfiguration(array $configContainerBuilder $containerPhpFileLoader $loader)
  2223.     {
  2224.         $loader->load('uid.php');
  2225.         $container->getDefinition('uuid.factory')
  2226.             ->setArguments([
  2227.                 $config['default_uuid_version'],
  2228.                 $config['time_based_uuid_version'],
  2229.                 $config['name_based_uuid_version'],
  2230.                 UuidV4::class,
  2231.                 $config['time_based_uuid_node'] ?? null,
  2232.                 $config['name_based_uuid_namespace'] ?? null,
  2233.             ])
  2234.         ;
  2235.         if (isset($config['name_based_uuid_namespace'])) {
  2236.             $container->getDefinition('name_based_uuid.factory')
  2237.                 ->setArguments([$config['name_based_uuid_namespace']]);
  2238.         }
  2239.     }
  2240.     private function resolveTrustedHeaders(array $headers): int
  2241.     {
  2242.         $trustedHeaders 0;
  2243.         foreach ($headers as $h) {
  2244.             switch ($h) {
  2245.                 case 'forwarded'$trustedHeaders |= Request::HEADER_FORWARDED; break;
  2246.                 case 'x-forwarded-for'$trustedHeaders |= Request::HEADER_X_FORWARDED_FOR; break;
  2247.                 case 'x-forwarded-host'$trustedHeaders |= Request::HEADER_X_FORWARDED_HOST; break;
  2248.                 case 'x-forwarded-proto'$trustedHeaders |= Request::HEADER_X_FORWARDED_PROTO; break;
  2249.                 case 'x-forwarded-port'$trustedHeaders |= Request::HEADER_X_FORWARDED_PORT; break;
  2250.                 case 'x-forwarded-prefix'$trustedHeaders |= Request::HEADER_X_FORWARDED_PREFIX; break;
  2251.             }
  2252.         }
  2253.         return $trustedHeaders;
  2254.     }
  2255.     /**
  2256.      * {@inheritdoc}
  2257.      */
  2258.     public function getXsdValidationBasePath()
  2259.     {
  2260.         return \dirname(__DIR__).'/Resources/config/schema';
  2261.     }
  2262.     public function getNamespace()
  2263.     {
  2264.         return 'http://symfony.com/schema/dic/symfony';
  2265.     }
  2266. }