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

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