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

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