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.             'container.service_locator',
  569.             'container.service_subscriber',
  570.             'kernel.event_subscriber',
  571.             'kernel.event_listener',
  572.             'kernel.locale_aware',
  573.             'kernel.reset',
  574.         ]);
  575.     }
  576.     /**
  577.      * {@inheritdoc}
  578.      */
  579.     public function getConfiguration(array $configContainerBuilder $container)
  580.     {
  581.         return new Configuration($container->getParameter('kernel.debug'));
  582.     }
  583.     protected function hasConsole(): bool
  584.     {
  585.         return class_exists(Application::class);
  586.     }
  587.     private function registerFormConfiguration(array $configContainerBuilder $containerPhpFileLoader $loader)
  588.     {
  589.         $loader->load('form.php');
  590.         $container->getDefinition('form.type_extension.form.validator')->setArgument(1$config['form']['legacy_error_messages']);
  591.         if (null === $config['form']['csrf_protection']['enabled']) {
  592.             $config['form']['csrf_protection']['enabled'] = $config['csrf_protection']['enabled'];
  593.         }
  594.         if ($this->isConfigEnabled($container$config['form']['csrf_protection'])) {
  595.             $loader->load('form_csrf.php');
  596.             $container->setParameter('form.type_extension.csrf.enabled'true);
  597.             $container->setParameter('form.type_extension.csrf.field_name'$config['form']['csrf_protection']['field_name']);
  598.         } else {
  599.             $container->setParameter('form.type_extension.csrf.enabled'false);
  600.         }
  601.         if (!ContainerBuilder::willBeAvailable('symfony/translation'Translator::class, ['symfony/framework-bundle''symfony/form'], true)) {
  602.             $container->removeDefinition('form.type_extension.upload.validator');
  603.         }
  604.         if (!method_exists(CachingFactoryDecorator::class, 'reset')) {
  605.             $container->getDefinition('form.choice_list_factory.cached')
  606.                 ->clearTag('kernel.reset')
  607.             ;
  608.         }
  609.     }
  610.     private function registerHttpCacheConfiguration(array $configContainerBuilder $containerbool $httpMethodOverride)
  611.     {
  612.         $options $config;
  613.         unset($options['enabled']);
  614.         if (!$options['private_headers']) {
  615.             unset($options['private_headers']);
  616.         }
  617.         $container->getDefinition('http_cache')
  618.             ->setPublic($config['enabled'])
  619.             ->replaceArgument(3$options);
  620.         if ($httpMethodOverride) {
  621.             $container->getDefinition('http_cache')
  622.                   ->addArgument((new Definition('void'))
  623.                       ->setFactory([Request::class, 'enableHttpMethodParameterOverride'])
  624.                   );
  625.         }
  626.     }
  627.     private function registerEsiConfiguration(array $configContainerBuilder $containerPhpFileLoader $loader)
  628.     {
  629.         if (!$this->isConfigEnabled($container$config)) {
  630.             $container->removeDefinition('fragment.renderer.esi');
  631.             return;
  632.         }
  633.         $loader->load('esi.php');
  634.     }
  635.     private function registerSsiConfiguration(array $configContainerBuilder $containerPhpFileLoader $loader)
  636.     {
  637.         if (!$this->isConfigEnabled($container$config)) {
  638.             $container->removeDefinition('fragment.renderer.ssi');
  639.             return;
  640.         }
  641.         $loader->load('ssi.php');
  642.     }
  643.     private function registerFragmentsConfiguration(array $configContainerBuilder $containerPhpFileLoader $loader)
  644.     {
  645.         if (!$this->isConfigEnabled($container$config)) {
  646.             $container->removeDefinition('fragment.renderer.hinclude');
  647.             return;
  648.         }
  649.         $container->setParameter('fragment.renderer.hinclude.global_template'$config['hinclude_default_template']);
  650.         $loader->load('fragment_listener.php');
  651.         $container->setParameter('fragment.path'$config['path']);
  652.     }
  653.     private function registerProfilerConfiguration(array $configContainerBuilder $containerPhpFileLoader $loader)
  654.     {
  655.         if (!$this->isConfigEnabled($container$config)) {
  656.             // this is needed for the WebProfiler to work even if the profiler is disabled
  657.             $container->setParameter('data_collector.templates', []);
  658.             return;
  659.         }
  660.         $loader->load('profiling.php');
  661.         $loader->load('collectors.php');
  662.         $loader->load('cache_debug.php');
  663.         if ($this->formConfigEnabled) {
  664.             $loader->load('form_debug.php');
  665.         }
  666.         if ($this->validatorConfigEnabled) {
  667.             $loader->load('validator_debug.php');
  668.         }
  669.         if ($this->translationConfigEnabled) {
  670.             $loader->load('translation_debug.php');
  671.             $container->getDefinition('translator.data_collector')->setDecoratedService('translator');
  672.         }
  673.         if ($this->messengerConfigEnabled) {
  674.             $loader->load('messenger_debug.php');
  675.         }
  676.         if ($this->mailerConfigEnabled) {
  677.             $loader->load('mailer_debug.php');
  678.         }
  679.         if ($this->httpClientConfigEnabled) {
  680.             $loader->load('http_client_debug.php');
  681.         }
  682.         if ($this->notifierConfigEnabled) {
  683.             $loader->load('notifier_debug.php');
  684.         }
  685.         $container->setParameter('profiler_listener.only_exceptions'$config['only_exceptions']);
  686.         $container->setParameter('profiler_listener.only_main_requests'$config['only_main_requests'] || $config['only_master_requests']);
  687.         // Choose storage class based on the DSN
  688.         [$class] = explode(':'$config['dsn'], 2);
  689.         if ('file' !== $class) {
  690.             throw new \LogicException(sprintf('Driver "%s" is not supported for the profiler.'$class));
  691.         }
  692.         $container->setParameter('profiler.storage.dsn'$config['dsn']);
  693.         $container->getDefinition('profiler')
  694.             ->addArgument($config['collect'])
  695.             ->addTag('kernel.reset', ['method' => 'reset']);
  696.         $container->getDefinition('profiler_listener')
  697.             ->addArgument($config['collect_parameter']);
  698.     }
  699.     private function registerWorkflowConfiguration(array $configContainerBuilder $containerPhpFileLoader $loader)
  700.     {
  701.         if (!$config['enabled']) {
  702.             $container->removeDefinition('console.command.workflow_dump');
  703.             return;
  704.         }
  705.         if (!class_exists(Workflow\Workflow::class)) {
  706.             throw new LogicException('Workflow support cannot be enabled as the Workflow component is not installed. Try running "composer require symfony/workflow".');
  707.         }
  708.         $loader->load('workflow.php');
  709.         $registryDefinition $container->getDefinition('workflow.registry');
  710.         $workflows = [];
  711.         foreach ($config['workflows'] as $name => $workflow) {
  712.             $type $workflow['type'];
  713.             $workflowId sprintf('%s.%s'$type$name);
  714.             // Process Metadata (workflow + places (transition is done in the "create transition" block))
  715.             $metadataStoreDefinition = new Definition(Workflow\Metadata\InMemoryMetadataStore::class, [[], [], null]);
  716.             if ($workflow['metadata']) {
  717.                 $metadataStoreDefinition->replaceArgument(0$workflow['metadata']);
  718.             }
  719.             $placesMetadata = [];
  720.             foreach ($workflow['places'] as $place) {
  721.                 if ($place['metadata']) {
  722.                     $placesMetadata[$place['name']] = $place['metadata'];
  723.                 }
  724.             }
  725.             if ($placesMetadata) {
  726.                 $metadataStoreDefinition->replaceArgument(1$placesMetadata);
  727.             }
  728.             // Create transitions
  729.             $transitions = [];
  730.             $guardsConfiguration = [];
  731.             $transitionsMetadataDefinition = new Definition(\SplObjectStorage::class);
  732.             // Global transition counter per workflow
  733.             $transitionCounter 0;
  734.             foreach ($workflow['transitions'] as $transition) {
  735.                 if ('workflow' === $type) {
  736.                     $transitionDefinition = new Definition(Workflow\Transition::class, [$transition['name'], $transition['from'], $transition['to']]);
  737.                     $transitionDefinition->setPublic(false);
  738.                     $transitionId sprintf('.%s.transition.%s'$workflowId$transitionCounter++);
  739.                     $container->setDefinition($transitionId$transitionDefinition);
  740.                     $transitions[] = new Reference($transitionId);
  741.                     if (isset($transition['guard'])) {
  742.                         $configuration = new Definition(Workflow\EventListener\GuardExpression::class);
  743.                         $configuration->addArgument(new Reference($transitionId));
  744.                         $configuration->addArgument($transition['guard']);
  745.                         $configuration->setPublic(false);
  746.                         $eventName sprintf('workflow.%s.guard.%s'$name$transition['name']);
  747.                         $guardsConfiguration[$eventName][] = $configuration;
  748.                     }
  749.                     if ($transition['metadata']) {
  750.                         $transitionsMetadataDefinition->addMethodCall('attach', [
  751.                             new Reference($transitionId),
  752.                             $transition['metadata'],
  753.                         ]);
  754.                     }
  755.                 } elseif ('state_machine' === $type) {
  756.                     foreach ($transition['from'] as $from) {
  757.                         foreach ($transition['to'] as $to) {
  758.                             $transitionDefinition = new Definition(Workflow\Transition::class, [$transition['name'], $from$to]);
  759.                             $transitionDefinition->setPublic(false);
  760.                             $transitionId sprintf('.%s.transition.%s'$workflowId$transitionCounter++);
  761.                             $container->setDefinition($transitionId$transitionDefinition);
  762.                             $transitions[] = new Reference($transitionId);
  763.                             if (isset($transition['guard'])) {
  764.                                 $configuration = new Definition(Workflow\EventListener\GuardExpression::class);
  765.                                 $configuration->addArgument(new Reference($transitionId));
  766.                                 $configuration->addArgument($transition['guard']);
  767.                                 $configuration->setPublic(false);
  768.                                 $eventName sprintf('workflow.%s.guard.%s'$name$transition['name']);
  769.                                 $guardsConfiguration[$eventName][] = $configuration;
  770.                             }
  771.                             if ($transition['metadata']) {
  772.                                 $transitionsMetadataDefinition->addMethodCall('attach', [
  773.                                     new Reference($transitionId),
  774.                                     $transition['metadata'],
  775.                                 ]);
  776.                             }
  777.                         }
  778.                     }
  779.                 }
  780.             }
  781.             $metadataStoreDefinition->replaceArgument(2$transitionsMetadataDefinition);
  782.             $container->setDefinition(sprintf('%s.metadata_store'$workflowId), $metadataStoreDefinition);
  783.             // Create places
  784.             $places array_column($workflow['places'], 'name');
  785.             $initialMarking $workflow['initial_marking'] ?? [];
  786.             // Create a Definition
  787.             $definitionDefinition = new Definition(Workflow\Definition::class);
  788.             $definitionDefinition->setPublic(false);
  789.             $definitionDefinition->addArgument($places);
  790.             $definitionDefinition->addArgument($transitions);
  791.             $definitionDefinition->addArgument($initialMarking);
  792.             $definitionDefinition->addArgument(new Reference(sprintf('%s.metadata_store'$workflowId)));
  793.             $workflows[$workflowId] = $definitionDefinition;
  794.             // Create MarkingStore
  795.             if (isset($workflow['marking_store']['type'])) {
  796.                 $markingStoreDefinition = new ChildDefinition('workflow.marking_store.method');
  797.                 $markingStoreDefinition->setArguments([
  798.                     'state_machine' === $type//single state
  799.                     $workflow['marking_store']['property'],
  800.                 ]);
  801.             } elseif (isset($workflow['marking_store']['service'])) {
  802.                 $markingStoreDefinition = new Reference($workflow['marking_store']['service']);
  803.             }
  804.             // Create Workflow
  805.             $workflowDefinition = new ChildDefinition(sprintf('%s.abstract'$type));
  806.             $workflowDefinition->replaceArgument(0, new Reference(sprintf('%s.definition'$workflowId)));
  807.             $workflowDefinition->replaceArgument(1$markingStoreDefinition ?? null);
  808.             $workflowDefinition->replaceArgument(3$name);
  809.             $workflowDefinition->replaceArgument(4$workflow['events_to_dispatch']);
  810.             $workflowDefinition->addTag('container.private', [
  811.                 'package' => 'symfony/framework-bundle',
  812.                 'version' => '5.3',
  813.             ]);
  814.             // Store to container
  815.             $container->setDefinition($workflowId$workflowDefinition);
  816.             $container->setDefinition(sprintf('%s.definition'$workflowId), $definitionDefinition);
  817.             $container->registerAliasForArgument($workflowIdWorkflowInterface::class, $name.'.'.$type);
  818.             // Validate Workflow
  819.             if ('state_machine' === $workflow['type']) {
  820.                 $validator = new Workflow\Validator\StateMachineValidator();
  821.             } else {
  822.                 $validator = new Workflow\Validator\WorkflowValidator();
  823.             }
  824.             $trs array_map(function (Reference $ref) use ($container): Workflow\Transition {
  825.                 return $container->get((string) $ref);
  826.             }, $transitions);
  827.             $realDefinition = new Workflow\Definition($places$trs$initialMarking);
  828.             $validator->validate($realDefinition$name);
  829.             // Add workflow to Registry
  830.             if ($workflow['supports']) {
  831.                 foreach ($workflow['supports'] as $supportedClassName) {
  832.                     $strategyDefinition = new Definition(Workflow\SupportStrategy\InstanceOfSupportStrategy::class, [$supportedClassName]);
  833.                     $strategyDefinition->setPublic(false);
  834.                     $registryDefinition->addMethodCall('addWorkflow', [new Reference($workflowId), $strategyDefinition]);
  835.                 }
  836.             } elseif (isset($workflow['support_strategy'])) {
  837.                 $registryDefinition->addMethodCall('addWorkflow', [new Reference($workflowId), new Reference($workflow['support_strategy'])]);
  838.             }
  839.             // Enable the AuditTrail
  840.             if ($workflow['audit_trail']['enabled']) {
  841.                 $listener = new Definition(Workflow\EventListener\AuditTrailListener::class);
  842.                 $listener->addTag('monolog.logger', ['channel' => 'workflow']);
  843.                 $listener->addTag('kernel.event_listener', ['event' => sprintf('workflow.%s.leave'$name), 'method' => 'onLeave']);
  844.                 $listener->addTag('kernel.event_listener', ['event' => sprintf('workflow.%s.transition'$name), 'method' => 'onTransition']);
  845.                 $listener->addTag('kernel.event_listener', ['event' => sprintf('workflow.%s.enter'$name), 'method' => 'onEnter']);
  846.                 $listener->addArgument(new Reference('logger'));
  847.                 $container->setDefinition(sprintf('.%s.listener.audit_trail'$workflowId), $listener);
  848.             }
  849.             // Add Guard Listener
  850.             if ($guardsConfiguration) {
  851.                 if (!class_exists(ExpressionLanguage::class)) {
  852.                     throw new LogicException('Cannot guard workflows as the ExpressionLanguage component is not installed. Try running "composer require symfony/expression-language".');
  853.                 }
  854.                 if (!class_exists(Security::class)) {
  855.                     throw new LogicException('Cannot guard workflows as the Security component is not installed. Try running "composer require symfony/security-core".');
  856.                 }
  857.                 $guard = new Definition(Workflow\EventListener\GuardListener::class);
  858.                 $guard->setArguments([
  859.                     $guardsConfiguration,
  860.                     new Reference('workflow.security.expression_language'),
  861.                     new Reference('security.token_storage'),
  862.                     new Reference('security.authorization_checker'),
  863.                     new Reference('security.authentication.trust_resolver'),
  864.                     new Reference('security.role_hierarchy'),
  865.                     new Reference('validator'ContainerInterface::NULL_ON_INVALID_REFERENCE),
  866.                 ]);
  867.                 foreach ($guardsConfiguration as $eventName => $config) {
  868.                     $guard->addTag('kernel.event_listener', ['event' => $eventName'method' => 'onTransition']);
  869.                 }
  870.                 $container->setDefinition(sprintf('.%s.listener.guard'$workflowId), $guard);
  871.                 $container->setParameter('workflow.has_guard_listeners'true);
  872.             }
  873.         }
  874.         $commandDumpDefinition $container->getDefinition('console.command.workflow_dump');
  875.         $commandDumpDefinition->setArgument(0$workflows);
  876.     }
  877.     private function registerDebugConfiguration(array $configContainerBuilder $containerPhpFileLoader $loader)
  878.     {
  879.         $loader->load('debug_prod.php');
  880.         if (class_exists(Stopwatch::class)) {
  881.             $container->register('debug.stopwatch'Stopwatch::class)
  882.                 ->addArgument(true)
  883.                 ->addTag('kernel.reset', ['method' => 'reset']);
  884.             $container->setAlias(Stopwatch::class, new Alias('debug.stopwatch'false));
  885.         }
  886.         $debug $container->getParameter('kernel.debug');
  887.         if ($debug) {
  888.             $container->setParameter('debug.container.dump''%kernel.build_dir%/%kernel.container_class%.xml');
  889.         }
  890.         if ($debug && class_exists(Stopwatch::class)) {
  891.             $loader->load('debug.php');
  892.         }
  893.         $definition $container->findDefinition('debug.debug_handlers_listener');
  894.         if (false === $config['log']) {
  895.             $definition->replaceArgument(1null);
  896.         } elseif (true !== $config['log']) {
  897.             $definition->replaceArgument(2$config['log']);
  898.         }
  899.         if (!$config['throw']) {
  900.             $container->setParameter('debug.error_handler.throw_at'0);
  901.         }
  902.         if ($debug && class_exists(DebugProcessor::class)) {
  903.             $definition = new Definition(DebugProcessor::class);
  904.             $definition->setPublic(false);
  905.             $definition->addArgument(new Reference('request_stack'));
  906.             $container->setDefinition('debug.log_processor'$definition);
  907.         }
  908.     }
  909.     private function registerRouterConfiguration(array $configContainerBuilder $containerPhpFileLoader $loader, array $enabledLocales = [])
  910.     {
  911.         if (!$this->isConfigEnabled($container$config)) {
  912.             $container->removeDefinition('console.command.router_debug');
  913.             $container->removeDefinition('console.command.router_match');
  914.             $container->removeDefinition('messenger.middleware.router_context');
  915.             return;
  916.         }
  917.         if (!class_exists(RouterContextMiddleware::class)) {
  918.             $container->removeDefinition('messenger.middleware.router_context');
  919.         }
  920.         $loader->load('routing.php');
  921.         if (null === $config['utf8']) {
  922.             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.');
  923.         }
  924.         if ($config['utf8']) {
  925.             $container->getDefinition('routing.loader')->replaceArgument(1, ['utf8' => true]);
  926.         }
  927.         if ($enabledLocales) {
  928.             $enabledLocales implode('|'array_map('preg_quote'$enabledLocales));
  929.             $container->getDefinition('routing.loader')->replaceArgument(2, ['_locale' => $enabledLocales]);
  930.         }
  931.         if (!ContainerBuilder::willBeAvailable('symfony/expression-language'ExpressionLanguage::class, ['symfony/framework-bundle''symfony/routing'], true)) {
  932.             $container->removeDefinition('router.expression_language_provider');
  933.         }
  934.         $container->setParameter('router.resource'$config['resource']);
  935.         $router $container->findDefinition('router.default');
  936.         $argument $router->getArgument(2);
  937.         $argument['strict_requirements'] = $config['strict_requirements'];
  938.         if (isset($config['type'])) {
  939.             $argument['resource_type'] = $config['type'];
  940.         }
  941.         $router->replaceArgument(2$argument);
  942.         $container->setParameter('request_listener.http_port'$config['http_port']);
  943.         $container->setParameter('request_listener.https_port'$config['https_port']);
  944.         if (null !== $config['default_uri']) {
  945.             $container->getDefinition('router.request_context')
  946.                 ->replaceArgument(0$config['default_uri']);
  947.         }
  948.         if (\PHP_VERSION_ID 80000 && !$this->annotationsConfigEnabled) {
  949.             return;
  950.         }
  951.         $container->register('routing.loader.annotation'AnnotatedRouteControllerLoader::class)
  952.             ->setPublic(false)
  953.             ->addTag('routing.loader', ['priority' => -10])
  954.             ->setArguments([
  955.                 new Reference('annotation_reader'ContainerInterface::NULL_ON_INVALID_REFERENCE),
  956.                 '%kernel.environment%',
  957.             ]);
  958.         $container->register('routing.loader.annotation.directory'AnnotationDirectoryLoader::class)
  959.             ->setPublic(false)
  960.             ->addTag('routing.loader', ['priority' => -10])
  961.             ->setArguments([
  962.                 new Reference('file_locator'),
  963.                 new Reference('routing.loader.annotation'),
  964.             ]);
  965.         $container->register('routing.loader.annotation.file'AnnotationFileLoader::class)
  966.             ->setPublic(false)
  967.             ->addTag('routing.loader', ['priority' => -10])
  968.             ->setArguments([
  969.                 new Reference('file_locator'),
  970.                 new Reference('routing.loader.annotation'),
  971.             ]);
  972.     }
  973.     private function registerSessionConfiguration(array $configContainerBuilder $containerPhpFileLoader $loader)
  974.     {
  975.         $loader->load('session.php');
  976.         // session storage
  977.         if (null === $config['storage_factory_id']) {
  978.             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.');
  979.             $container->setAlias('session.storage'$config['storage_id']);
  980.             $container->setAlias('session.storage.factory''session.storage.factory.service');
  981.         } else {
  982.             $container->setAlias('session.storage.factory'$config['storage_factory_id']);
  983.             $container->removeAlias(SessionStorageInterface::class);
  984.             $container->removeDefinition('session.storage.metadata_bag');
  985.             $container->removeDefinition('session.storage.native');
  986.             $container->removeDefinition('session.storage.php_bridge');
  987.             $container->removeDefinition('session.storage.mock_file');
  988.             $container->removeAlias('session.storage.filesystem');
  989.         }
  990.         $options = ['cache_limiter' => '0'];
  991.         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) {
  992.             if (isset($config[$key])) {
  993.                 $options[$key] = $config[$key];
  994.             }
  995.         }
  996.         if ('auto' === ($options['cookie_secure'] ?? null)) {
  997.             if (null === $config['storage_factory_id']) {
  998.                 $locator $container->getDefinition('session_listener')->getArgument(0);
  999.                 $locator->setValues($locator->getValues() + [
  1000.                     'session_storage' => new Reference('session.storage'ContainerInterface::IGNORE_ON_INVALID_REFERENCE),
  1001.                     'request_stack' => new Reference('request_stack'),
  1002.                 ]);
  1003.             } else {
  1004.                 $container->getDefinition('session.storage.factory.native')->replaceArgument(3true);
  1005.                 $container->getDefinition('session.storage.factory.php_bridge')->replaceArgument(2true);
  1006.             }
  1007.         }
  1008.         $container->setParameter('session.storage.options'$options);
  1009.         // session handler (the internal callback registered with PHP session management)
  1010.         if (null === $config['handler_id']) {
  1011.             // Set the handler class to be null
  1012.             if ($container->hasDefinition('session.storage.native')) {
  1013.                 $container->getDefinition('session.storage.native')->replaceArgument(1null);
  1014.                 $container->getDefinition('session.storage.php_bridge')->replaceArgument(0null);
  1015.             } else {
  1016.                 $container->getDefinition('session.storage.factory.native')->replaceArgument(1null);
  1017.                 $container->getDefinition('session.storage.factory.php_bridge')->replaceArgument(0null);
  1018.             }
  1019.             $container->setAlias('session.handler''session.handler.native_file');
  1020.         } else {
  1021.             $container->resolveEnvPlaceholders($config['handler_id'], null$usedEnvs);
  1022.             if ($usedEnvs || preg_match('#^[a-z]++://#'$config['handler_id'])) {
  1023.                 $id '.cache_connection.'.ContainerBuilder::hash($config['handler_id']);
  1024.                 $container->getDefinition('session.abstract_handler')
  1025.                     ->replaceArgument(0$container->hasDefinition($id) ? new Reference($id) : $config['handler_id']);
  1026.                 $container->setAlias('session.handler''session.abstract_handler');
  1027.             } else {
  1028.                 $container->setAlias('session.handler'$config['handler_id']);
  1029.             }
  1030.         }
  1031.         $container->setParameter('session.save_path'$config['save_path']);
  1032.         $container->setParameter('session.metadata.update_threshold'$config['metadata_update_threshold']);
  1033.     }
  1034.     private function registerRequestConfiguration(array $configContainerBuilder $containerPhpFileLoader $loader)
  1035.     {
  1036.         if ($config['formats']) {
  1037.             $loader->load('request.php');
  1038.             $listener $container->getDefinition('request.add_request_formats_listener');
  1039.             $listener->replaceArgument(0$config['formats']);
  1040.         }
  1041.     }
  1042.     private function registerAssetsConfiguration(array $configContainerBuilder $containerPhpFileLoader $loader)
  1043.     {
  1044.         $loader->load('assets.php');
  1045.         if ($config['version_strategy']) {
  1046.             $defaultVersion = new Reference($config['version_strategy']);
  1047.         } else {
  1048.             $defaultVersion $this->createVersion($container$config['version'], $config['version_format'], $config['json_manifest_path'], '_default'$config['strict_mode']);
  1049.         }
  1050.         $defaultPackage $this->createPackageDefinition($config['base_path'], $config['base_urls'], $defaultVersion);
  1051.         $container->setDefinition('assets._default_package'$defaultPackage);
  1052.         foreach ($config['packages'] as $name => $package) {
  1053.             if (null !== $package['version_strategy']) {
  1054.                 $version = new Reference($package['version_strategy']);
  1055.             } elseif (!\array_key_exists('version'$package) && null === $package['json_manifest_path']) {
  1056.                 // if neither version nor json_manifest_path are specified, use the default
  1057.                 $version $defaultVersion;
  1058.             } else {
  1059.                 // let format fallback to main version_format
  1060.                 $format $package['version_format'] ?: $config['version_format'];
  1061.                 $version $package['version'] ?? null;
  1062.                 $version $this->createVersion($container$version$format$package['json_manifest_path'], $name$package['strict_mode']);
  1063.             }
  1064.             $packageDefinition $this->createPackageDefinition($package['base_path'], $package['base_urls'], $version)
  1065.                 ->addTag('assets.package', ['package' => $name]);
  1066.             $container->setDefinition('assets._package_'.$name$packageDefinition);
  1067.             $container->registerAliasForArgument('assets._package_'.$namePackageInterface::class, $name.'.package');
  1068.         }
  1069.     }
  1070.     /**
  1071.      * Returns a definition for an asset package.
  1072.      */
  1073.     private function createPackageDefinition(?string $basePath, array $baseUrlsReference $version): Definition
  1074.     {
  1075.         if ($basePath && $baseUrls) {
  1076.             throw new \LogicException('An asset package cannot have base URLs and base paths.');
  1077.         }
  1078.         $package = new ChildDefinition($baseUrls 'assets.url_package' 'assets.path_package');
  1079.         $package
  1080.             ->setPublic(false)
  1081.             ->replaceArgument(0$baseUrls ?: $basePath)
  1082.             ->replaceArgument(1$version)
  1083.         ;
  1084.         return $package;
  1085.     }
  1086.     private function createVersion(ContainerBuilder $container, ?string $version, ?string $format, ?string $jsonManifestPathstring $namebool $strictMode): Reference
  1087.     {
  1088.         // Configuration prevents $version and $jsonManifestPath from being set
  1089.         if (null !== $version) {
  1090.             $def = new ChildDefinition('assets.static_version_strategy');
  1091.             $def
  1092.                 ->replaceArgument(0$version)
  1093.                 ->replaceArgument(1$format)
  1094.             ;
  1095.             $container->setDefinition('assets._version_'.$name$def);
  1096.             return new Reference('assets._version_'.$name);
  1097.         }
  1098.         if (null !== $jsonManifestPath) {
  1099.             $def = new ChildDefinition('assets.json_manifest_version_strategy');
  1100.             $def->replaceArgument(0$jsonManifestPath);
  1101.             $def->replaceArgument(2$strictMode);
  1102.             $container->setDefinition('assets._version_'.$name$def);
  1103.             return new Reference('assets._version_'.$name);
  1104.         }
  1105.         return new Reference('assets.empty_version_strategy');
  1106.     }
  1107.     private function registerTranslatorConfiguration(array $configContainerBuilder $containerLoaderInterface $loaderstring $defaultLocale, array $enabledLocales)
  1108.     {
  1109.         if (!$this->isConfigEnabled($container$config)) {
  1110.             $container->removeDefinition('console.command.translation_debug');
  1111.             $container->removeDefinition('console.command.translation_extract');
  1112.             $container->removeDefinition('console.command.translation_pull');
  1113.             $container->removeDefinition('console.command.translation_push');
  1114.             return;
  1115.         }
  1116.         $loader->load('translation.php');
  1117.         $loader->load('translation_providers.php');
  1118.         // Use the "real" translator instead of the identity default
  1119.         $container->setAlias('translator''translator.default')->setPublic(true);
  1120.         $container->setAlias('translator.formatter', new Alias($config['formatter'], false));
  1121.         $translator $container->findDefinition('translator.default');
  1122.         $translator->addMethodCall('setFallbackLocales', [$config['fallbacks'] ?: [$defaultLocale]]);
  1123.         $defaultOptions $translator->getArgument(4);
  1124.         $defaultOptions['cache_dir'] = $config['cache_dir'];
  1125.         $translator->setArgument(4$defaultOptions);
  1126.         // @deprecated since Symfony 5.4, in 6.0 change to:
  1127.         // $translator->setArgument(5, $enabledLocales);
  1128.         $translator->setArgument(5$config['enabled_locales'] ?: $enabledLocales);
  1129.         $container->setParameter('translator.logging'$config['logging']);
  1130.         $container->setParameter('translator.default_path'$config['default_path']);
  1131.         // Discover translation directories
  1132.         $dirs = [];
  1133.         $transPaths = [];
  1134.         $nonExistingDirs = [];
  1135.         if (ContainerBuilder::willBeAvailable('symfony/validator'Validation::class, ['symfony/framework-bundle''symfony/translation'], true)) {
  1136.             $r = new \ReflectionClass(Validation::class);
  1137.             $dirs[] = $transPaths[] = \dirname($r->getFileName()).'/Resources/translations';
  1138.         }
  1139.         if (ContainerBuilder::willBeAvailable('symfony/form'Form::class, ['symfony/framework-bundle''symfony/translation'], true)) {
  1140.             $r = new \ReflectionClass(Form::class);
  1141.             $dirs[] = $transPaths[] = \dirname($r->getFileName()).'/Resources/translations';
  1142.         }
  1143.         if (ContainerBuilder::willBeAvailable('symfony/security-core'AuthenticationException::class, ['symfony/framework-bundle''symfony/translation'], true)) {
  1144.             $r = new \ReflectionClass(AuthenticationException::class);
  1145.             $dirs[] = $transPaths[] = \dirname($r->getFileName(), 2).'/Resources/translations';
  1146.         }
  1147.         $defaultDir $container->getParameterBag()->resolveValue($config['default_path']);
  1148.         foreach ($container->getParameter('kernel.bundles_metadata') as $name => $bundle) {
  1149.             if ($container->fileExists($dir $bundle['path'].'/Resources/translations') || $container->fileExists($dir $bundle['path'].'/translations')) {
  1150.                 $dirs[] = $dir;
  1151.             } else {
  1152.                 $nonExistingDirs[] = $dir;
  1153.             }
  1154.         }
  1155.         foreach ($config['paths'] as $dir) {
  1156.             if ($container->fileExists($dir)) {
  1157.                 $dirs[] = $transPaths[] = $dir;
  1158.             } else {
  1159.                 throw new \UnexpectedValueException(sprintf('"%s" defined in translator.paths does not exist or is not a directory.'$dir));
  1160.             }
  1161.         }
  1162.         if ($container->hasDefinition('console.command.translation_debug')) {
  1163.             $container->getDefinition('console.command.translation_debug')->replaceArgument(5$transPaths);
  1164.         }
  1165.         if ($container->hasDefinition('console.command.translation_extract')) {
  1166.             $container->getDefinition('console.command.translation_extract')->replaceArgument(6$transPaths);
  1167.         }
  1168.         if (null === $defaultDir) {
  1169.             // allow null
  1170.         } elseif ($container->fileExists($defaultDir)) {
  1171.             $dirs[] = $defaultDir;
  1172.         } else {
  1173.             $nonExistingDirs[] = $defaultDir;
  1174.         }
  1175.         // Register translation resources
  1176.         if ($dirs) {
  1177.             $files = [];
  1178.             foreach ($dirs as $dir) {
  1179.                 $finder Finder::create()
  1180.                     ->followLinks()
  1181.                     ->files()
  1182.                     ->filter(function (\SplFileInfo $file) {
  1183.                         return <= substr_count($file->getBasename(), '.') && preg_match('/\.\w+$/'$file->getBasename());
  1184.                     })
  1185.                     ->in($dir)
  1186.                     ->sortByName()
  1187.                 ;
  1188.                 foreach ($finder as $file) {
  1189.                     $fileNameParts explode('.'basename($file));
  1190.                     $locale $fileNameParts[\count($fileNameParts) - 2];
  1191.                     if (!isset($files[$locale])) {
  1192.                         $files[$locale] = [];
  1193.                     }
  1194.                     $files[$locale][] = (string) $file;
  1195.                 }
  1196.             }
  1197.             $projectDir $container->getParameter('kernel.project_dir');
  1198.             $options array_merge(
  1199.                 $translator->getArgument(4),
  1200.                 [
  1201.                     'resource_files' => $files,
  1202.                     'scanned_directories' => $scannedDirectories array_merge($dirs$nonExistingDirs),
  1203.                     'cache_vary' => [
  1204.                         'scanned_directories' => array_map(static function (string $dir) use ($projectDir): string {
  1205.                             return str_starts_with($dir$projectDir.'/') ? substr($dir+ \strlen($projectDir)) : $dir;
  1206.                         }, $scannedDirectories),
  1207.                     ],
  1208.                 ]
  1209.             );
  1210.             $translator->replaceArgument(4$options);
  1211.         }
  1212.         if ($config['pseudo_localization']['enabled']) {
  1213.             $options $config['pseudo_localization'];
  1214.             unset($options['enabled']);
  1215.             $container
  1216.                 ->register('translator.pseudo'PseudoLocalizationTranslator::class)
  1217.                 ->setDecoratedService('translator'null, -1// Lower priority than "translator.data_collector"
  1218.                 ->setArguments([
  1219.                     new Reference('translator.pseudo.inner'),
  1220.                     $options,
  1221.                 ]);
  1222.         }
  1223.         $classToServices = [
  1224.             CrowdinProviderFactory::class => 'translation.provider_factory.crowdin',
  1225.             LocoProviderFactory::class => 'translation.provider_factory.loco',
  1226.             LokaliseProviderFactory::class => 'translation.provider_factory.lokalise',
  1227.         ];
  1228.         $parentPackages = ['symfony/framework-bundle''symfony/translation''symfony/http-client'];
  1229.         foreach ($classToServices as $class => $service) {
  1230.             $package substr($service, \strlen('translation.provider_factory.'));
  1231.             if (!$container->hasDefinition('http_client') || !ContainerBuilder::willBeAvailable(sprintf('symfony/%s-translation-provider'$package), $class$parentPackagestrue)) {
  1232.                 $container->removeDefinition($service);
  1233.             }
  1234.         }
  1235.         if (!$config['providers']) {
  1236.             return;
  1237.         }
  1238.         // @deprecated since Symfony 5.4, in 6.0 change to:
  1239.         // $locales = $enabledLocales;
  1240.         $locales $config['enabled_locales'] ?: $enabledLocales;
  1241.         foreach ($config['providers'] as $provider) {
  1242.             if ($provider['locales']) {
  1243.                 $locales += $provider['locales'];
  1244.             }
  1245.         }
  1246.         $locales array_unique($locales);
  1247.         $container->getDefinition('console.command.translation_pull')
  1248.             ->replaceArgument(4array_merge($transPaths, [$config['default_path']]))
  1249.             ->replaceArgument(5$locales)
  1250.         ;
  1251.         $container->getDefinition('console.command.translation_push')
  1252.             ->replaceArgument(2array_merge($transPaths, [$config['default_path']]))
  1253.             ->replaceArgument(3$locales)
  1254.         ;
  1255.         $container->getDefinition('translation.provider_collection_factory')
  1256.             ->replaceArgument(1$locales)
  1257.         ;
  1258.         $container->getDefinition('translation.provider_collection')->setArgument(0$config['providers']);
  1259.     }
  1260.     private function registerValidationConfiguration(array $configContainerBuilder $containerPhpFileLoader $loaderbool $propertyInfoEnabled)
  1261.     {
  1262.         if (!$this->validatorConfigEnabled $this->isConfigEnabled($container$config)) {
  1263.             $container->removeDefinition('console.command.validator_debug');
  1264.             return;
  1265.         }
  1266.         if (!class_exists(Validation::class)) {
  1267.             throw new LogicException('Validation support cannot be enabled as the Validator component is not installed. Try running "composer require symfony/validator".');
  1268.         }
  1269.         if (!isset($config['email_validation_mode'])) {
  1270.             $config['email_validation_mode'] = 'loose';
  1271.         }
  1272.         $loader->load('validator.php');
  1273.         $validatorBuilder $container->getDefinition('validator.builder');
  1274.         $container->setParameter('validator.translation_domain'$config['translation_domain']);
  1275.         $files = ['xml' => [], 'yml' => []];
  1276.         $this->registerValidatorMapping($container$config$files);
  1277.         if (!empty($files['xml'])) {
  1278.             $validatorBuilder->addMethodCall('addXmlMappings', [$files['xml']]);
  1279.         }
  1280.         if (!empty($files['yml'])) {
  1281.             $validatorBuilder->addMethodCall('addYamlMappings', [$files['yml']]);
  1282.         }
  1283.         $definition $container->findDefinition('validator.email');
  1284.         $definition->replaceArgument(0$config['email_validation_mode']);
  1285.         if (\array_key_exists('enable_annotations'$config) && $config['enable_annotations']) {
  1286.             if (!$this->annotationsConfigEnabled && \PHP_VERSION_ID 80000) {
  1287.                 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.');
  1288.             }
  1289.             $validatorBuilder->addMethodCall('enableAnnotationMapping', [true]);
  1290.             if ($this->annotationsConfigEnabled) {
  1291.                 $validatorBuilder->addMethodCall('setDoctrineAnnotationReader', [new Reference('annotation_reader')]);
  1292.             }
  1293.         }
  1294.         if (\array_key_exists('static_method'$config) && $config['static_method']) {
  1295.             foreach ($config['static_method'] as $methodName) {
  1296.                 $validatorBuilder->addMethodCall('addMethodMapping', [$methodName]);
  1297.             }
  1298.         }
  1299.         if (!$container->getParameter('kernel.debug')) {
  1300.             $validatorBuilder->addMethodCall('setMappingCache', [new Reference('validator.mapping.cache.adapter')]);
  1301.         }
  1302.         $container->setParameter('validator.auto_mapping'$config['auto_mapping']);
  1303.         if (!$propertyInfoEnabled || !class_exists(PropertyInfoLoader::class)) {
  1304.             $container->removeDefinition('validator.property_info_loader');
  1305.         }
  1306.         $container
  1307.             ->getDefinition('validator.not_compromised_password')
  1308.             ->setArgument(2$config['not_compromised_password']['enabled'])
  1309.             ->setArgument(3$config['not_compromised_password']['endpoint'])
  1310.         ;
  1311.         if (!class_exists(ExpressionLanguage::class)) {
  1312.             $container->removeDefinition('validator.expression_language');
  1313.         }
  1314.     }
  1315.     private function registerValidatorMapping(ContainerBuilder $container, array $config, array &$files)
  1316.     {
  1317.         $fileRecorder = function ($extension$path) use (&$files) {
  1318.             $files['yaml' === $extension 'yml' $extension][] = $path;
  1319.         };
  1320.         if (ContainerBuilder::willBeAvailable('symfony/form'Form::class, ['symfony/framework-bundle''symfony/validator'], true)) {
  1321.             $reflClass = new \ReflectionClass(Form::class);
  1322.             $fileRecorder('xml', \dirname($reflClass->getFileName()).'/Resources/config/validation.xml');
  1323.         }
  1324.         foreach ($container->getParameter('kernel.bundles_metadata') as $bundle) {
  1325.             $configDir is_dir($bundle['path'].'/Resources/config') ? $bundle['path'].'/Resources/config' $bundle['path'].'/config';
  1326.             if (
  1327.                 $container->fileExists($file $configDir.'/validation.yaml'false) ||
  1328.                 $container->fileExists($file $configDir.'/validation.yml'false)
  1329.             ) {
  1330.                 $fileRecorder('yml'$file);
  1331.             }
  1332.             if ($container->fileExists($file $configDir.'/validation.xml'false)) {
  1333.                 $fileRecorder('xml'$file);
  1334.             }
  1335.             if ($container->fileExists($dir $configDir.'/validation''/^$/')) {
  1336.                 $this->registerMappingFilesFromDir($dir$fileRecorder);
  1337.             }
  1338.         }
  1339.         $projectDir $container->getParameter('kernel.project_dir');
  1340.         if ($container->fileExists($dir $projectDir.'/config/validator''/^$/')) {
  1341.             $this->registerMappingFilesFromDir($dir$fileRecorder);
  1342.         }
  1343.         $this->registerMappingFilesFromConfig($container$config$fileRecorder);
  1344.     }
  1345.     private function registerMappingFilesFromDir(string $dir, callable $fileRecorder)
  1346.     {
  1347.         foreach (Finder::create()->followLinks()->files()->in($dir)->name('/\.(xml|ya?ml)$/')->sortByName() as $file) {
  1348.             $fileRecorder($file->getExtension(), $file->getRealPath());
  1349.         }
  1350.     }
  1351.     private function registerMappingFilesFromConfig(ContainerBuilder $container, array $config, callable $fileRecorder)
  1352.     {
  1353.         foreach ($config['mapping']['paths'] as $path) {
  1354.             if (is_dir($path)) {
  1355.                 $this->registerMappingFilesFromDir($path$fileRecorder);
  1356.                 $container->addResource(new DirectoryResource($path'/^$/'));
  1357.             } elseif ($container->fileExists($pathfalse)) {
  1358.                 if (!preg_match('/\.(xml|ya?ml)$/'$path$matches)) {
  1359.                     throw new \RuntimeException(sprintf('Unsupported mapping type in "%s", supported types are XML & Yaml.'$path));
  1360.                 }
  1361.                 $fileRecorder($matches[1], $path);
  1362.             } else {
  1363.                 throw new \RuntimeException(sprintf('Could not open file or directory "%s".'$path));
  1364.             }
  1365.         }
  1366.     }
  1367.     private function registerAnnotationsConfiguration(array $configContainerBuilder $containerLoaderInterface $loader)
  1368.     {
  1369.         if (!$this->annotationsConfigEnabled) {
  1370.             return;
  1371.         }
  1372.         if (!class_exists(\Doctrine\Common\Annotations\Annotation::class)) {
  1373.             throw new LogicException('Annotations cannot be enabled as the Doctrine Annotation library is not installed. Try running "composer require doctrine/annotations".');
  1374.         }
  1375.         $loader->load('annotations.php');
  1376.         if (!method_exists(AnnotationRegistry::class, 'registerUniqueLoader')) {
  1377.             $container->getDefinition('annotations.dummy_registry')
  1378.                 ->setMethodCalls([['registerLoader', ['class_exists']]]);
  1379.         }
  1380.         if ('none' === $config['cache']) {
  1381.             $container->removeDefinition('annotations.cached_reader');
  1382.             return;
  1383.         }
  1384.         $cacheService $config['cache'];
  1385.         if (\in_array($config['cache'], ['php_array''file'])) {
  1386.             if ('php_array' === $config['cache']) {
  1387.                 $cacheService 'annotations.cache_adapter';
  1388.                 // Enable warmer only if PHP array is used for cache
  1389.                 $definition $container->findDefinition('annotations.cache_warmer');
  1390.                 $definition->addTag('kernel.cache_warmer');
  1391.             } elseif ('file' === $config['cache']) {
  1392.                 $cacheService 'annotations.filesystem_cache_adapter';
  1393.                 $cacheDir $container->getParameterBag()->resolveValue($config['file_cache_dir']);
  1394.                 if (!is_dir($cacheDir) && false === @mkdir($cacheDir0777true) && !is_dir($cacheDir)) {
  1395.                     throw new \RuntimeException(sprintf('Could not create cache directory "%s".'$cacheDir));
  1396.                 }
  1397.                 $container
  1398.                     ->getDefinition('annotations.filesystem_cache_adapter')
  1399.                     ->replaceArgument(2$cacheDir)
  1400.                 ;
  1401.             }
  1402.         } else {
  1403.             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.');
  1404.         }
  1405.         $container
  1406.             ->getDefinition('annotations.cached_reader')
  1407.             ->setPublic(true// set to false in AddAnnotationsCachedReaderPass
  1408.             ->replaceArgument(2$config['debug'])
  1409.             // reference the cache provider without using it until AddAnnotationsCachedReaderPass runs
  1410.             ->addArgument(new ServiceClosureArgument(new Reference($cacheService)))
  1411.             ->addTag('annotations.cached_reader')
  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 $storeDsn) {
  1597.                 $storeDsn $container->resolveEnvPlaceholders($storeDsnnull$usedEnvs);
  1598.                 $storeDefinition = new Definition(interface_exists(StoreInterface::class) ? StoreInterface::class : PersistingStoreInterface::class);
  1599.                 $storeDefinition->setFactory([StoreFactory::class, 'createStore']);
  1600.                 $storeDefinition->setArguments([$storeDsn]);
  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.             PostmarkTransportFactory::class => 'mailer.transport_factory.postmark',
  2053.             SendgridTransportFactory::class => 'mailer.transport_factory.sendgrid',
  2054.             SendinblueTransportFactory::class => 'mailer.transport_factory.sendinblue',
  2055.             SesTransportFactory::class => 'mailer.transport_factory.amazon',
  2056.             OhMySmtpTransportFactory::class => 'mailer.transport_factory.ohmysmtp',
  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. }