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

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