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

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