vendor/symfony/framework-bundle/DependencyInjection/Configuration.php line 62

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\Annotation;
  12. use Doctrine\DBAL\Connection;
  13. use Psr\Log\LogLevel;
  14. use Symfony\Bundle\FullStack;
  15. use Symfony\Component\Asset\Package;
  16. use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
  17. use Symfony\Component\Config\Definition\Builder\NodeBuilder;
  18. use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  19. use Symfony\Component\Config\Definition\ConfigurationInterface;
  20. use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
  21. use Symfony\Component\DependencyInjection\ContainerBuilder;
  22. use Symfony\Component\DependencyInjection\Exception\LogicException;
  23. use Symfony\Component\Form\Form;
  24. use Symfony\Component\HttpClient\HttpClient;
  25. use Symfony\Component\HttpFoundation\Cookie;
  26. use Symfony\Component\Lock\Lock;
  27. use Symfony\Component\Lock\Store\SemaphoreStore;
  28. use Symfony\Component\Mailer\Mailer;
  29. use Symfony\Component\Messenger\MessageBusInterface;
  30. use Symfony\Component\Notifier\Notifier;
  31. use Symfony\Component\PropertyAccess\PropertyAccessor;
  32. use Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface;
  33. use Symfony\Component\RateLimiter\Policy\TokenBucketLimiter;
  34. use Symfony\Component\Serializer\Serializer;
  35. use Symfony\Component\Translation\Translator;
  36. use Symfony\Component\Uid\Factory\UuidFactory;
  37. use Symfony\Component\Validator\Validation;
  38. use Symfony\Component\WebLink\HttpHeaderSerializer;
  39. use Symfony\Component\Workflow\WorkflowEvents;
  40. /**
  41.  * FrameworkExtension configuration structure.
  42.  */
  43. class Configuration implements ConfigurationInterface
  44. {
  45.     private bool $debug;
  46.     /**
  47.      * @param bool $debug Whether debugging is enabled or not
  48.      */
  49.     public function __construct(bool $debug)
  50.     {
  51.         $this->debug = $debug;
  52.     }
  53.     /**
  54.      * Generates the configuration tree builder.
  55.      */
  56.     public function getConfigTreeBuilder(): TreeBuilder
  57.     {
  58.         $treeBuilder = new TreeBuilder('framework');
  59.         $rootNode = $treeBuilder->getRootNode();
  60.         $rootNode
  61.             ->beforeNormalization()
  62.                 ->ifTrue(function ($v) { return !isset($v['assets']) && isset($v['templating']) && class_exists(Package::class); })
  63.                 ->then(function ($v) {
  64.                     $v['assets'] = [];
  65.                     return $v;
  66.                 })
  67.             ->end()
  68.             ->fixXmlConfig('enabled_locale')
  69.             ->children()
  70.                 ->scalarNode('secret')->end()
  71.                 ->scalarNode('http_method_override')
  72.                     ->info("Set true to enable support for the '_method' request parameter to determine the intended HTTP method on POST requests. Note: When using the HttpCache, you need to call the method in your front controller instead")
  73.                     ->defaultTrue()
  74.                 ->end()
  75.                 ->scalarNode('ide')->defaultNull()->end()
  76.                 ->booleanNode('test')->end()
  77.                 ->scalarNode('default_locale')->defaultValue('en')->end()
  78.                 ->booleanNode('set_locale_from_accept_language')
  79.                     ->info('Whether to use the Accept-Language HTTP header to set the Request locale (only when the "_locale" request attribute is not passed).')
  80.                     ->defaultFalse()
  81.                 ->end()
  82.                 ->booleanNode('set_content_language_from_locale')
  83.                     ->info('Whether to set the Content-Language HTTP header on the Response using the Request locale.')
  84.                     ->defaultFalse()
  85.                 ->end()
  86.                 ->arrayNode('enabled_locales')
  87.                     ->info('Defines the possible locales for the application. This list is used for generating translations files, but also to restrict which locales are allowed when it is set from Accept-Language header (using "set_locale_from_accept_language").')
  88.                     ->prototype('scalar')->end()
  89.                 ->end()
  90.                 ->arrayNode('trusted_hosts')
  91.                     ->beforeNormalization()->ifString()->then(function ($v) { return [$v]; })->end()
  92.                     ->prototype('scalar')->end()
  93.                 ->end()
  94.                 ->scalarNode('trusted_proxies')->end()
  95.                 ->arrayNode('trusted_headers')
  96.                     ->fixXmlConfig('trusted_header')
  97.                     ->performNoDeepMerging()
  98.                     ->defaultValue(['x-forwarded-for', 'x-forwarded-port', 'x-forwarded-proto'])
  99.                     ->beforeNormalization()->ifString()->then(function ($v) { return $v ? array_map('trim', explode(',', $v)) : []; })->end()
  100.                     ->enumPrototype()
  101.                         ->values([
  102.                             'forwarded',
  103.                             'x-forwarded-for', 'x-forwarded-host', 'x-forwarded-proto', 'x-forwarded-port', 'x-forwarded-prefix',
  104.                         ])
  105.                     ->end()
  106.                 ->end()
  107.                 ->scalarNode('error_controller')
  108.                     ->defaultValue('error_controller')
  109.                 ->end()
  110.             ->end()
  111.         ;
  112.         $willBeAvailable = static function (string $package, string $class, string $parentPackage = null) {
  113.             $parentPackages = (array) $parentPackage;
  114.             $parentPackages[] = 'symfony/framework-bundle';
  115.             return ContainerBuilder::willBeAvailable($package, $class, $parentPackages);
  116.         };
  117.         $enableIfStandalone = static function (string $package, string $class) use ($willBeAvailable) {
  118.             return !class_exists(FullStack::class) && $willBeAvailable($package, $class) ? 'canBeDisabled' : 'canBeEnabled';
  119.         };
  120.         $this->addCsrfSection($rootNode);
  121.         $this->addFormSection($rootNode, $enableIfStandalone);
  122.         $this->addHttpCacheSection($rootNode);
  123.         $this->addEsiSection($rootNode);
  124.         $this->addSsiSection($rootNode);
  125.         $this->addFragmentsSection($rootNode);
  126.         $this->addProfilerSection($rootNode);
  127.         $this->addWorkflowSection($rootNode);
  128.         $this->addRouterSection($rootNode);
  129.         $this->addSessionSection($rootNode);
  130.         $this->addRequestSection($rootNode);
  131.         $this->addAssetsSection($rootNode, $enableIfStandalone);
  132.         $this->addTranslatorSection($rootNode, $enableIfStandalone);
  133.         $this->addValidationSection($rootNode, $enableIfStandalone, $willBeAvailable);
  134.         $this->addAnnotationsSection($rootNode, $willBeAvailable);
  135.         $this->addSerializerSection($rootNode, $enableIfStandalone, $willBeAvailable);
  136.         $this->addPropertyAccessSection($rootNode, $willBeAvailable);
  137.         $this->addPropertyInfoSection($rootNode, $enableIfStandalone);
  138.         $this->addCacheSection($rootNode, $willBeAvailable);
  139.         $this->addPhpErrorsSection($rootNode);
  140.         $this->addExceptionsSection($rootNode);
  141.         $this->addWebLinkSection($rootNode, $enableIfStandalone);
  142.         $this->addLockSection($rootNode, $enableIfStandalone);
  143.         $this->addMessengerSection($rootNode, $enableIfStandalone);
  144.         $this->addRobotsIndexSection($rootNode);
  145.         $this->addHttpClientSection($rootNode, $enableIfStandalone);
  146.         $this->addMailerSection($rootNode, $enableIfStandalone);
  147.         $this->addSecretsSection($rootNode);
  148.         $this->addNotifierSection($rootNode, $enableIfStandalone);
  149.         $this->addRateLimiterSection($rootNode, $enableIfStandalone);
  150.         $this->addUidSection($rootNode, $enableIfStandalone);
  151.         return $treeBuilder;
  152.     }
  153.     private function addSecretsSection(ArrayNodeDefinition $rootNode)
  154.     {
  155.         $rootNode
  156.             ->children()
  157.                 ->arrayNode('secrets')
  158.                     ->canBeDisabled()
  159.                     ->children()
  160.                         ->scalarNode('vault_directory')->defaultValue('%kernel.project_dir%/config/secrets/%kernel.runtime_environment%')->cannotBeEmpty()->end()
  161.                         ->scalarNode('local_dotenv_file')->defaultValue('%kernel.project_dir%/.env.%kernel.environment%.local')->end()
  162.                         ->scalarNode('decryption_env_var')->defaultValue('base64:default::SYMFONY_DECRYPTION_SECRET')->end()
  163.                     ->end()
  164.                 ->end()
  165.             ->end()
  166.         ;
  167.     }
  168.     private function addCsrfSection(ArrayNodeDefinition $rootNode)
  169.     {
  170.         $rootNode
  171.             ->children()
  172.                 ->arrayNode('csrf_protection')
  173.                     ->treatFalseLike(['enabled' => false])
  174.                     ->treatTrueLike(['enabled' => true])
  175.                     ->treatNullLike(['enabled' => true])
  176.                     ->addDefaultsIfNotSet()
  177.                     ->children()
  178.                         // defaults to framework.session.enabled && !class_exists(FullStack::class) && interface_exists(CsrfTokenManagerInterface::class)
  179.                         ->booleanNode('enabled')->defaultNull()->end()
  180.                     ->end()
  181.                 ->end()
  182.             ->end()
  183.         ;
  184.     }
  185.     private function addFormSection(ArrayNodeDefinition $rootNode, callable $enableIfStandalone)
  186.     {
  187.         $rootNode
  188.             ->children()
  189.                 ->arrayNode('form')
  190.                     ->info('form configuration')
  191.                     ->{$enableIfStandalone('symfony/form', Form::class)}()
  192.                     ->children()
  193.                         ->arrayNode('csrf_protection')
  194.                             ->treatFalseLike(['enabled' => false])
  195.                             ->treatTrueLike(['enabled' => true])
  196.                             ->treatNullLike(['enabled' => true])
  197.                             ->addDefaultsIfNotSet()
  198.                             ->children()
  199.                                 ->booleanNode('enabled')->defaultNull()->end() // defaults to framework.csrf_protection.enabled
  200.                                 ->scalarNode('field_name')->defaultValue('_token')->end()
  201.                             ->end()
  202.                         ->end()
  203.                         // to be deprecated in Symfony 6.1
  204.                         ->booleanNode('legacy_error_messages')->end()
  205.                     ->end()
  206.                 ->end()
  207.             ->end()
  208.         ;
  209.     }
  210.     private function addHttpCacheSection(ArrayNodeDefinition $rootNode)
  211.     {
  212.         $rootNode
  213.             ->children()
  214.                 ->arrayNode('http_cache')
  215.                     ->info('HTTP cache configuration')
  216.                     ->canBeEnabled()
  217.                     ->fixXmlConfig('private_header')
  218.                     ->children()
  219.                         ->booleanNode('debug')->defaultValue('%kernel.debug%')->end()
  220.                         ->enumNode('trace_level')
  221.                             ->values(['none', 'short', 'full'])
  222.                         ->end()
  223.                         ->scalarNode('trace_header')->end()
  224.                         ->integerNode('default_ttl')->end()
  225.                         ->arrayNode('private_headers')
  226.                             ->performNoDeepMerging()
  227.                             ->scalarPrototype()->end()
  228.                         ->end()
  229.                         ->booleanNode('allow_reload')->end()
  230.                         ->booleanNode('allow_revalidate')->end()
  231.                         ->integerNode('stale_while_revalidate')->end()
  232.                         ->integerNode('stale_if_error')->end()
  233.                     ->end()
  234.                 ->end()
  235.             ->end()
  236.         ;
  237.     }
  238.     private function addEsiSection(ArrayNodeDefinition $rootNode)
  239.     {
  240.         $rootNode
  241.             ->children()
  242.                 ->arrayNode('esi')
  243.                     ->info('esi configuration')
  244.                     ->canBeEnabled()
  245.                 ->end()
  246.             ->end()
  247.         ;
  248.     }
  249.     private function addSsiSection(ArrayNodeDefinition $rootNode)
  250.     {
  251.         $rootNode
  252.             ->children()
  253.                 ->arrayNode('ssi')
  254.                     ->info('ssi configuration')
  255.                     ->canBeEnabled()
  256.                 ->end()
  257.             ->end();
  258.     }
  259.     private function addFragmentsSection(ArrayNodeDefinition $rootNode)
  260.     {
  261.         $rootNode
  262.             ->children()
  263.                 ->arrayNode('fragments')
  264.                     ->info('fragments configuration')
  265.                     ->canBeEnabled()
  266.                     ->children()
  267.                         ->scalarNode('hinclude_default_template')->defaultNull()->end()
  268.                         ->scalarNode('path')->defaultValue('/_fragment')->end()
  269.                     ->end()
  270.                 ->end()
  271.             ->end()
  272.         ;
  273.     }
  274.     private function addProfilerSection(ArrayNodeDefinition $rootNode)
  275.     {
  276.         $rootNode
  277.             ->children()
  278.                 ->arrayNode('profiler')
  279.                     ->info('profiler configuration')
  280.                     ->canBeEnabled()
  281.                     ->children()
  282.                         ->booleanNode('collect')->defaultTrue()->end()
  283.                         ->scalarNode('collect_parameter')->defaultNull()->info('The name of the parameter to use to enable or disable collection on a per request basis')->end()
  284.                         ->booleanNode('only_exceptions')->defaultFalse()->end()
  285.                         ->booleanNode('only_main_requests')->defaultFalse()->end()
  286.                         ->scalarNode('dsn')->defaultValue('file:%kernel.cache_dir%/profiler')->end()
  287.                     ->end()
  288.                 ->end()
  289.             ->end()
  290.         ;
  291.     }
  292.     private function addWorkflowSection(ArrayNodeDefinition $rootNode)
  293.     {
  294.         $rootNode
  295.             ->fixXmlConfig('workflow')
  296.             ->children()
  297.                 ->arrayNode('workflows')
  298.                     ->canBeEnabled()
  299.                     ->beforeNormalization()
  300.                         ->always(function ($v) {
  301.                             if (\is_array($v) && true === $v['enabled']) {
  302.                                 $workflows = $v;
  303.                                 unset($workflows['enabled']);
  304.                                 if (1 === \count($workflows) && isset($workflows[0]['enabled']) && 1 === \count($workflows[0])) {
  305.                                     $workflows = [];
  306.                                 }
  307.                                 if (1 === \count($workflows) && isset($workflows['workflows']) && !array_is_list($workflows['workflows']) && !empty(array_diff(array_keys($workflows['workflows']), ['audit_trail', 'type', 'marking_store', 'supports', 'support_strategy', 'initial_marking', 'places', 'transitions']))) {
  308.                                     $workflows = $workflows['workflows'];
  309.                                 }
  310.                                 foreach ($workflows as $key => $workflow) {
  311.                                     if (isset($workflow['enabled']) && false === $workflow['enabled']) {
  312.                                         throw new LogicException(sprintf('Cannot disable a single workflow. Remove the configuration for the workflow "%s" instead.', $workflow['name']));
  313.                                     }
  314.                                     unset($workflows[$key]['enabled']);
  315.                                 }
  316.                                 $v = [
  317.                                     'enabled' => true,
  318.                                     'workflows' => $workflows,
  319.                                 ];
  320.                             }
  321.                             return $v;
  322.                         })
  323.                     ->end()
  324.                     ->children()
  325.                         ->arrayNode('workflows')
  326.                             ->useAttributeAsKey('name')
  327.                             ->prototype('array')
  328.                                 ->fixXmlConfig('support')
  329.                                 ->fixXmlConfig('place')
  330.                                 ->fixXmlConfig('transition')
  331.                                 ->fixXmlConfig('event_to_dispatch', 'events_to_dispatch')
  332.                                 ->children()
  333.                                     ->arrayNode('audit_trail')
  334.                                         ->canBeEnabled()
  335.                                     ->end()
  336.                                     ->enumNode('type')
  337.                                         ->values(['workflow', 'state_machine'])
  338.                                         ->defaultValue('state_machine')
  339.                                     ->end()
  340.                                     ->arrayNode('marking_store')
  341.                                         ->children()
  342.                                             ->enumNode('type')
  343.                                                 ->values(['method'])
  344.                                             ->end()
  345.                                             ->scalarNode('property')
  346.                                                 ->defaultValue('marking')
  347.                                             ->end()
  348.                                             ->scalarNode('service')
  349.                                                 ->cannotBeEmpty()
  350.                                             ->end()
  351.                                         ->end()
  352.                                     ->end()
  353.                                     ->arrayNode('supports')
  354.                                         ->beforeNormalization()
  355.                                             ->ifString()
  356.                                             ->then(function ($v) { return [$v]; })
  357.                                         ->end()
  358.                                         ->prototype('scalar')
  359.                                             ->cannotBeEmpty()
  360.                                             ->validate()
  361.                                                 ->ifTrue(function ($v) { return !class_exists($v) && !interface_exists($v, false); })
  362.                                                 ->thenInvalid('The supported class or interface "%s" does not exist.')
  363.                                             ->end()
  364.                                         ->end()
  365.                                     ->end()
  366.                                     ->scalarNode('support_strategy')
  367.                                         ->cannotBeEmpty()
  368.                                     ->end()
  369.                                     ->arrayNode('initial_marking')
  370.                                         ->beforeNormalization()->castToArray()->end()
  371.                                         ->defaultValue([])
  372.                                         ->prototype('scalar')->end()
  373.                                     ->end()
  374.                                     ->variableNode('events_to_dispatch')
  375.                                         ->defaultValue(null)
  376.                                         ->validate()
  377.                                             ->ifTrue(function ($v) {
  378.                                                 if (null === $v) {
  379.                                                     return false;
  380.                                                 }
  381.                                                 if (!\is_array($v)) {
  382.                                                     return true;
  383.                                                 }
  384.                                                 foreach ($v as $value) {
  385.                                                     if (!\is_string($value)) {
  386.                                                         return true;
  387.                                                     }
  388.                                                     if (class_exists(WorkflowEvents::class) && !\in_array($value, WorkflowEvents::ALIASES)) {
  389.                                                         return true;
  390.                                                     }
  391.                                                 }
  392.                                                 return false;
  393.                                             })
  394.                                             ->thenInvalid('The value must be "null" or an array of workflow events (like ["workflow.enter"]).')
  395.                                         ->end()
  396.                                         ->info('Select which Transition events should be dispatched for this Workflow')
  397.                                         ->example(['workflow.enter', 'workflow.transition'])
  398.                                     ->end()
  399.                                     ->arrayNode('places')
  400.                                         ->beforeNormalization()
  401.                                             ->always()
  402.                                             ->then(function ($places) {
  403.                                                 // It's an indexed array of shape  ['place1', 'place2']
  404.                                                 if (isset($places[0]) && \is_string($places[0])) {
  405.                                                     return array_map(function (string $place) {
  406.                                                         return ['name' => $place];
  407.                                                     }, $places);
  408.                                                 }
  409.                                                 // It's an indexed array, we let the validation occur
  410.                                                 if (isset($places[0]) && \is_array($places[0])) {
  411.                                                     return $places;
  412.                                                 }
  413.                                                 foreach ($places as $name => $place) {
  414.                                                     if (\is_array($place) && \array_key_exists('name', $place)) {
  415.                                                         continue;
  416.                                                     }
  417.                                                     $place['name'] = $name;
  418.                                                     $places[$name] = $place;
  419.                                                 }
  420.                                                 return array_values($places);
  421.                                             })
  422.                                         ->end()
  423.                                         ->isRequired()
  424.                                         ->requiresAtLeastOneElement()
  425.                                         ->prototype('array')
  426.                                             ->children()
  427.                                                 ->scalarNode('name')
  428.                                                     ->isRequired()
  429.                                                     ->cannotBeEmpty()
  430.                                                 ->end()
  431.                                                 ->arrayNode('metadata')
  432.                                                     ->normalizeKeys(false)
  433.                                                     ->defaultValue([])
  434.                                                     ->example(['color' => 'blue', 'description' => 'Workflow to manage article.'])
  435.                                                     ->prototype('variable')
  436.                                                     ->end()
  437.                                                 ->end()
  438.                                             ->end()
  439.                                         ->end()
  440.                                     ->end()
  441.                                     ->arrayNode('transitions')
  442.                                         ->beforeNormalization()
  443.                                             ->always()
  444.                                             ->then(function ($transitions) {
  445.                                                 // It's an indexed array, we let the validation occur
  446.                                                 if (isset($transitions[0]) && \is_array($transitions[0])) {
  447.                                                     return $transitions;
  448.                                                 }
  449.                                                 foreach ($transitions as $name => $transition) {
  450.                                                     if (\is_array($transition) && \array_key_exists('name', $transition)) {
  451.                                                         continue;
  452.                                                     }
  453.                                                     $transition['name'] = $name;
  454.                                                     $transitions[$name] = $transition;
  455.                                                 }
  456.                                                 return $transitions;
  457.                                             })
  458.                                         ->end()
  459.                                         ->isRequired()
  460.                                         ->requiresAtLeastOneElement()
  461.                                         ->prototype('array')
  462.                                             ->children()
  463.                                                 ->scalarNode('name')
  464.                                                     ->isRequired()
  465.                                                     ->cannotBeEmpty()
  466.                                                 ->end()
  467.                                                 ->scalarNode('guard')
  468.                                                     ->cannotBeEmpty()
  469.                                                     ->info('An expression to block the transition')
  470.                                                     ->example('is_fully_authenticated() and is_granted(\'ROLE_JOURNALIST\') and subject.getTitle() == \'My first article\'')
  471.                                                 ->end()
  472.                                                 ->arrayNode('from')
  473.                                                     ->beforeNormalization()
  474.                                                         ->ifString()
  475.                                                         ->then(function ($v) { return [$v]; })
  476.                                                     ->end()
  477.                                                     ->requiresAtLeastOneElement()
  478.                                                     ->prototype('scalar')
  479.                                                         ->cannotBeEmpty()
  480.                                                     ->end()
  481.                                                 ->end()
  482.                                                 ->arrayNode('to')
  483.                                                     ->beforeNormalization()
  484.                                                         ->ifString()
  485.                                                         ->then(function ($v) { return [$v]; })
  486.                                                     ->end()
  487.                                                     ->requiresAtLeastOneElement()
  488.                                                     ->prototype('scalar')
  489.                                                         ->cannotBeEmpty()
  490.                                                     ->end()
  491.                                                 ->end()
  492.                                                 ->arrayNode('metadata')
  493.                                                     ->normalizeKeys(false)
  494.                                                     ->defaultValue([])
  495.                                                     ->example(['color' => 'blue', 'description' => 'Workflow to manage article.'])
  496.                                                     ->prototype('variable')
  497.                                                     ->end()
  498.                                                 ->end()
  499.                                             ->end()
  500.                                         ->end()
  501.                                     ->end()
  502.                                     ->arrayNode('metadata')
  503.                                         ->normalizeKeys(false)
  504.                                         ->defaultValue([])
  505.                                         ->example(['color' => 'blue', 'description' => 'Workflow to manage article.'])
  506.                                         ->prototype('variable')
  507.                                         ->end()
  508.                                     ->end()
  509.                                 ->end()
  510.                                 ->validate()
  511.                                     ->ifTrue(function ($v) {
  512.                                         return $v['supports'] && isset($v['support_strategy']);
  513.                                     })
  514.                                     ->thenInvalid('"supports" and "support_strategy" cannot be used together.')
  515.                                 ->end()
  516.                                 ->validate()
  517.                                     ->ifTrue(function ($v) {
  518.                                         return !$v['supports'] && !isset($v['support_strategy']);
  519.                                     })
  520.                                     ->thenInvalid('"supports" or "support_strategy" should be configured.')
  521.                                 ->end()
  522.                                 ->beforeNormalization()
  523.                                         ->always()
  524.                                         ->then(function ($values) {
  525.                                             // Special case to deal with XML when the user wants an empty array
  526.                                             if (\array_key_exists('event_to_dispatch', $values) && null === $values['event_to_dispatch']) {
  527.                                                 $values['events_to_dispatch'] = [];
  528.                                                 unset($values['event_to_dispatch']);
  529.                                             }
  530.                                             return $values;
  531.                                         })
  532.                                 ->end()
  533.                             ->end()
  534.                         ->end()
  535.                     ->end()
  536.                 ->end()
  537.             ->end()
  538.         ;
  539.     }
  540.     private function addRouterSection(ArrayNodeDefinition $rootNode)
  541.     {
  542.         $rootNode
  543.             ->children()
  544.                 ->arrayNode('router')
  545.                     ->info('router configuration')
  546.                     ->canBeEnabled()
  547.                     ->children()
  548.                         ->scalarNode('resource')->isRequired()->end()
  549.                         ->scalarNode('type')->end()
  550.                         ->scalarNode('default_uri')
  551.                             ->info('The default URI used to generate URLs in a non-HTTP context')
  552.                             ->defaultNull()
  553.                         ->end()
  554.                         ->scalarNode('http_port')->defaultValue(80)->end()
  555.                         ->scalarNode('https_port')->defaultValue(443)->end()
  556.                         ->scalarNode('strict_requirements')
  557.                             ->info(
  558.                                 "set to true to throw an exception when a parameter does not match the requirements\n".
  559.                                 "set to false to disable exceptions when a parameter does not match the requirements (and return null instead)\n".
  560.                                 "set to null to disable parameter checks against requirements\n".
  561.                                 "'true' is the preferred configuration in development mode, while 'false' or 'null' might be preferred in production"
  562.                             )
  563.                             ->defaultTrue()
  564.                         ->end()
  565.                         ->booleanNode('utf8')->defaultTrue()->end()
  566.                     ->end()
  567.                 ->end()
  568.             ->end()
  569.         ;
  570.     }
  571.     private function addSessionSection(ArrayNodeDefinition $rootNode)
  572.     {
  573.         $rootNode
  574.             ->children()
  575.                 ->arrayNode('session')
  576.                     ->info('session configuration')
  577.                     ->canBeEnabled()
  578.                     ->children()
  579.                         ->scalarNode('storage_factory_id')->defaultValue('session.storage.factory.native')->end()
  580.                         ->scalarNode('handler_id')->defaultValue('session.handler.native_file')->end()
  581.                         ->scalarNode('name')
  582.                             ->validate()
  583.                                 ->ifTrue(function ($v) {
  584.                                     parse_str($v, $parsed);
  585.                                     return implode('&', array_keys($parsed)) !== (string) $v;
  586.                                 })
  587.                                 ->thenInvalid('Session name %s contains illegal character(s)')
  588.                             ->end()
  589.                         ->end()
  590.                         ->scalarNode('cookie_lifetime')->end()
  591.                         ->scalarNode('cookie_path')->end()
  592.                         ->scalarNode('cookie_domain')->end()
  593.                         ->enumNode('cookie_secure')->values([true, false, 'auto'])->end()
  594.                         ->booleanNode('cookie_httponly')->defaultTrue()->end()
  595.                         ->enumNode('cookie_samesite')->values([null, Cookie::SAMESITE_LAX, Cookie::SAMESITE_STRICT, Cookie::SAMESITE_NONE])->defaultNull()->end()
  596.                         ->booleanNode('use_cookies')->end()
  597.                         ->scalarNode('gc_divisor')->end()
  598.                         ->scalarNode('gc_probability')->defaultValue(1)->end()
  599.                         ->scalarNode('gc_maxlifetime')->end()
  600.                         ->scalarNode('save_path')->defaultValue('%kernel.cache_dir%/sessions')->end()
  601.                         ->integerNode('metadata_update_threshold')
  602.                             ->defaultValue(0)
  603.                             ->info('seconds to wait between 2 session metadata updates')
  604.                         ->end()
  605.                         ->integerNode('sid_length')
  606.                             ->min(22)
  607.                             ->max(256)
  608.                         ->end()
  609.                         ->integerNode('sid_bits_per_character')
  610.                             ->min(4)
  611.                             ->max(6)
  612.                         ->end()
  613.                     ->end()
  614.                 ->end()
  615.             ->end()
  616.         ;
  617.     }
  618.     private function addRequestSection(ArrayNodeDefinition $rootNode)
  619.     {
  620.         $rootNode
  621.             ->children()
  622.                 ->arrayNode('request')
  623.                     ->info('request configuration')
  624.                     ->canBeEnabled()
  625.                     ->fixXmlConfig('format')
  626.                     ->children()
  627.                         ->arrayNode('formats')
  628.                             ->useAttributeAsKey('name')
  629.                             ->prototype('array')
  630.                                 ->beforeNormalization()
  631.                                     ->ifTrue(function ($v) { return \is_array($v) && isset($v['mime_type']); })
  632.                                     ->then(function ($v) { return $v['mime_type']; })
  633.                                 ->end()
  634.                                 ->beforeNormalization()->castToArray()->end()
  635.                                 ->prototype('scalar')->end()
  636.                             ->end()
  637.                         ->end()
  638.                     ->end()
  639.                 ->end()
  640.             ->end()
  641.         ;
  642.     }
  643.     private function addAssetsSection(ArrayNodeDefinition $rootNode, callable $enableIfStandalone)
  644.     {
  645.         $rootNode
  646.             ->children()
  647.                 ->arrayNode('assets')
  648.                     ->info('assets configuration')
  649.                     ->{$enableIfStandalone('symfony/asset', Package::class)}()
  650.                     ->fixXmlConfig('base_url')
  651.                     ->children()
  652.                         ->booleanNode('strict_mode')
  653.                             ->info('Throw an exception if an entry is missing from the manifest.json')
  654.                             ->defaultFalse()
  655.                         ->end()
  656.                         ->scalarNode('version_strategy')->defaultNull()->end()
  657.                         ->scalarNode('version')->defaultNull()->end()
  658.                         ->scalarNode('version_format')->defaultValue('%%s?%%s')->end()
  659.                         ->scalarNode('json_manifest_path')->defaultNull()->end()
  660.                         ->scalarNode('base_path')->defaultValue('')->end()
  661.                         ->arrayNode('base_urls')
  662.                             ->requiresAtLeastOneElement()
  663.                             ->beforeNormalization()->castToArray()->end()
  664.                             ->prototype('scalar')->end()
  665.                         ->end()
  666.                     ->end()
  667.                     ->validate()
  668.                         ->ifTrue(function ($v) {
  669.                             return isset($v['version_strategy']) && isset($v['version']);
  670.                         })
  671.                         ->thenInvalid('You cannot use both "version_strategy" and "version" at the same time under "assets".')
  672.                     ->end()
  673.                     ->validate()
  674.                         ->ifTrue(function ($v) {
  675.                             return isset($v['version_strategy']) && isset($v['json_manifest_path']);
  676.                         })
  677.                         ->thenInvalid('You cannot use both "version_strategy" and "json_manifest_path" at the same time under "assets".')
  678.                     ->end()
  679.                     ->validate()
  680.                         ->ifTrue(function ($v) {
  681.                             return isset($v['version']) && isset($v['json_manifest_path']);
  682.                         })
  683.                         ->thenInvalid('You cannot use both "version" and "json_manifest_path" at the same time under "assets".')
  684.                     ->end()
  685.                     ->fixXmlConfig('package')
  686.                     ->children()
  687.                         ->arrayNode('packages')
  688.                             ->normalizeKeys(false)
  689.                             ->useAttributeAsKey('name')
  690.                             ->prototype('array')
  691.                                 ->fixXmlConfig('base_url')
  692.                                 ->children()
  693.                                     ->booleanNode('strict_mode')
  694.                                         ->info('Throw an exception if an entry is missing from the manifest.json')
  695.                                         ->defaultFalse()
  696.                                     ->end()
  697.                                     ->scalarNode('version_strategy')->defaultNull()->end()
  698.                                     ->scalarNode('version')
  699.                                         ->beforeNormalization()
  700.                                         ->ifTrue(function ($v) { return '' === $v; })
  701.                                         ->then(function ($v) { return; })
  702.                                         ->end()
  703.                                     ->end()
  704.                                     ->scalarNode('version_format')->defaultNull()->end()
  705.                                     ->scalarNode('json_manifest_path')->defaultNull()->end()
  706.                                     ->scalarNode('base_path')->defaultValue('')->end()
  707.                                     ->arrayNode('base_urls')
  708.                                         ->requiresAtLeastOneElement()
  709.                                         ->beforeNormalization()->castToArray()->end()
  710.                                         ->prototype('scalar')->end()
  711.                                     ->end()
  712.                                 ->end()
  713.                                 ->validate()
  714.                                     ->ifTrue(function ($v) {
  715.                                         return isset($v['version_strategy']) && isset($v['version']);
  716.                                     })
  717.                                     ->thenInvalid('You cannot use both "version_strategy" and "version" at the same time under "assets" packages.')
  718.                                 ->end()
  719.                                 ->validate()
  720.                                     ->ifTrue(function ($v) {
  721.                                         return isset($v['version_strategy']) && isset($v['json_manifest_path']);
  722.                                     })
  723.                                     ->thenInvalid('You cannot use both "version_strategy" and "json_manifest_path" at the same time under "assets" packages.')
  724.                                 ->end()
  725.                                 ->validate()
  726.                                     ->ifTrue(function ($v) {
  727.                                         return isset($v['version']) && isset($v['json_manifest_path']);
  728.                                     })
  729.                                     ->thenInvalid('You cannot use both "version" and "json_manifest_path" at the same time under "assets" packages.')
  730.                                 ->end()
  731.                             ->end()
  732.                         ->end()
  733.                     ->end()
  734.                 ->end()
  735.             ->end()
  736.         ;
  737.     }
  738.     private function addTranslatorSection(ArrayNodeDefinition $rootNode, callable $enableIfStandalone)
  739.     {
  740.         $rootNode
  741.             ->children()
  742.                 ->arrayNode('translator')
  743.                     ->info('translator configuration')
  744.                     ->{$enableIfStandalone('symfony/translation', Translator::class)}()
  745.                     ->fixXmlConfig('fallback')
  746.                     ->fixXmlConfig('path')
  747.                     ->fixXmlConfig('provider')
  748.                     ->children()
  749.                         ->arrayNode('fallbacks')
  750.                             ->info('Defaults to the value of "default_locale".')
  751.                             ->beforeNormalization()->ifString()->then(function ($v) { return [$v]; })->end()
  752.                             ->prototype('scalar')->end()
  753.                             ->defaultValue([])
  754.                         ->end()
  755.                         ->booleanNode('logging')->defaultValue(false)->end()
  756.                         ->scalarNode('formatter')->defaultValue('translator.formatter.default')->end()
  757.                         ->scalarNode('cache_dir')->defaultValue('%kernel.cache_dir%/translations')->end()
  758.                         ->scalarNode('default_path')
  759.                             ->info('The default path used to load translations')
  760.                             ->defaultValue('%kernel.project_dir%/translations')
  761.                         ->end()
  762.                         ->arrayNode('paths')
  763.                             ->prototype('scalar')->end()
  764.                         ->end()
  765.                         ->arrayNode('pseudo_localization')
  766.                             ->canBeEnabled()
  767.                             ->fixXmlConfig('localizable_html_attribute')
  768.                             ->children()
  769.                                 ->booleanNode('accents')->defaultTrue()->end()
  770.                                 ->floatNode('expansion_factor')
  771.                                     ->min(1.0)
  772.                                     ->defaultValue(1.0)
  773.                                 ->end()
  774.                                 ->booleanNode('brackets')->defaultTrue()->end()
  775.                                 ->booleanNode('parse_html')->defaultFalse()->end()
  776.                                 ->arrayNode('localizable_html_attributes')
  777.                                     ->prototype('scalar')->end()
  778.                                 ->end()
  779.                             ->end()
  780.                         ->end()
  781.                         ->arrayNode('providers')
  782.                             ->info('Translation providers you can read/write your translations from')
  783.                             ->useAttributeAsKey('name')
  784.                             ->prototype('array')
  785.                                 ->fixXmlConfig('domain')
  786.                                 ->fixXmlConfig('locale')
  787.                                 ->children()
  788.                                     ->scalarNode('dsn')->end()
  789.                                     ->arrayNode('domains')
  790.                                         ->prototype('scalar')->end()
  791.                                         ->defaultValue([])
  792.                                     ->end()
  793.                                     ->arrayNode('locales')
  794.                                         ->prototype('scalar')->end()
  795.                                         ->defaultValue([])
  796.                                         ->info('If not set, all locales listed under framework.enabled_locales are used.')
  797.                                     ->end()
  798.                                 ->end()
  799.                             ->end()
  800.                             ->defaultValue([])
  801.                         ->end()
  802.                     ->end()
  803.                 ->end()
  804.             ->end()
  805.         ;
  806.     }
  807.     private function addValidationSection(ArrayNodeDefinition $rootNode, callable $enableIfStandalone, callable $willBeAvailable)
  808.     {
  809.         $rootNode
  810.             ->children()
  811.                 ->arrayNode('validation')
  812.                     ->info('validation configuration')
  813.                     ->{$enableIfStandalone('symfony/validator', Validation::class)}()
  814.                     ->children()
  815.                         ->scalarNode('cache')->end()
  816.                         ->booleanNode('enable_annotations')->{!class_exists(FullStack::class) ? 'defaultTrue' : 'defaultFalse'}()->end()
  817.                         ->arrayNode('static_method')
  818.                             ->defaultValue(['loadValidatorMetadata'])
  819.                             ->prototype('scalar')->end()
  820.                             ->treatFalseLike([])
  821.                             ->validate()->castToArray()->end()
  822.                         ->end()
  823.                         ->scalarNode('translation_domain')->defaultValue('validators')->end()
  824.                         ->enumNode('email_validation_mode')->values(['html5', 'loose', 'strict'])->end()
  825.                         ->arrayNode('mapping')
  826.                             ->addDefaultsIfNotSet()
  827.                             ->fixXmlConfig('path')
  828.                             ->children()
  829.                                 ->arrayNode('paths')
  830.                                     ->prototype('scalar')->end()
  831.                                 ->end()
  832.                             ->end()
  833.                         ->end()
  834.                         ->arrayNode('not_compromised_password')
  835.                             ->canBeDisabled()
  836.                             ->children()
  837.                                 ->booleanNode('enabled')
  838.                                     ->defaultTrue()
  839.                                     ->info('When disabled, compromised passwords will be accepted as valid.')
  840.                                 ->end()
  841.                                 ->scalarNode('endpoint')
  842.                                     ->defaultNull()
  843.                                     ->info('API endpoint for the NotCompromisedPassword Validator.')
  844.                                 ->end()
  845.                             ->end()
  846.                         ->end()
  847.                         ->arrayNode('auto_mapping')
  848.                             ->info('A collection of namespaces for which auto-mapping will be enabled by default, or null to opt-in with the EnableAutoMapping constraint.')
  849.                             ->example([
  850.                                 'App\\Entity\\' => [],
  851.                                 'App\\WithSpecificLoaders\\' => ['validator.property_info_loader'],
  852.                             ])
  853.                             ->useAttributeAsKey('namespace')
  854.                             ->normalizeKeys(false)
  855.                             ->beforeNormalization()
  856.                                 ->ifArray()
  857.                                 ->then(function (array $values): array {
  858.                                     foreach ($values as $k => $v) {
  859.                                         if (isset($v['service'])) {
  860.                                             continue;
  861.                                         }
  862.                                         if (isset($v['namespace'])) {
  863.                                             $values[$k]['services'] = [];
  864.                                             continue;
  865.                                         }
  866.                                         if (!\is_array($v)) {
  867.                                             $values[$v]['services'] = [];
  868.                                             unset($values[$k]);
  869.                                             continue;
  870.                                         }
  871.                                         $tmp = $v;
  872.                                         unset($values[$k]);
  873.                                         $values[$k]['services'] = $tmp;
  874.                                     }
  875.                                     return $values;
  876.                                 })
  877.                             ->end()
  878.                             ->arrayPrototype()
  879.                                 ->fixXmlConfig('service')
  880.                                 ->children()
  881.                                     ->arrayNode('services')
  882.                                         ->prototype('scalar')->end()
  883.                                     ->end()
  884.                                 ->end()
  885.                             ->end()
  886.                         ->end()
  887.                     ->end()
  888.                 ->end()
  889.             ->end()
  890.         ;
  891.     }
  892.     private function addAnnotationsSection(ArrayNodeDefinition $rootNode, callable $willBeAvailable)
  893.     {
  894.         $rootNode
  895.             ->children()
  896.                 ->arrayNode('annotations')
  897.                     ->info('annotation configuration')
  898.                     ->{$willBeAvailable('doctrine/annotations', Annotation::class) ? 'canBeDisabled' : 'canBeEnabled'}()
  899.                     ->children()
  900.                         ->enumNode('cache')
  901.                             ->values(['none', 'php_array', 'file'])
  902.                             ->defaultValue('php_array')
  903.                         ->end()
  904.                         ->scalarNode('file_cache_dir')->defaultValue('%kernel.cache_dir%/annotations')->end()
  905.                         ->booleanNode('debug')->defaultValue($this->debug)->end()
  906.                     ->end()
  907.                 ->end()
  908.             ->end()
  909.         ;
  910.     }
  911.     private function addSerializerSection(ArrayNodeDefinition $rootNode, callable $enableIfStandalone, callable $willBeAvailable)
  912.     {
  913.         $rootNode
  914.             ->children()
  915.                 ->arrayNode('serializer')
  916.                     ->info('serializer configuration')
  917.                     ->{$enableIfStandalone('symfony/serializer', Serializer::class)}()
  918.                     ->children()
  919.                         ->booleanNode('enable_annotations')->{!class_exists(FullStack::class) ? 'defaultTrue' : 'defaultFalse'}()->end()
  920.                         ->scalarNode('name_converter')->end()
  921.                         ->scalarNode('circular_reference_handler')->end()
  922.                         ->scalarNode('max_depth_handler')->end()
  923.                         ->arrayNode('mapping')
  924.                             ->addDefaultsIfNotSet()
  925.                             ->fixXmlConfig('path')
  926.                             ->children()
  927.                                 ->arrayNode('paths')
  928.                                     ->prototype('scalar')->end()
  929.                                 ->end()
  930.                             ->end()
  931.                         ->end()
  932.                         ->arrayNode('default_context')
  933.                             ->normalizeKeys(false)
  934.                             ->useAttributeAsKey('name')
  935.                             ->defaultValue([])
  936.                             ->prototype('variable')->end()
  937.                         ->end()
  938.                     ->end()
  939.                 ->end()
  940.             ->end()
  941.         ;
  942.     }
  943.     private function addPropertyAccessSection(ArrayNodeDefinition $rootNode, callable $willBeAvailable)
  944.     {
  945.         $rootNode
  946.             ->children()
  947.                 ->arrayNode('property_access')
  948.                     ->addDefaultsIfNotSet()
  949.                     ->info('Property access configuration')
  950.                     ->{$willBeAvailable('symfony/property-access', PropertyAccessor::class) ? 'canBeDisabled' : 'canBeEnabled'}()
  951.                     ->children()
  952.                         ->booleanNode('magic_call')->defaultFalse()->end()
  953.                         ->booleanNode('magic_get')->defaultTrue()->end()
  954.                         ->booleanNode('magic_set')->defaultTrue()->end()
  955.                         ->booleanNode('throw_exception_on_invalid_index')->defaultFalse()->end()
  956.                         ->booleanNode('throw_exception_on_invalid_property_path')->defaultTrue()->end()
  957.                     ->end()
  958.                 ->end()
  959.             ->end()
  960.         ;
  961.     }
  962.     private function addPropertyInfoSection(ArrayNodeDefinition $rootNode, callable $enableIfStandalone)
  963.     {
  964.         $rootNode
  965.             ->children()
  966.                 ->arrayNode('property_info')
  967.                     ->info('Property info configuration')
  968.                     ->{$enableIfStandalone('symfony/property-info', PropertyInfoExtractorInterface::class)}()
  969.                 ->end()
  970.             ->end()
  971.         ;
  972.     }
  973.     private function addCacheSection(ArrayNodeDefinition $rootNode, callable $willBeAvailable)
  974.     {
  975.         $rootNode
  976.             ->children()
  977.                 ->arrayNode('cache')
  978.                     ->info('Cache configuration')
  979.                     ->addDefaultsIfNotSet()
  980.                     ->fixXmlConfig('pool')
  981.                     ->children()
  982.                         ->scalarNode('prefix_seed')
  983.                             ->info('Used to namespace cache keys when using several apps with the same shared backend')
  984.                             ->defaultValue('_%kernel.project_dir%.%kernel.container_class%')
  985.                             ->example('my-application-name/%kernel.environment%')
  986.                         ->end()
  987.                         ->scalarNode('app')
  988.                             ->info('App related cache pools configuration')
  989.                             ->defaultValue('cache.adapter.filesystem')
  990.                         ->end()
  991.                         ->scalarNode('system')
  992.                             ->info('System related cache pools configuration')
  993.                             ->defaultValue('cache.adapter.system')
  994.                         ->end()
  995.                         ->scalarNode('directory')->defaultValue('%kernel.cache_dir%/pools/app')->end()
  996.                         ->scalarNode('default_psr6_provider')->end()
  997.                         ->scalarNode('default_redis_provider')->defaultValue('redis://localhost')->end()
  998.                         ->scalarNode('default_memcached_provider')->defaultValue('memcached://localhost')->end()
  999.                         ->scalarNode('default_doctrine_dbal_provider')->defaultValue('database_connection')->end()
  1000.                         ->scalarNode('default_pdo_provider')->defaultValue($willBeAvailable('doctrine/dbal', Connection::class) ? 'database_connection' : null)->end()
  1001.                         ->arrayNode('pools')
  1002.                             ->useAttributeAsKey('name')
  1003.                             ->prototype('array')
  1004.                                 ->fixXmlConfig('adapter')
  1005.                                 ->beforeNormalization()
  1006.                                     ->ifTrue(function ($v) { return (isset($v['adapters']) || \is_array($v['adapter'] ?? null)) && isset($v['provider']); })
  1007.                                     ->thenInvalid('Pool cannot have a "provider" while "adapter" is set to a map')
  1008.                                 ->end()
  1009.                                 ->children()
  1010.                                     ->arrayNode('adapters')
  1011.                                         ->performNoDeepMerging()
  1012.                                         ->info('One or more adapters to chain for creating the pool, defaults to "cache.app".')
  1013.                                         ->beforeNormalization()
  1014.                                             ->always()->then(function ($values) {
  1015.                                                 if ([0] === array_keys($values) && \is_array($values[0])) {
  1016.                                                     return $values[0];
  1017.                                                 }
  1018.                                                 $adapters = [];
  1019.                                                 foreach ($values as $k => $v) {
  1020.                                                     if (\is_int($k) && \is_string($v)) {
  1021.                                                         $adapters[] = $v;
  1022.                                                     } elseif (!\is_array($v)) {
  1023.                                                         $adapters[$k] = $v;
  1024.                                                     } elseif (isset($v['provider'])) {
  1025.                                                         $adapters[$v['provider']] = $v['name'] ?? $v;
  1026.                                                     } else {
  1027.                                                         $adapters[] = $v['name'] ?? $v;
  1028.                                                     }
  1029.                                                 }
  1030.                                                 return $adapters;
  1031.                                             })
  1032.                                         ->end()
  1033.                                         ->prototype('scalar')->end()
  1034.                                     ->end()
  1035.                                     ->scalarNode('tags')->defaultNull()->end()
  1036.                                     ->booleanNode('public')->defaultFalse()->end()
  1037.                                     ->scalarNode('default_lifetime')
  1038.                                         ->info('Default lifetime of the pool')
  1039.                                         ->example('"600" for 5 minutes expressed in seconds, "PT5M" for five minutes expressed as ISO 8601 time interval, or "5 minutes" as a date expression')
  1040.                                     ->end()
  1041.                                     ->scalarNode('provider')
  1042.                                         ->info('Overwrite the setting from the default provider for this adapter.')
  1043.                                     ->end()
  1044.                                     ->scalarNode('early_expiration_message_bus')
  1045.                                         ->example('"messenger.default_bus" to send early expiration events to the default Messenger bus.')
  1046.                                     ->end()
  1047.                                     ->scalarNode('clearer')->end()
  1048.                                 ->end()
  1049.                             ->end()
  1050.                             ->validate()
  1051.                                 ->ifTrue(function ($v) { return isset($v['cache.app']) || isset($v['cache.system']); })
  1052.                                 ->thenInvalid('"cache.app" and "cache.system" are reserved names')
  1053.                             ->end()
  1054.                         ->end()
  1055.                     ->end()
  1056.                 ->end()
  1057.             ->end()
  1058.         ;
  1059.     }
  1060.     private function addPhpErrorsSection(ArrayNodeDefinition $rootNode)
  1061.     {
  1062.         $rootNode
  1063.             ->children()
  1064.                 ->arrayNode('php_errors')
  1065.                     ->info('PHP errors handling configuration')
  1066.                     ->addDefaultsIfNotSet()
  1067.                     ->children()
  1068.                         ->variableNode('log')
  1069.                             ->info('Use the application logger instead of the PHP logger for logging PHP errors.')
  1070.                             ->example('"true" to use the default configuration: log all errors. "false" to disable. An integer bit field of E_* constants, or an array mapping E_* constants to log levels.')
  1071.                             ->defaultValue($this->debug)
  1072.                             ->treatNullLike($this->debug)
  1073.                             ->beforeNormalization()
  1074.                                 ->ifArray()
  1075.                                 ->then(function (array $v): array {
  1076.                                     if (!($v[0]['type'] ?? false)) {
  1077.                                         return $v;
  1078.                                     }
  1079.                                     // Fix XML normalization
  1080.                                     $ret = [];
  1081.                                     foreach ($v as ['type' => $type, 'logLevel' => $logLevel]) {
  1082.                                         $ret[$type] = $logLevel;
  1083.                                     }
  1084.                                     return $ret;
  1085.                                 })
  1086.                             ->end()
  1087.                             ->validate()
  1088.                                 ->ifTrue(function ($v) { return !(\is_int($v) || \is_bool($v) || \is_array($v)); })
  1089.                                 ->thenInvalid('The "php_errors.log" parameter should be either an integer, a boolean, or an array')
  1090.                             ->end()
  1091.                         ->end()
  1092.                         ->booleanNode('throw')
  1093.                             ->info('Throw PHP errors as \ErrorException instances.')
  1094.                             ->defaultValue($this->debug)
  1095.                             ->treatNullLike($this->debug)
  1096.                         ->end()
  1097.                     ->end()
  1098.                 ->end()
  1099.             ->end()
  1100.         ;
  1101.     }
  1102.     private function addExceptionsSection(ArrayNodeDefinition $rootNode)
  1103.     {
  1104.         $logLevels = (new \ReflectionClass(LogLevel::class))->getConstants();
  1105.         $rootNode
  1106.             ->children()
  1107.                 ->arrayNode('exceptions')
  1108.                     ->info('Exception handling configuration')
  1109.                     ->beforeNormalization()
  1110.                         ->ifArray()
  1111.                         ->then(function (array $v): array {
  1112.                             if (!\array_key_exists('exception', $v)) {
  1113.                                 return $v;
  1114.                             }
  1115.                             // Fix XML normalization
  1116.                             $data = isset($v['exception'][0]) ? $v['exception'] : [$v['exception']];
  1117.                             $exceptions = [];
  1118.                             foreach ($data as $exception) {
  1119.                                 $config = [];
  1120.                                 if (\array_key_exists('log-level', $exception)) {
  1121.                                     $config['log_level'] = $exception['log-level'];
  1122.                                 }
  1123.                                 if (\array_key_exists('status-code', $exception)) {
  1124.                                     $config['status_code'] = $exception['status-code'];
  1125.                                 }
  1126.                                 $exceptions[$exception['name']] = $config;
  1127.                             }
  1128.                             return $exceptions;
  1129.                         })
  1130.                     ->end()
  1131.                     ->prototype('array')
  1132.                         ->fixXmlConfig('exception')
  1133.                         ->children()
  1134.                             ->scalarNode('log_level')
  1135.                                 ->info('The level of log message. Null to let Symfony decide.')
  1136.                                 ->validate()
  1137.                                     ->ifTrue(function ($v) use ($logLevels) { return !\in_array($v, $logLevels); })
  1138.                                     ->thenInvalid(sprintf('The log level is not valid. Pick one among "%s".', implode('", "', $logLevels)))
  1139.                                 ->end()
  1140.                                 ->defaultNull()
  1141.                             ->end()
  1142.                             ->scalarNode('status_code')
  1143.                                 ->info('The status code of the response. Null to let Symfony decide.')
  1144.                                 ->validate()
  1145.                                     ->ifTrue(function ($v) { return $v < 100 || $v > 599; })
  1146.                                     ->thenInvalid('The log level is not valid. Pick a value between 100 and 599.')
  1147.                                 ->end()
  1148.                                 ->defaultNull()
  1149.                             ->end()
  1150.                         ->end()
  1151.                     ->end()
  1152.                 ->end()
  1153.             ->end()
  1154.         ;
  1155.     }
  1156.     private function addLockSection(ArrayNodeDefinition $rootNode, callable $enableIfStandalone)
  1157.     {
  1158.         $rootNode
  1159.             ->children()
  1160.                 ->arrayNode('lock')
  1161.                     ->info('Lock configuration')
  1162.                     ->{$enableIfStandalone('symfony/lock', Lock::class)}()
  1163.                     ->beforeNormalization()
  1164.                         ->ifString()->then(function ($v) { return ['enabled' => true, 'resources' => $v]; })
  1165.                     ->end()
  1166.                     ->beforeNormalization()
  1167.                         ->ifTrue(function ($v) { return \is_array($v) && !isset($v['enabled']); })
  1168.                         ->then(function ($v) { return $v + ['enabled' => true]; })
  1169.                     ->end()
  1170.                     ->beforeNormalization()
  1171.                         ->ifTrue(function ($v) { return \is_array($v) && !isset($v['resources']) && !isset($v['resource']); })
  1172.                         ->then(function ($v) {
  1173.                             $e = $v['enabled'];
  1174.                             unset($v['enabled']);
  1175.                             return ['enabled' => $e, 'resources' => $v];
  1176.                         })
  1177.                     ->end()
  1178.                     ->addDefaultsIfNotSet()
  1179.                     ->fixXmlConfig('resource')
  1180.                     ->children()
  1181.                         ->arrayNode('resources')
  1182.                             ->normalizeKeys(false)
  1183.                             ->useAttributeAsKey('name')
  1184.                             ->requiresAtLeastOneElement()
  1185.                             ->defaultValue(['default' => [class_exists(SemaphoreStore::class) && SemaphoreStore::isSupported() ? 'semaphore' : 'flock']])
  1186.                             ->beforeNormalization()
  1187.                                 ->ifString()->then(function ($v) { return ['default' => $v]; })
  1188.                             ->end()
  1189.                             ->beforeNormalization()
  1190.                                 ->ifTrue(function ($v) { return \is_array($v) && array_is_list($v); })
  1191.                                 ->then(function ($v) {
  1192.                                     $resources = [];
  1193.                                     foreach ($v as $resource) {
  1194.                                         $resources[] = \is_array($resource) && isset($resource['name'])
  1195.                                             ? [$resource['name'] => $resource['value']]
  1196.                                             : ['default' => $resource]
  1197.                                         ;
  1198.                                     }
  1199.                                     return array_merge_recursive([], ...$resources);
  1200.                                 })
  1201.                             ->end()
  1202.                             ->prototype('array')
  1203.                                 ->performNoDeepMerging()
  1204.                                 ->beforeNormalization()->ifString()->then(function ($v) { return [$v]; })->end()
  1205.                                 ->prototype('scalar')->end()
  1206.                             ->end()
  1207.                         ->end()
  1208.                     ->end()
  1209.                 ->end()
  1210.             ->end()
  1211.         ;
  1212.     }
  1213.     private function addWebLinkSection(ArrayNodeDefinition $rootNode, callable $enableIfStandalone)
  1214.     {
  1215.         $rootNode
  1216.             ->children()
  1217.                 ->arrayNode('web_link')
  1218.                     ->info('web links configuration')
  1219.                     ->{$enableIfStandalone('symfony/weblink', HttpHeaderSerializer::class)}()
  1220.                 ->end()
  1221.             ->end()
  1222.         ;
  1223.     }
  1224.     private function addMessengerSection(ArrayNodeDefinition $rootNode, callable $enableIfStandalone)
  1225.     {
  1226.         $rootNode
  1227.             ->children()
  1228.                 ->arrayNode('messenger')
  1229.                     ->info('Messenger configuration')
  1230.                     ->{$enableIfStandalone('symfony/messenger', MessageBusInterface::class)}()
  1231.                     ->fixXmlConfig('transport')
  1232.                     ->fixXmlConfig('bus', 'buses')
  1233.                     ->validate()
  1234.                         ->ifTrue(function ($v) { return isset($v['buses']) && \count($v['buses']) > 1 && null === $v['default_bus']; })
  1235.                         ->thenInvalid('You must specify the "default_bus" if you define more than one bus.')
  1236.                     ->end()
  1237.                     ->validate()
  1238.                         ->ifTrue(static function ($v): bool { return isset($v['buses']) && null !== $v['default_bus'] && !isset($v['buses'][$v['default_bus']]); })
  1239.                         ->then(static function (array $v): void { throw new InvalidConfigurationException(sprintf('The specified default bus "%s" is not configured. Available buses are "%s".', $v['default_bus'], implode('", "', array_keys($v['buses'])))); })
  1240.                     ->end()
  1241.                     ->children()
  1242.                         ->arrayNode('routing')
  1243.                             ->normalizeKeys(false)
  1244.                             ->useAttributeAsKey('message_class')
  1245.                             ->beforeNormalization()
  1246.                                 ->always()
  1247.                                 ->then(function ($config) {
  1248.                                     if (!\is_array($config)) {
  1249.                                         return [];
  1250.                                     }
  1251.                                     // If XML config with only one routing attribute
  1252.                                     if (2 === \count($config) && isset($config['message-class']) && isset($config['sender'])) {
  1253.                                         $config = [0 => $config];
  1254.                                     }
  1255.                                     $newConfig = [];
  1256.                                     foreach ($config as $k => $v) {
  1257.                                         if (!\is_int($k)) {
  1258.                                             $newConfig[$k] = [
  1259.                                                 'senders' => $v['senders'] ?? (\is_array($v) ? array_values($v) : [$v]),
  1260.                                             ];
  1261.                                         } else {
  1262.                                             $newConfig[$v['message-class']]['senders'] = array_map(
  1263.                                                 function ($a) {
  1264.                                                     return \is_string($a) ? $a : $a['service'];
  1265.                                                 },
  1266.                                                 array_values($v['sender'])
  1267.                                             );
  1268.                                         }
  1269.                                     }
  1270.                                     return $newConfig;
  1271.                                 })
  1272.                             ->end()
  1273.                             ->prototype('array')
  1274.                                 ->performNoDeepMerging()
  1275.                                 ->children()
  1276.                                     ->arrayNode('senders')
  1277.                                         ->requiresAtLeastOneElement()
  1278.                                         ->prototype('scalar')->end()
  1279.                                     ->end()
  1280.                                 ->end()
  1281.                             ->end()
  1282.                         ->end()
  1283.                         ->arrayNode('serializer')
  1284.                             ->addDefaultsIfNotSet()
  1285.                             ->children()
  1286.                                 ->scalarNode('default_serializer')
  1287.                                     ->defaultValue('messenger.transport.native_php_serializer')
  1288.                                     ->info('Service id to use as the default serializer for the transports.')
  1289.                                 ->end()
  1290.                                 ->arrayNode('symfony_serializer')
  1291.                                     ->addDefaultsIfNotSet()
  1292.                                     ->children()
  1293.                                         ->scalarNode('format')->defaultValue('json')->info('Serialization format for the messenger.transport.symfony_serializer service (which is not the serializer used by default).')->end()
  1294.                                         ->arrayNode('context')
  1295.                                             ->normalizeKeys(false)
  1296.                                             ->useAttributeAsKey('name')
  1297.                                             ->defaultValue([])
  1298.                                             ->info('Context array for the messenger.transport.symfony_serializer service (which is not the serializer used by default).')
  1299.                                             ->prototype('variable')->end()
  1300.                                         ->end()
  1301.                                     ->end()
  1302.                                 ->end()
  1303.                             ->end()
  1304.                         ->end()
  1305.                         ->arrayNode('transports')
  1306.                             ->normalizeKeys(false)
  1307.                             ->useAttributeAsKey('name')
  1308.                             ->arrayPrototype()
  1309.                                 ->beforeNormalization()
  1310.                                     ->ifString()
  1311.                                     ->then(function (string $dsn) {
  1312.                                         return ['dsn' => $dsn];
  1313.                                     })
  1314.                                 ->end()
  1315.                                 ->fixXmlConfig('option')
  1316.                                 ->children()
  1317.                                     ->scalarNode('dsn')->end()
  1318.                                     ->scalarNode('serializer')->defaultNull()->info('Service id of a custom serializer to use.')->end()
  1319.                                     ->arrayNode('options')
  1320.                                         ->normalizeKeys(false)
  1321.                                         ->defaultValue([])
  1322.                                         ->prototype('variable')
  1323.                                         ->end()
  1324.                                     ->end()
  1325.                                     ->scalarNode('failure_transport')
  1326.                                         ->defaultNull()
  1327.                                         ->info('Transport name to send failed messages to (after all retries have failed).')
  1328.                                     ->end()
  1329.                                     ->arrayNode('retry_strategy')
  1330.                                         ->addDefaultsIfNotSet()
  1331.                                         ->beforeNormalization()
  1332.                                             ->always(function ($v) {
  1333.                                                 if (isset($v['service']) && (isset($v['max_retries']) || isset($v['delay']) || isset($v['multiplier']) || isset($v['max_delay']))) {
  1334.                                                     throw new \InvalidArgumentException('The "service" cannot be used along with the other "retry_strategy" options.');
  1335.                                                 }
  1336.                                                 return $v;
  1337.                                             })
  1338.                                         ->end()
  1339.                                         ->children()
  1340.                                             ->scalarNode('service')->defaultNull()->info('Service id to override the retry strategy entirely')->end()
  1341.                                             ->integerNode('max_retries')->defaultValue(3)->min(0)->end()
  1342.                                             ->integerNode('delay')->defaultValue(1000)->min(0)->info('Time in ms to delay (or the initial value when multiplier is used)')->end()
  1343.                                             ->floatNode('multiplier')->defaultValue(2)->min(1)->info('If greater than 1, delay will grow exponentially for each retry: this delay = (delay * (multiple ^ retries))')->end()
  1344.                                             ->integerNode('max_delay')->defaultValue(0)->min(0)->info('Max time in ms that a retry should ever be delayed (0 = infinite)')->end()
  1345.                                         ->end()
  1346.                                     ->end()
  1347.                                 ->end()
  1348.                             ->end()
  1349.                         ->end()
  1350.                         ->scalarNode('failure_transport')
  1351.                             ->defaultNull()
  1352.                             ->info('Transport name to send failed messages to (after all retries have failed).')
  1353.                         ->end()
  1354.                         ->booleanNode('reset_on_message')
  1355.                             ->defaultTrue()
  1356.                             ->info('Reset container services after each message.')
  1357.                             ->validate()
  1358.                                 ->ifTrue(static fn ($v) => true !== $v)
  1359.                                 ->thenInvalid('The "framework.messenger.reset_on_message" configuration option can be set to "true" only. To prevent services resetting after each message you can set the "--no-reset" option in "messenger:consume" command.')
  1360.                             ->end()
  1361.                         ->end()
  1362.                         ->scalarNode('default_bus')->defaultNull()->end()
  1363.                         ->arrayNode('buses')
  1364.                             ->defaultValue(['messenger.bus.default' => ['default_middleware' => true, 'middleware' => []]])
  1365.                             ->normalizeKeys(false)
  1366.                             ->useAttributeAsKey('name')
  1367.                             ->arrayPrototype()
  1368.                                 ->addDefaultsIfNotSet()
  1369.                                 ->children()
  1370.                                     ->enumNode('default_middleware')
  1371.                                         ->values([true, false, 'allow_no_handlers'])
  1372.                                         ->defaultTrue()
  1373.                                     ->end()
  1374.                                     ->arrayNode('middleware')
  1375.                                         ->performNoDeepMerging()
  1376.                                         ->beforeNormalization()
  1377.                                             ->ifTrue(function ($v) { return \is_string($v) || (\is_array($v) && !\is_int(key($v))); })
  1378.                                             ->then(function ($v) { return [$v]; })
  1379.                                         ->end()
  1380.                                         ->defaultValue([])
  1381.                                         ->arrayPrototype()
  1382.                                             ->beforeNormalization()
  1383.                                                 ->always()
  1384.                                                 ->then(function ($middleware): array {
  1385.                                                     if (!\is_array($middleware)) {
  1386.                                                         return ['id' => $middleware];
  1387.                                                     }
  1388.                                                     if (isset($middleware['id'])) {
  1389.                                                         return $middleware;
  1390.                                                     }
  1391.                                                     if (1 < \count($middleware)) {
  1392.                                                         throw new \InvalidArgumentException('Invalid middleware at path "framework.messenger": a map with a single factory id as key and its arguments as value was expected, '.json_encode($middleware).' given.');
  1393.                                                     }
  1394.                                                     return [
  1395.                                                         'id' => key($middleware),
  1396.                                                         'arguments' => current($middleware),
  1397.                                                     ];
  1398.                                                 })
  1399.                                             ->end()
  1400.                                             ->fixXmlConfig('argument')
  1401.                                             ->children()
  1402.                                                 ->scalarNode('id')->isRequired()->cannotBeEmpty()->end()
  1403.                                                 ->arrayNode('arguments')
  1404.                                                     ->normalizeKeys(false)
  1405.                                                     ->defaultValue([])
  1406.                                                     ->prototype('variable')
  1407.                                                 ->end()
  1408.                                             ->end()
  1409.                                         ->end()
  1410.                                     ->end()
  1411.                                 ->end()
  1412.                             ->end()
  1413.                         ->end()
  1414.                     ->end()
  1415.                 ->end()
  1416.             ->end()
  1417.         ;
  1418.     }
  1419.     private function addRobotsIndexSection(ArrayNodeDefinition $rootNode)
  1420.     {
  1421.         $rootNode
  1422.             ->children()
  1423.                 ->booleanNode('disallow_search_engine_index')
  1424.                     ->info('Enabled by default when debug is enabled.')
  1425.                     ->defaultValue($this->debug)
  1426.                     ->treatNullLike($this->debug)
  1427.                 ->end()
  1428.             ->end()
  1429.         ;
  1430.     }
  1431.     private function addHttpClientSection(ArrayNodeDefinition $rootNode, callable $enableIfStandalone)
  1432.     {
  1433.         $rootNode
  1434.             ->children()
  1435.                 ->arrayNode('http_client')
  1436.                     ->info('HTTP Client configuration')
  1437.                     ->{$enableIfStandalone('symfony/http-client', HttpClient::class)}()
  1438.                     ->fixXmlConfig('scoped_client')
  1439.                     ->beforeNormalization()
  1440.                         ->always(function ($config) {
  1441.                             if (empty($config['scoped_clients']) || !\is_array($config['default_options']['retry_failed'] ?? null)) {
  1442.                                 return $config;
  1443.                             }
  1444.                             foreach ($config['scoped_clients'] as &$scopedConfig) {
  1445.                                 if (!isset($scopedConfig['retry_failed']) || true === $scopedConfig['retry_failed']) {
  1446.                                     $scopedConfig['retry_failed'] = $config['default_options']['retry_failed'];
  1447.                                     continue;
  1448.                                 }
  1449.                                 if (\is_array($scopedConfig['retry_failed'])) {
  1450.                                     $scopedConfig['retry_failed'] = $scopedConfig['retry_failed'] + $config['default_options']['retry_failed'];
  1451.                                 }
  1452.                             }
  1453.                             return $config;
  1454.                         })
  1455.                     ->end()
  1456.                     ->children()
  1457.                         ->integerNode('max_host_connections')
  1458.                             ->info('The maximum number of connections to a single host.')
  1459.                         ->end()
  1460.                         ->arrayNode('default_options')
  1461.                             ->fixXmlConfig('header')
  1462.                             ->children()
  1463.                                 ->arrayNode('headers')
  1464.                                     ->info('Associative array: header => value(s).')
  1465.                                     ->useAttributeAsKey('name')
  1466.                                     ->normalizeKeys(false)
  1467.                                     ->variablePrototype()->end()
  1468.                                 ->end()
  1469.                                 ->integerNode('max_redirects')
  1470.                                     ->info('The maximum number of redirects to follow.')
  1471.                                 ->end()
  1472.                                 ->scalarNode('http_version')
  1473.                                     ->info('The default HTTP version, typically 1.1 or 2.0, leave to null for the best version.')
  1474.                                 ->end()
  1475.                                 ->arrayNode('resolve')
  1476.                                     ->info('Associative array: domain => IP.')
  1477.                                     ->useAttributeAsKey('host')
  1478.                                     ->beforeNormalization()
  1479.                                         ->always(function ($config) {
  1480.                                             if (!\is_array($config)) {
  1481.                                                 return [];
  1482.                                             }
  1483.                                             if (!isset($config['host'], $config['value']) || \count($config) > 2) {
  1484.                                                 return $config;
  1485.                                             }
  1486.                                             return [$config['host'] => $config['value']];
  1487.                                         })
  1488.                                     ->end()
  1489.                                     ->normalizeKeys(false)
  1490.                                     ->scalarPrototype()->end()
  1491.                                 ->end()
  1492.                                 ->scalarNode('proxy')
  1493.                                     ->info('The URL of the proxy to pass requests through or null for automatic detection.')
  1494.                                 ->end()
  1495.                                 ->scalarNode('no_proxy')
  1496.                                     ->info('A comma separated list of hosts that do not require a proxy to be reached.')
  1497.                                 ->end()
  1498.                                 ->floatNode('timeout')
  1499.                                     ->info('The idle timeout, defaults to the "default_socket_timeout" ini parameter.')
  1500.                                 ->end()
  1501.                                 ->floatNode('max_duration')
  1502.                                     ->info('The maximum execution time for the request+response as a whole.')
  1503.                                 ->end()
  1504.                                 ->scalarNode('bindto')
  1505.                                     ->info('A network interface name, IP address, a host name or a UNIX socket to bind to.')
  1506.                                 ->end()
  1507.                                 ->booleanNode('verify_peer')
  1508.                                     ->info('Indicates if the peer should be verified in an SSL/TLS context.')
  1509.                                 ->end()
  1510.                                 ->booleanNode('verify_host')
  1511.                                     ->info('Indicates if the host should exist as a certificate common name.')
  1512.                                 ->end()
  1513.                                 ->scalarNode('cafile')
  1514.                                     ->info('A certificate authority file.')
  1515.                                 ->end()
  1516.                                 ->scalarNode('capath')
  1517.                                     ->info('A directory that contains multiple certificate authority files.')
  1518.                                 ->end()
  1519.                                 ->scalarNode('local_cert')
  1520.                                     ->info('A PEM formatted certificate file.')
  1521.                                 ->end()
  1522.                                 ->scalarNode('local_pk')
  1523.                                     ->info('A private key file.')
  1524.                                 ->end()
  1525.                                 ->scalarNode('passphrase')
  1526.                                     ->info('The passphrase used to encrypt the "local_pk" file.')
  1527.                                 ->end()
  1528.                                 ->scalarNode('ciphers')
  1529.                                     ->info('A list of SSL/TLS ciphers separated by colons, commas or spaces (e.g. "RC3-SHA:TLS13-AES-128-GCM-SHA256"...)')
  1530.                                 ->end()
  1531.                                 ->arrayNode('peer_fingerprint')
  1532.                                     ->info('Associative array: hashing algorithm => hash(es).')
  1533.                                     ->normalizeKeys(false)
  1534.                                     ->children()
  1535.                                         ->variableNode('sha1')->end()
  1536.                                         ->variableNode('pin-sha256')->end()
  1537.                                         ->variableNode('md5')->end()
  1538.                                     ->end()
  1539.                                 ->end()
  1540.                                 ->append($this->addHttpClientRetrySection())
  1541.                             ->end()
  1542.                         ->end()
  1543.                         ->scalarNode('mock_response_factory')
  1544.                             ->info('The id of the service that should generate mock responses. It should be either an invokable or an iterable.')
  1545.                         ->end()
  1546.                         ->arrayNode('scoped_clients')
  1547.                             ->useAttributeAsKey('name')
  1548.                             ->normalizeKeys(false)
  1549.                             ->arrayPrototype()
  1550.                                 ->fixXmlConfig('header')
  1551.                                 ->beforeNormalization()
  1552.                                     ->always()
  1553.                                     ->then(function ($config) {
  1554.                                         if (!class_exists(HttpClient::class)) {
  1555.                                             throw new LogicException('HttpClient support cannot be enabled as the component is not installed. Try running "composer require symfony/http-client".');
  1556.                                         }
  1557.                                         return \is_array($config) ? $config : ['base_uri' => $config];
  1558.                                     })
  1559.                                 ->end()
  1560.                                 ->validate()
  1561.                                     ->ifTrue(function ($v) { return !isset($v['scope']) && !isset($v['base_uri']); })
  1562.                                     ->thenInvalid('Either "scope" or "base_uri" should be defined.')
  1563.                                 ->end()
  1564.                                 ->validate()
  1565.                                     ->ifTrue(function ($v) { return !empty($v['query']) && !isset($v['base_uri']); })
  1566.                                     ->thenInvalid('"query" applies to "base_uri" but no base URI is defined.')
  1567.                                 ->end()
  1568.                                 ->children()
  1569.                                     ->scalarNode('scope')
  1570.                                         ->info('The regular expression that the request URL must match before adding the other options. When none is provided, the base URI is used instead.')
  1571.                                         ->cannotBeEmpty()
  1572.                                     ->end()
  1573.                                     ->scalarNode('base_uri')
  1574.                                         ->info('The URI to resolve relative URLs, following rules in RFC 3985, section 2.')
  1575.                                         ->cannotBeEmpty()
  1576.                                     ->end()
  1577.                                     ->scalarNode('auth_basic')
  1578.                                         ->info('An HTTP Basic authentication "username:password".')
  1579.                                     ->end()
  1580.                                     ->scalarNode('auth_bearer')
  1581.                                         ->info('A token enabling HTTP Bearer authorization.')
  1582.                                     ->end()
  1583.                                     ->scalarNode('auth_ntlm')
  1584.                                         ->info('A "username:password" pair to use Microsoft NTLM authentication (requires the cURL extension).')
  1585.                                     ->end()
  1586.                                     ->arrayNode('query')
  1587.                                         ->info('Associative array of query string values merged with the base URI.')
  1588.                                         ->useAttributeAsKey('key')
  1589.                                         ->beforeNormalization()
  1590.                                             ->always(function ($config) {
  1591.                                                 if (!\is_array($config)) {
  1592.                                                     return [];
  1593.                                                 }
  1594.                                                 if (!isset($config['key'], $config['value']) || \count($config) > 2) {
  1595.                                                     return $config;
  1596.                                                 }
  1597.                                                 return [$config['key'] => $config['value']];
  1598.                                             })
  1599.                                         ->end()
  1600.                                         ->normalizeKeys(false)
  1601.                                         ->scalarPrototype()->end()
  1602.                                     ->end()
  1603.                                     ->arrayNode('headers')
  1604.                                         ->info('Associative array: header => value(s).')
  1605.                                         ->useAttributeAsKey('name')
  1606.                                         ->normalizeKeys(false)
  1607.                                         ->variablePrototype()->end()
  1608.                                     ->end()
  1609.                                     ->integerNode('max_redirects')
  1610.                                         ->info('The maximum number of redirects to follow.')
  1611.                                     ->end()
  1612.                                     ->scalarNode('http_version')
  1613.                                         ->info('The default HTTP version, typically 1.1 or 2.0, leave to null for the best version.')
  1614.                                     ->end()
  1615.                                     ->arrayNode('resolve')
  1616.                                         ->info('Associative array: domain => IP.')
  1617.                                         ->useAttributeAsKey('host')
  1618.                                         ->beforeNormalization()
  1619.                                             ->always(function ($config) {
  1620.                                                 if (!\is_array($config)) {
  1621.                                                     return [];
  1622.                                                 }
  1623.                                                 if (!isset($config['host'], $config['value']) || \count($config) > 2) {
  1624.                                                     return $config;
  1625.                                                 }
  1626.                                                 return [$config['host'] => $config['value']];
  1627.                                             })
  1628.                                         ->end()
  1629.                                         ->normalizeKeys(false)
  1630.                                         ->scalarPrototype()->end()
  1631.                                     ->end()
  1632.                                     ->scalarNode('proxy')
  1633.                                         ->info('The URL of the proxy to pass requests through or null for automatic detection.')
  1634.                                     ->end()
  1635.                                     ->scalarNode('no_proxy')
  1636.                                         ->info('A comma separated list of hosts that do not require a proxy to be reached.')
  1637.                                     ->end()
  1638.                                     ->floatNode('timeout')
  1639.                                         ->info('The idle timeout, defaults to the "default_socket_timeout" ini parameter.')
  1640.                                     ->end()
  1641.                                     ->floatNode('max_duration')
  1642.                                         ->info('The maximum execution time for the request+response as a whole.')
  1643.                                     ->end()
  1644.                                     ->scalarNode('bindto')
  1645.                                         ->info('A network interface name, IP address, a host name or a UNIX socket to bind to.')
  1646.                                     ->end()
  1647.                                     ->booleanNode('verify_peer')
  1648.                                         ->info('Indicates if the peer should be verified in an SSL/TLS context.')
  1649.                                     ->end()
  1650.                                     ->booleanNode('verify_host')
  1651.                                         ->info('Indicates if the host should exist as a certificate common name.')
  1652.                                     ->end()
  1653.                                     ->scalarNode('cafile')
  1654.                                         ->info('A certificate authority file.')
  1655.                                     ->end()
  1656.                                     ->scalarNode('capath')
  1657.                                         ->info('A directory that contains multiple certificate authority files.')
  1658.                                     ->end()
  1659.                                     ->scalarNode('local_cert')
  1660.                                         ->info('A PEM formatted certificate file.')
  1661.                                     ->end()
  1662.                                     ->scalarNode('local_pk')
  1663.                                         ->info('A private key file.')
  1664.                                     ->end()
  1665.                                     ->scalarNode('passphrase')
  1666.                                         ->info('The passphrase used to encrypt the "local_pk" file.')
  1667.                                     ->end()
  1668.                                     ->scalarNode('ciphers')
  1669.                                         ->info('A list of SSL/TLS ciphers separated by colons, commas or spaces (e.g. "RC3-SHA:TLS13-AES-128-GCM-SHA256"...)')
  1670.                                     ->end()
  1671.                                     ->arrayNode('peer_fingerprint')
  1672.                                         ->info('Associative array: hashing algorithm => hash(es).')
  1673.                                         ->normalizeKeys(false)
  1674.                                         ->children()
  1675.                                             ->variableNode('sha1')->end()
  1676.                                             ->variableNode('pin-sha256')->end()
  1677.                                             ->variableNode('md5')->end()
  1678.                                         ->end()
  1679.                                     ->end()
  1680.                                     ->append($this->addHttpClientRetrySection())
  1681.                                 ->end()
  1682.                             ->end()
  1683.                         ->end()
  1684.                     ->end()
  1685.                 ->end()
  1686.             ->end()
  1687.         ;
  1688.     }
  1689.     private function addHttpClientRetrySection()
  1690.     {
  1691.         $root = new NodeBuilder();
  1692.         return $root
  1693.             ->arrayNode('retry_failed')
  1694.                 ->fixXmlConfig('http_code')
  1695.                 ->canBeEnabled()
  1696.                 ->addDefaultsIfNotSet()
  1697.                 ->beforeNormalization()
  1698.                     ->always(function ($v) {
  1699.                         if (isset($v['retry_strategy']) && (isset($v['http_codes']) || isset($v['delay']) || isset($v['multiplier']) || isset($v['max_delay']) || isset($v['jitter']))) {
  1700.                             throw new \InvalidArgumentException('The "retry_strategy" option cannot be used along with the "http_codes", "delay", "multiplier", "max_delay" or "jitter" options.');
  1701.                         }
  1702.                         return $v;
  1703.                     })
  1704.                 ->end()
  1705.                 ->children()
  1706.                     ->scalarNode('retry_strategy')->defaultNull()->info('service id to override the retry strategy')->end()
  1707.                     ->arrayNode('http_codes')
  1708.                         ->performNoDeepMerging()
  1709.                         ->beforeNormalization()
  1710.                             ->ifArray()
  1711.                             ->then(static function ($v) {
  1712.                                 $list = [];
  1713.                                 foreach ($v as $key => $val) {
  1714.                                     if (is_numeric($val)) {
  1715.                                         $list[] = ['code' => $val];
  1716.                                     } elseif (\is_array($val)) {
  1717.                                         if (isset($val['code']) || isset($val['methods'])) {
  1718.                                             $list[] = $val;
  1719.                                         } else {
  1720.                                             $list[] = ['code' => $key, 'methods' => $val];
  1721.                                         }
  1722.                                     } elseif (true === $val || null === $val) {
  1723.                                         $list[] = ['code' => $key];
  1724.                                     }
  1725.                                 }
  1726.                                 return $list;
  1727.                             })
  1728.                         ->end()
  1729.                         ->useAttributeAsKey('code')
  1730.                         ->arrayPrototype()
  1731.                             ->fixXmlConfig('method')
  1732.                             ->children()
  1733.                                 ->integerNode('code')->end()
  1734.                                 ->arrayNode('methods')
  1735.                                     ->beforeNormalization()
  1736.                                     ->ifArray()
  1737.                                         ->then(function ($v) {
  1738.                                             return array_map('strtoupper', $v);
  1739.                                         })
  1740.                                     ->end()
  1741.                                     ->prototype('scalar')->end()
  1742.                                     ->info('A list of HTTP methods that triggers a retry for this status code. When empty, all methods are retried')
  1743.                                 ->end()
  1744.                             ->end()
  1745.                         ->end()
  1746.                         ->info('A list of HTTP status code that triggers a retry')
  1747.                     ->end()
  1748.                     ->integerNode('max_retries')->defaultValue(3)->min(0)->end()
  1749.                     ->integerNode('delay')->defaultValue(1000)->min(0)->info('Time in ms to delay (or the initial value when multiplier is used)')->end()
  1750.                     ->floatNode('multiplier')->defaultValue(2)->min(1)->info('If greater than 1, delay will grow exponentially for each retry: delay * (multiple ^ retries)')->end()
  1751.                     ->integerNode('max_delay')->defaultValue(0)->min(0)->info('Max time in ms that a retry should ever be delayed (0 = infinite)')->end()
  1752.                     ->floatNode('jitter')->defaultValue(0.1)->min(0)->max(1)->info('Randomness in percent (between 0 and 1) to apply to the delay')->end()
  1753.                 ->end()
  1754.             ;
  1755.     }
  1756.     private function addMailerSection(ArrayNodeDefinition $rootNode, callable $enableIfStandalone)
  1757.     {
  1758.         $rootNode
  1759.             ->children()
  1760.                 ->arrayNode('mailer')
  1761.                     ->info('Mailer configuration')
  1762.                     ->{$enableIfStandalone('symfony/mailer', Mailer::class)}()
  1763.                     ->validate()
  1764.                         ->ifTrue(function ($v) { return isset($v['dsn']) && \count($v['transports']); })
  1765.                         ->thenInvalid('"dsn" and "transports" cannot be used together.')
  1766.                     ->end()
  1767.                     ->fixXmlConfig('transport')
  1768.                     ->fixXmlConfig('header')
  1769.                     ->children()
  1770.                         ->scalarNode('message_bus')->defaultNull()->info('The message bus to use. Defaults to the default bus if the Messenger component is installed.')->end()
  1771.                         ->scalarNode('dsn')->defaultNull()->end()
  1772.                         ->arrayNode('transports')
  1773.                             ->useAttributeAsKey('name')
  1774.                             ->prototype('scalar')->end()
  1775.                         ->end()
  1776.                         ->arrayNode('envelope')
  1777.                             ->info('Mailer Envelope configuration')
  1778.                             ->children()
  1779.                                 ->scalarNode('sender')->end()
  1780.                                 ->arrayNode('recipients')
  1781.                                     ->performNoDeepMerging()
  1782.                                     ->beforeNormalization()
  1783.                                     ->ifArray()
  1784.                                         ->then(function ($v) {
  1785.                                             return array_filter(array_values($v));
  1786.                                         })
  1787.                                     ->end()
  1788.                                     ->prototype('scalar')->end()
  1789.                                 ->end()
  1790.                             ->end()
  1791.                         ->end()
  1792.                         ->arrayNode('headers')
  1793.                             ->normalizeKeys(false)
  1794.                             ->useAttributeAsKey('name')
  1795.                             ->prototype('array')
  1796.                                 ->normalizeKeys(false)
  1797.                                 ->beforeNormalization()
  1798.                                     ->ifTrue(function ($v) { return !\is_array($v) || array_keys($v) !== ['value']; })
  1799.                                     ->then(function ($v) { return ['value' => $v]; })
  1800.                                 ->end()
  1801.                                 ->children()
  1802.                                     ->variableNode('value')->end()
  1803.                                 ->end()
  1804.                             ->end()
  1805.                         ->end()
  1806.                     ->end()
  1807.                 ->end()
  1808.             ->end()
  1809.         ;
  1810.     }
  1811.     private function addNotifierSection(ArrayNodeDefinition $rootNode, callable $enableIfStandalone)
  1812.     {
  1813.         $rootNode
  1814.             ->children()
  1815.                 ->arrayNode('notifier')
  1816.                     ->info('Notifier configuration')
  1817.                     ->{$enableIfStandalone('symfony/notifier', Notifier::class)}()
  1818.                     ->fixXmlConfig('chatter_transport')
  1819.                     ->children()
  1820.                         ->arrayNode('chatter_transports')
  1821.                             ->useAttributeAsKey('name')
  1822.                             ->prototype('scalar')->end()
  1823.                         ->end()
  1824.                     ->end()
  1825.                     ->fixXmlConfig('texter_transport')
  1826.                     ->children()
  1827.                         ->arrayNode('texter_transports')
  1828.                             ->useAttributeAsKey('name')
  1829.                             ->prototype('scalar')->end()
  1830.                         ->end()
  1831.                     ->end()
  1832.                     ->children()
  1833.                         ->booleanNode('notification_on_failed_messages')->defaultFalse()->end()
  1834.                     ->end()
  1835.                     ->children()
  1836.                         ->arrayNode('channel_policy')
  1837.                             ->useAttributeAsKey('name')
  1838.                             ->prototype('array')
  1839.                                 ->beforeNormalization()->ifString()->then(function (string $v) { return [$v]; })->end()
  1840.                                 ->prototype('scalar')->end()
  1841.                             ->end()
  1842.                         ->end()
  1843.                     ->end()
  1844.                     ->fixXmlConfig('admin_recipient')
  1845.                     ->children()
  1846.                         ->arrayNode('admin_recipients')
  1847.                             ->prototype('array')
  1848.                                 ->children()
  1849.                                     ->scalarNode('email')->cannotBeEmpty()->end()
  1850.                                     ->scalarNode('phone')->defaultValue('')->end()
  1851.                                 ->end()
  1852.                             ->end()
  1853.                         ->end()
  1854.                     ->end()
  1855.                 ->end()
  1856.             ->end()
  1857.         ;
  1858.     }
  1859.     private function addRateLimiterSection(ArrayNodeDefinition $rootNode, callable $enableIfStandalone)
  1860.     {
  1861.         $rootNode
  1862.             ->children()
  1863.                 ->arrayNode('rate_limiter')
  1864.                     ->info('Rate limiter configuration')
  1865.                     ->{$enableIfStandalone('symfony/rate-limiter', TokenBucketLimiter::class)}()
  1866.                     ->fixXmlConfig('limiter')
  1867.                     ->beforeNormalization()
  1868.                         ->ifTrue(function ($v) { return \is_array($v) && !isset($v['limiters']) && !isset($v['limiter']); })
  1869.                         ->then(function (array $v) {
  1870.                             $newV = [
  1871.                                 'enabled' => $v['enabled'] ?? true,
  1872.                             ];
  1873.                             unset($v['enabled']);
  1874.                             $newV['limiters'] = $v;
  1875.                             return $newV;
  1876.                         })
  1877.                     ->end()
  1878.                     ->children()
  1879.                         ->arrayNode('limiters')
  1880.                             ->useAttributeAsKey('name')
  1881.                             ->arrayPrototype()
  1882.                                 ->children()
  1883.                                     ->scalarNode('lock_factory')
  1884.                                         ->info('The service ID of the lock factory used by this limiter (or null to disable locking)')
  1885.                                         ->defaultValue('lock.factory')
  1886.                                     ->end()
  1887.                                     ->scalarNode('cache_pool')
  1888.                                         ->info('The cache pool to use for storing the current limiter state')
  1889.                                         ->defaultValue('cache.rate_limiter')
  1890.                                     ->end()
  1891.                                     ->scalarNode('storage_service')
  1892.                                         ->info('The service ID of a custom storage implementation, this precedes any configured "cache_pool"')
  1893.                                         ->defaultNull()
  1894.                                     ->end()
  1895.                                     ->enumNode('policy')
  1896.                                         ->info('The algorithm to be used by this limiter')
  1897.                                         ->isRequired()
  1898.                                         ->values(['fixed_window', 'token_bucket', 'sliding_window', 'no_limit'])
  1899.                                     ->end()
  1900.                                     ->integerNode('limit')
  1901.                                         ->info('The maximum allowed hits in a fixed interval or burst')
  1902.                                         ->isRequired()
  1903.                                     ->end()
  1904.                                     ->scalarNode('interval')
  1905.                                         ->info('Configures the fixed interval if "policy" is set to "fixed_window" or "sliding_window". The value must be a number followed by "second", "minute", "hour", "day", "week" or "month" (or their plural equivalent).')
  1906.                                     ->end()
  1907.                                     ->arrayNode('rate')
  1908.                                         ->info('Configures the fill rate if "policy" is set to "token_bucket"')
  1909.                                         ->children()
  1910.                                             ->scalarNode('interval')
  1911.                                                 ->info('Configures the rate interval. The value must be a number followed by "second", "minute", "hour", "day", "week" or "month" (or their plural equivalent).')
  1912.                                             ->end()
  1913.                                             ->integerNode('amount')->info('Amount of tokens to add each interval')->defaultValue(1)->end()
  1914.                                         ->end()
  1915.                                     ->end()
  1916.                                 ->end()
  1917.                             ->end()
  1918.                         ->end()
  1919.                     ->end()
  1920.                 ->end()
  1921.             ->end()
  1922.         ;
  1923.     }
  1924.     private function addUidSection(ArrayNodeDefinition $rootNode, callable $enableIfStandalone)
  1925.     {
  1926.         $rootNode
  1927.             ->children()
  1928.                 ->arrayNode('uid')
  1929.                     ->info('Uid configuration')
  1930.                     ->{$enableIfStandalone('symfony/uid', UuidFactory::class)}()
  1931.                     ->addDefaultsIfNotSet()
  1932.                     ->children()
  1933.                         ->enumNode('default_uuid_version')
  1934.                             ->defaultValue(6)
  1935.                             ->values([6, 4, 1])
  1936.                         ->end()
  1937.                         ->enumNode('name_based_uuid_version')
  1938.                             ->defaultValue(5)
  1939.                             ->values([5, 3])
  1940.                         ->end()
  1941.                         ->scalarNode('name_based_uuid_namespace')
  1942.                             ->cannotBeEmpty()
  1943.                         ->end()
  1944.                         ->enumNode('time_based_uuid_version')
  1945.                             ->defaultValue(6)
  1946.                             ->values([6, 1])
  1947.                         ->end()
  1948.                         ->scalarNode('time_based_uuid_node')
  1949.                             ->cannotBeEmpty()
  1950.                         ->end()
  1951.                     ->end()
  1952.                 ->end()
  1953.             ->end()
  1954.         ;
  1955.     }
  1956. }