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

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