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

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