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

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