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

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