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

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