vendor/doctrine/doctrine-bundle/DependencyInjection/Configuration.php line 247

Open in your IDE?
  1. <?php
  2. namespace Doctrine\Bundle\DoctrineBundle\DependencyInjection;
  3. use Doctrine\ORM\EntityManager;
  4. use ReflectionClass;
  5. use Symfony\Component\Config\Definition\BaseNode;
  6. use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
  7. use Symfony\Component\Config\Definition\Builder\NodeDefinition;
  8. use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  9. use Symfony\Component\Config\Definition\ConfigurationInterface;
  10. use Symfony\Component\DependencyInjection\Exception\LogicException;
  11. use function array_intersect_key;
  12. use function array_key_exists;
  13. use function array_keys;
  14. use function array_pop;
  15. use function assert;
  16. use function class_exists;
  17. use function constant;
  18. use function count;
  19. use function implode;
  20. use function in_array;
  21. use function is_array;
  22. use function is_bool;
  23. use function is_int;
  24. use function is_string;
  25. use function key;
  26. use function method_exists;
  27. use function reset;
  28. use function sprintf;
  29. use function strlen;
  30. use function strpos;
  31. use function strtoupper;
  32. use function substr;
  33. use function trigger_deprecation;
  34. /**
  35.  * This class contains the configuration information for the bundle
  36.  *
  37.  * This information is solely responsible for how the different configuration
  38.  * sections are normalized, and merged.
  39.  */
  40. class Configuration implements ConfigurationInterface
  41. {
  42.     /** @var bool */
  43.     private $debug;
  44.     /** @param bool $debug Whether to use the debug mode */
  45.     public function __construct(bool $debug)
  46.     {
  47.         $this->debug $debug;
  48.     }
  49.     public function getConfigTreeBuilder(): TreeBuilder
  50.     {
  51.         $treeBuilder = new TreeBuilder('doctrine');
  52.         $rootNode    $treeBuilder->getRootNode();
  53.         $this->addDbalSection($rootNode);
  54.         $this->addOrmSection($rootNode);
  55.         return $treeBuilder;
  56.     }
  57.     /**
  58.      * Add DBAL section to configuration tree
  59.      */
  60.     private function addDbalSection(ArrayNodeDefinition $node): void
  61.     {
  62.         $node
  63.             ->children()
  64.             ->arrayNode('dbal')
  65.                 ->beforeNormalization()
  66.                     ->ifTrue(static function ($v) {
  67.                         return is_array($v) && ! array_key_exists('connections'$v) && ! array_key_exists('connection'$v);
  68.                     })
  69.                     ->then(static function ($v) {
  70.                         // Key that should not be rewritten to the connection config
  71.                         $excludedKeys = ['default_connection' => true'types' => true'type' => true];
  72.                         $connection   = [];
  73.                         foreach ($v as $key => $value) {
  74.                             if (isset($excludedKeys[$key])) {
  75.                                 continue;
  76.                             }
  77.                             $connection[$key] = $v[$key];
  78.                             unset($v[$key]);
  79.                         }
  80.                         $v['default_connection'] = isset($v['default_connection']) ? (string) $v['default_connection'] : 'default';
  81.                         $v['connections']        = [$v['default_connection'] => $connection];
  82.                         return $v;
  83.                     })
  84.                 ->end()
  85.                 ->children()
  86.                     ->scalarNode('default_connection')->end()
  87.                 ->end()
  88.                 ->fixXmlConfig('type')
  89.                 ->children()
  90.                     ->arrayNode('types')
  91.                         ->useAttributeAsKey('name')
  92.                         ->prototype('array')
  93.                             ->beforeNormalization()
  94.                                 ->ifString()
  95.                                 ->then(static function ($v) {
  96.                                     return ['class' => $v];
  97.                                 })
  98.                             ->end()
  99.                             ->children()
  100.                                 ->scalarNode('class')->isRequired()->end()
  101.                                 ->booleanNode('commented')
  102.                                     ->setDeprecated(
  103.                                         ...$this->getDeprecationMsg('The doctrine-bundle type commenting features were removed; the corresponding config parameter was deprecated in 2.0 and will be dropped in 3.0.''2.0')
  104.                                     )
  105.                                 ->end()
  106.                             ->end()
  107.                         ->end()
  108.                     ->end()
  109.                 ->end()
  110.                 ->fixXmlConfig('connection')
  111.                 ->append($this->getDbalConnectionsNode())
  112.             ->end();
  113.     }
  114.     /**
  115.      * Return the dbal connections node
  116.      */
  117.     private function getDbalConnectionsNode(): ArrayNodeDefinition
  118.     {
  119.         $treeBuilder = new TreeBuilder('connections');
  120.         $node        $treeBuilder->getRootNode();
  121.         $connectionNode $node
  122.             ->requiresAtLeastOneElement()
  123.             ->useAttributeAsKey('name')
  124.             ->prototype('array');
  125.         assert($connectionNode instanceof ArrayNodeDefinition);
  126.         $this->configureDbalDriverNode($connectionNode);
  127.         $connectionNode
  128.             ->fixXmlConfig('option')
  129.             ->fixXmlConfig('mapping_type')
  130.             ->fixXmlConfig('slave')
  131.             ->fixXmlConfig('replica')
  132.             ->fixXmlConfig('shard')
  133.             ->fixXmlConfig('default_table_option')
  134.             ->children()
  135.                 ->scalarNode('driver')->defaultValue('pdo_mysql')->end()
  136.                 ->scalarNode('platform_service')->end()
  137.                 ->booleanNode('auto_commit')->end()
  138.                 ->scalarNode('schema_filter')->end()
  139.                 ->booleanNode('logging')->defaultValue($this->debug)->end()
  140.                 ->booleanNode('profiling')->defaultValue($this->debug)->end()
  141.                 ->booleanNode('profiling_collect_backtrace')
  142.                     ->defaultValue(false)
  143.                     ->info('Enables collecting backtraces when profiling is enabled')
  144.                 ->end()
  145.                 ->booleanNode('profiling_collect_schema_errors')
  146.                     ->defaultValue(true)
  147.                     ->info('Enables collecting schema errors when profiling is enabled')
  148.                 ->end()
  149.                 ->scalarNode('server_version')->end()
  150.                 ->scalarNode('driver_class')->end()
  151.                 ->scalarNode('wrapper_class')->end()
  152.                 ->scalarNode('shard_manager_class')->end()
  153.                 ->scalarNode('shard_choser')->end()
  154.                 ->scalarNode('shard_choser_service')->end()
  155.                 ->booleanNode('keep_slave')
  156.                     ->setDeprecated(
  157.                         ...$this->getDeprecationMsg('The "keep_slave" configuration key is deprecated since doctrine-bundle 2.2. Use the "keep_replica" configuration key instead.''2.2')
  158.                     )
  159.                 ->end()
  160.                 ->booleanNode('keep_replica')->end()
  161.                 ->arrayNode('options')
  162.                     ->useAttributeAsKey('key')
  163.                     ->prototype('variable')->end()
  164.                 ->end()
  165.                 ->arrayNode('mapping_types')
  166.                     ->useAttributeAsKey('name')
  167.                     ->prototype('scalar')->end()
  168.                 ->end()
  169.                 ->arrayNode('default_table_options')
  170.                     ->info("This option is used by the schema-tool and affects generated SQL. Possible keys include 'charset','collate', and 'engine'.")
  171.                     ->useAttributeAsKey('name')
  172.                     ->prototype('scalar')->end()
  173.                 ->end()
  174.             ->end();
  175.         // dbal < 2.11
  176.         $slaveNode $connectionNode
  177.             ->children()
  178.                 ->arrayNode('slaves')
  179.                     ->setDeprecated(
  180.                         ...$this->getDeprecationMsg('The "slaves" configuration key will be renamed to "replicas" in doctrine-bundle 3.0. "slaves" is deprecated since doctrine-bundle 2.2.''2.2')
  181.                     )
  182.                     ->useAttributeAsKey('name')
  183.                     ->prototype('array');
  184.         $this->configureDbalDriverNode($slaveNode);
  185.         // dbal >= 2.11
  186.         $replicaNode $connectionNode
  187.             ->children()
  188.                 ->arrayNode('replicas')
  189.                     ->useAttributeAsKey('name')
  190.                     ->prototype('array');
  191.         $this->configureDbalDriverNode($replicaNode);
  192.         $shardNode $connectionNode
  193.             ->children()
  194.                 ->arrayNode('shards')
  195.                     ->prototype('array');
  196.         $shardNode
  197.             ->children()
  198.                 ->integerNode('id')
  199.                     ->min(1)
  200.                     ->isRequired()
  201.                 ->end()
  202.             ->end();
  203.         $this->configureDbalDriverNode($shardNode);
  204.         return $node;
  205.     }
  206.     /**
  207.      * Adds config keys related to params processed by the DBAL drivers
  208.      *
  209.      * These keys are available for replica configurations too.
  210.      */
  211.     private function configureDbalDriverNode(ArrayNodeDefinition $node): void
  212.     {
  213.         $node
  214.             ->validate()
  215.             ->always(static function (array $values) {
  216.                 if (! isset($values['url'])) {
  217.                     return $values;
  218.                 }
  219.                 $urlConflictingOptions = ['host' => true'port' => true'user' => true'password' => true'path' => true'dbname' => true'unix_socket' => true'memory' => true];
  220.                 $urlConflictingValues  array_keys(array_intersect_key($values$urlConflictingOptions));
  221.                 if ($urlConflictingValues) {
  222.                     $tail count($urlConflictingValues) > sprintf('or "%s" options'array_pop($urlConflictingValues)) : 'option';
  223.                     trigger_deprecation(
  224.                         'doctrine/doctrine-bundle',
  225.                         '2.4',
  226.                         'Setting the "doctrine.dbal.%s" %s while the "url" one is defined is deprecated',
  227.                         implode('", "'$urlConflictingValues),
  228.                         $tail
  229.                     );
  230.                 }
  231.                 return $values;
  232.             })
  233.             ->end()
  234.             ->children()
  235.                 ->scalarNode('url')->info('A URL with connection information; any parameter value parsed from this string will override explicitly set parameters')->end()
  236.                 ->scalarNode('dbname')->end()
  237.                 ->scalarNode('host')->info('Defaults to "localhost" at runtime.')->end()
  238.                 ->scalarNode('port')->info('Defaults to null at runtime.')->end()
  239.                 ->scalarNode('user')->info('Defaults to "root" at runtime.')->end()
  240.                 ->scalarNode('password')->info('Defaults to null at runtime.')->end()
  241.                 ->booleanNode('override_url')->setDeprecated(...$this->getDeprecationMsg('The "doctrine.dbal.override_url" configuration key is deprecated.''2.4'))->end()
  242.                 ->scalarNode('dbname_suffix')->end()
  243.                 ->scalarNode('application_name')->end()
  244.                 ->scalarNode('charset')->end()
  245.                 ->scalarNode('path')->end()
  246.                 ->booleanNode('memory')->end()
  247.                 ->scalarNode('unix_socket')->info('The unix socket to use for MySQL')->end()
  248.                 ->booleanNode('persistent')->info('True to use as persistent connection for the ibm_db2 driver')->end()
  249.                 ->scalarNode('protocol')->info('The protocol to use for the ibm_db2 driver (default to TCPIP if omitted)')->end()
  250.                 ->booleanNode('service')
  251.                     ->info('True to use SERVICE_NAME as connection parameter instead of SID for Oracle')
  252.                 ->end()
  253.                 ->scalarNode('servicename')
  254.                     ->info(
  255.                         'Overrules dbname parameter if given and used as SERVICE_NAME or SID connection parameter ' .
  256.                         'for Oracle depending on the service parameter.'
  257.                     )
  258.                 ->end()
  259.                 ->scalarNode('sessionMode')
  260.                     ->info('The session mode to use for the oci8 driver')
  261.                 ->end()
  262.                 ->scalarNode('server')
  263.                     ->info('The name of a running database server to connect to for SQL Anywhere.')
  264.                 ->end()
  265.                 ->scalarNode('default_dbname')
  266.                     ->info(
  267.                         'Override the default database (postgres) to connect to for PostgreSQL connexion.'
  268.                     )
  269.                 ->end()
  270.                 ->scalarNode('sslmode')
  271.                     ->info(
  272.                         'Determines whether or with what priority a SSL TCP/IP connection will be negotiated with ' .
  273.                         'the server for PostgreSQL.'
  274.                     )
  275.                 ->end()
  276.                 ->scalarNode('sslrootcert')
  277.                     ->info(
  278.                         'The name of a file containing SSL certificate authority (CA) certificate(s). ' .
  279.                         'If the file exists, the server\'s certificate will be verified to be signed by one of these authorities.'
  280.                     )
  281.                 ->end()
  282.                 ->scalarNode('sslcert')
  283.                     ->info(
  284.                         'The path to the SSL client certificate file for PostgreSQL.'
  285.                     )
  286.                 ->end()
  287.                 ->scalarNode('sslkey')
  288.                     ->info(
  289.                         'The path to the SSL client key file for PostgreSQL.'
  290.                     )
  291.                 ->end()
  292.                 ->scalarNode('sslcrl')
  293.                     ->info(
  294.                         'The file name of the SSL certificate revocation list for PostgreSQL.'
  295.                     )
  296.                 ->end()
  297.                 ->booleanNode('pooled')->info('True to use a pooled server with the oci8/pdo_oracle driver')->end()
  298.                 ->booleanNode('MultipleActiveResultSets')->info('Configuring MultipleActiveResultSets for the pdo_sqlsrv driver')->end()
  299.                 ->booleanNode('use_savepoints')->info('Use savepoints for nested transactions')->end()
  300.                 ->scalarNode('instancename')
  301.                 ->info(
  302.                     'Optional parameter, complete whether to add the INSTANCE_NAME parameter in the connection.' .
  303.                     ' It is generally used to connect to an Oracle RAC server to select the name' .
  304.                     ' of a particular instance.'
  305.                 )
  306.                 ->end()
  307.                 ->scalarNode('connectstring')
  308.                 ->info(
  309.                     'Complete Easy Connect connection descriptor, see https://docs.oracle.com/database/121/NETAG/naming.htm.' .
  310.                     'When using this option, you will still need to provide the user and password parameters, but the other ' .
  311.                     'parameters will no longer be used. Note that when using this parameter, the getHost and getPort methods' .
  312.                     ' from Doctrine\DBAL\Connection will no longer function as expected.'
  313.                 )
  314.                 ->end()
  315.             ->end()
  316.             ->beforeNormalization()
  317.                 ->ifTrue(static function ($v) {
  318.                     return ! isset($v['sessionMode']) && isset($v['session_mode']);
  319.                 })
  320.                 ->then(static function ($v) {
  321.                     $v['sessionMode'] = $v['session_mode'];
  322.                     unset($v['session_mode']);
  323.                     return $v;
  324.                 })
  325.             ->end()
  326.             ->beforeNormalization()
  327.                 ->ifTrue(static function ($v) {
  328.                     return ! isset($v['MultipleActiveResultSets']) && isset($v['multiple_active_result_sets']);
  329.                 })
  330.                 ->then(static function ($v) {
  331.                     $v['MultipleActiveResultSets'] = $v['multiple_active_result_sets'];
  332.                     unset($v['multiple_active_result_sets']);
  333.                     return $v;
  334.                 })
  335.             ->end();
  336.     }
  337.     /**
  338.      * Add the ORM section to configuration tree
  339.      */
  340.     private function addOrmSection(ArrayNodeDefinition $node): void
  341.     {
  342.         $node
  343.             ->children()
  344.                 ->arrayNode('orm')
  345.                     ->beforeNormalization()
  346.                         ->ifTrue(static function ($v) {
  347.                             if (! empty($v) && ! class_exists(EntityManager::class)) {
  348.                                 throw new LogicException('The doctrine/orm package is required when the doctrine.orm config is set.');
  349.                             }
  350.                             return $v === null || (is_array($v) && ! array_key_exists('entity_managers'$v) && ! array_key_exists('entity_manager'$v));
  351.                         })
  352.                         ->then(static function ($v) {
  353.                             $v = (array) $v;
  354.                             // Key that should not be rewritten to the connection config
  355.                             $excludedKeys  = [
  356.                                 'default_entity_manager' => true,
  357.                                 'auto_generate_proxy_classes' => true,
  358.                                 'proxy_dir' => true,
  359.                                 'proxy_namespace' => true,
  360.                                 'resolve_target_entities' => true,
  361.                                 'resolve_target_entity' => true,
  362.                             ];
  363.                             $entityManager = [];
  364.                             foreach ($v as $key => $value) {
  365.                                 if (isset($excludedKeys[$key])) {
  366.                                     continue;
  367.                                 }
  368.                                 $entityManager[$key] = $v[$key];
  369.                                 unset($v[$key]);
  370.                             }
  371.                             $v['default_entity_manager'] = isset($v['default_entity_manager']) ? (string) $v['default_entity_manager'] : 'default';
  372.                             $v['entity_managers']        = [$v['default_entity_manager'] => $entityManager];
  373.                             return $v;
  374.                         })
  375.                     ->end()
  376.                     ->children()
  377.                         ->scalarNode('default_entity_manager')->end()
  378.                         ->scalarNode('auto_generate_proxy_classes')->defaultValue(false)
  379.                             ->info('Auto generate mode possible values are: "NEVER", "ALWAYS", "FILE_NOT_EXISTS", "EVAL"')
  380.                             ->validate()
  381.                                 ->ifTrue(function ($v) {
  382.                                     $generationModes $this->getAutoGenerateModes();
  383.                                     if (is_int($v) && in_array($v$generationModes['values']/*array(0, 1, 2, 3)*/)) {
  384.                                         return false;
  385.                                     }
  386.                                     if (is_bool($v)) {
  387.                                         return false;
  388.                                     }
  389.                                     if (is_string($v)) {
  390.                                         if (in_array(strtoupper($v), $generationModes['names']/*array('NEVER', 'ALWAYS', 'FILE_NOT_EXISTS', 'EVAL')*/)) {
  391.                                             return false;
  392.                                         }
  393.                                     }
  394.                                     return true;
  395.                                 })
  396.                                 ->thenInvalid('Invalid auto generate mode value %s')
  397.                             ->end()
  398.                             ->validate()
  399.                                 ->ifString()
  400.                                 ->then(static function ($v) {
  401.                                     return constant('Doctrine\Common\Proxy\AbstractProxyFactory::AUTOGENERATE_' strtoupper($v));
  402.                                 })
  403.                             ->end()
  404.                         ->end()
  405.                         ->scalarNode('proxy_dir')->defaultValue('%kernel.cache_dir%/doctrine/orm/Proxies')->end()
  406.                         ->scalarNode('proxy_namespace')->defaultValue('Proxies')->end()
  407.                     ->end()
  408.                     ->fixXmlConfig('entity_manager')
  409.                     ->append($this->getOrmEntityManagersNode())
  410.                     ->fixXmlConfig('resolve_target_entity''resolve_target_entities')
  411.                     ->append($this->getOrmTargetEntityResolverNode())
  412.                 ->end()
  413.             ->end();
  414.     }
  415.     /**
  416.      * Return ORM target entity resolver node
  417.      */
  418.     private function getOrmTargetEntityResolverNode(): NodeDefinition
  419.     {
  420.         $treeBuilder = new TreeBuilder('resolve_target_entities');
  421.         $node        $treeBuilder->getRootNode();
  422.         $node
  423.             ->useAttributeAsKey('interface')
  424.             ->prototype('scalar')
  425.                 ->cannotBeEmpty()
  426.             ->end();
  427.         return $node;
  428.     }
  429.     /**
  430.      * Return ORM entity listener node
  431.      */
  432.     private function getOrmEntityListenersNode(): NodeDefinition
  433.     {
  434.         $treeBuilder = new TreeBuilder('entity_listeners');
  435.         $node        $treeBuilder->getRootNode();
  436.         $normalizer = static function ($mappings) {
  437.             $entities = [];
  438.             foreach ($mappings as $entityClass => $mapping) {
  439.                 $listeners = [];
  440.                 foreach ($mapping as $listenerClass => $listenerEvent) {
  441.                     $events = [];
  442.                     foreach ($listenerEvent as $eventType => $eventMapping) {
  443.                         if ($eventMapping === null) {
  444.                             $eventMapping = [null];
  445.                         }
  446.                         foreach ($eventMapping as $method) {
  447.                             $events[] = [
  448.                                 'type' => $eventType,
  449.                                 'method' => $method,
  450.                             ];
  451.                         }
  452.                     }
  453.                     $listeners[] = [
  454.                         'class' => $listenerClass,
  455.                         'event' => $events,
  456.                     ];
  457.                 }
  458.                 $entities[] = [
  459.                     'class' => $entityClass,
  460.                     'listener' => $listeners,
  461.                 ];
  462.             }
  463.             return ['entities' => $entities];
  464.         };
  465.         $node
  466.             ->beforeNormalization()
  467.                 // Yaml normalization
  468.                 ->ifTrue(static function ($v) {
  469.                     return is_array(reset($v)) && is_string(key(reset($v)));
  470.                 })
  471.                 ->then($normalizer)
  472.             ->end()
  473.             ->fixXmlConfig('entity''entities')
  474.             ->children()
  475.                 ->arrayNode('entities')
  476.                     ->useAttributeAsKey('class')
  477.                     ->prototype('array')
  478.                         ->fixXmlConfig('listener')
  479.                         ->children()
  480.                             ->arrayNode('listeners')
  481.                                 ->useAttributeAsKey('class')
  482.                                 ->prototype('array')
  483.                                     ->fixXmlConfig('event')
  484.                                     ->children()
  485.                                         ->arrayNode('events')
  486.                                             ->prototype('array')
  487.                                                 ->children()
  488.                                                     ->scalarNode('type')->end()
  489.                                                     ->scalarNode('method')->defaultNull()->end()
  490.                                                 ->end()
  491.                                             ->end()
  492.                                         ->end()
  493.                                     ->end()
  494.                                 ->end()
  495.                             ->end()
  496.                         ->end()
  497.                     ->end()
  498.                 ->end()
  499.             ->end();
  500.         return $node;
  501.     }
  502.     /**
  503.      * Return ORM entity manager node
  504.      */
  505.     private function getOrmEntityManagersNode(): ArrayNodeDefinition
  506.     {
  507.         $treeBuilder = new TreeBuilder('entity_managers');
  508.         $node        $treeBuilder->getRootNode();
  509.         $node
  510.             ->requiresAtLeastOneElement()
  511.             ->useAttributeAsKey('name')
  512.             ->prototype('array')
  513.                 ->addDefaultsIfNotSet()
  514.                 ->append($this->getOrmCacheDriverNode('query_cache_driver'))
  515.                 ->append($this->getOrmCacheDriverNode('metadata_cache_driver'))
  516.                 ->append($this->getOrmCacheDriverNode('result_cache_driver'))
  517.                 ->append($this->getOrmEntityListenersNode())
  518.                 ->children()
  519.                     ->scalarNode('connection')->end()
  520.                     ->scalarNode('class_metadata_factory_name')->defaultValue('Doctrine\ORM\Mapping\ClassMetadataFactory')->end()
  521.                     ->scalarNode('default_repository_class')->defaultValue('Doctrine\ORM\EntityRepository')->end()
  522.                     ->scalarNode('auto_mapping')->defaultFalse()->end()
  523.                     ->scalarNode('naming_strategy')->defaultValue('doctrine.orm.naming_strategy.default')->end()
  524.                     ->scalarNode('quote_strategy')->defaultValue('doctrine.orm.quote_strategy.default')->end()
  525.                     ->scalarNode('entity_listener_resolver')->defaultNull()->end()
  526.                     ->scalarNode('repository_factory')->defaultValue('doctrine.orm.container_repository_factory')->end()
  527.                 ->end()
  528.                 ->children()
  529.                     ->arrayNode('second_level_cache')
  530.                         ->children()
  531.                             ->append($this->getOrmCacheDriverNode('region_cache_driver'))
  532.                             ->scalarNode('region_lock_lifetime')->defaultValue(60)->end()
  533.                             ->booleanNode('log_enabled')->defaultValue($this->debug)->end()
  534.                             ->scalarNode('region_lifetime')->defaultValue(3600)->end()
  535.                             ->booleanNode('enabled')->defaultValue(true)->end()
  536.                             ->scalarNode('factory')->end()
  537.                         ->end()
  538.                         ->fixXmlConfig('region')
  539.                         ->children()
  540.                             ->arrayNode('regions')
  541.                                 ->useAttributeAsKey('name')
  542.                                 ->prototype('array')
  543.                                     ->children()
  544.                                         ->append($this->getOrmCacheDriverNode('cache_driver'))
  545.                                         ->scalarNode('lock_path')->defaultValue('%kernel.cache_dir%/doctrine/orm/slc/filelock')->end()
  546.                                         ->scalarNode('lock_lifetime')->defaultValue(60)->end()
  547.                                         ->scalarNode('type')->defaultValue('default')->end()
  548.                                         ->scalarNode('lifetime')->defaultValue(0)->end()
  549.                                         ->scalarNode('service')->end()
  550.                                         ->scalarNode('name')->end()
  551.                                     ->end()
  552.                                 ->end()
  553.                             ->end()
  554.                         ->end()
  555.                         ->fixXmlConfig('logger')
  556.                         ->children()
  557.                             ->arrayNode('loggers')
  558.                                 ->useAttributeAsKey('name')
  559.                                 ->prototype('array')
  560.                                     ->children()
  561.                                         ->scalarNode('name')->end()
  562.                                         ->scalarNode('service')->end()
  563.                                     ->end()
  564.                                 ->end()
  565.                             ->end()
  566.                         ->end()
  567.                     ->end()
  568.                 ->end()
  569.                 ->fixXmlConfig('hydrator')
  570.                 ->children()
  571.                     ->arrayNode('hydrators')
  572.                         ->useAttributeAsKey('name')
  573.                         ->prototype('scalar')->end()
  574.                     ->end()
  575.                 ->end()
  576.                 ->fixXmlConfig('mapping')
  577.                 ->children()
  578.                     ->arrayNode('mappings')
  579.                         ->useAttributeAsKey('name')
  580.                         ->prototype('array')
  581.                             ->beforeNormalization()
  582.                                 ->ifString()
  583.                                 ->then(static function ($v) {
  584.                                     return ['type' => $v];
  585.                                 })
  586.                             ->end()
  587.                             ->treatNullLike([])
  588.                             ->treatFalseLike(['mapping' => false])
  589.                             ->performNoDeepMerging()
  590.                             ->children()
  591.                                 ->scalarNode('mapping')->defaultValue(true)->end()
  592.                                 ->scalarNode('type')->end()
  593.                                 ->scalarNode('dir')->end()
  594.                                 ->scalarNode('alias')->end()
  595.                                 ->scalarNode('prefix')->end()
  596.                                 ->booleanNode('is_bundle')->end()
  597.                             ->end()
  598.                         ->end()
  599.                     ->end()
  600.                     ->arrayNode('dql')
  601.                         ->fixXmlConfig('string_function')
  602.                         ->fixXmlConfig('numeric_function')
  603.                         ->fixXmlConfig('datetime_function')
  604.                         ->children()
  605.                             ->arrayNode('string_functions')
  606.                                 ->useAttributeAsKey('name')
  607.                                 ->prototype('scalar')->end()
  608.                             ->end()
  609.                             ->arrayNode('numeric_functions')
  610.                                 ->useAttributeAsKey('name')
  611.                                 ->prototype('scalar')->end()
  612.                             ->end()
  613.                             ->arrayNode('datetime_functions')
  614.                                 ->useAttributeAsKey('name')
  615.                                 ->prototype('scalar')->end()
  616.                             ->end()
  617.                         ->end()
  618.                     ->end()
  619.                 ->end()
  620.                 ->fixXmlConfig('filter')
  621.                 ->children()
  622.                     ->arrayNode('filters')
  623.                         ->info('Register SQL Filters in the entity manager')
  624.                         ->useAttributeAsKey('name')
  625.                         ->prototype('array')
  626.                             ->beforeNormalization()
  627.                                 ->ifString()
  628.                                 ->then(static function ($v) {
  629.                                     return ['class' => $v];
  630.                                 })
  631.                             ->end()
  632.                             ->beforeNormalization()
  633.                                 // The content of the XML node is returned as the "value" key so we need to rename it
  634.                                 ->ifTrue(static function ($v) {
  635.                                     return is_array($v) && isset($v['value']);
  636.                                 })
  637.                                 ->then(static function ($v) {
  638.                                     $v['class'] = $v['value'];
  639.                                     unset($v['value']);
  640.                                     return $v;
  641.                                 })
  642.                             ->end()
  643.                             ->fixXmlConfig('parameter')
  644.                             ->children()
  645.                                 ->scalarNode('class')->isRequired()->end()
  646.                                 ->booleanNode('enabled')->defaultFalse()->end()
  647.                                 ->arrayNode('parameters')
  648.                                     ->useAttributeAsKey('name')
  649.                                     ->prototype('variable')->end()
  650.                                 ->end()
  651.                             ->end()
  652.                         ->end()
  653.                     ->end()
  654.                 ->end()
  655.             ->end();
  656.         return $node;
  657.     }
  658.     /**
  659.      * Return a ORM cache driver node for an given entity manager
  660.      */
  661.     private function getOrmCacheDriverNode(string $name): ArrayNodeDefinition
  662.     {
  663.         $treeBuilder = new TreeBuilder($name);
  664.         $node        $treeBuilder->getRootNode();
  665.         $node
  666.             ->beforeNormalization()
  667.                 ->ifString()
  668.                 ->then(static function ($v): array {
  669.                     return ['type' => $v];
  670.                 })
  671.             ->end()
  672.             ->children()
  673.                 ->scalarNode('type')->defaultNull()->end()
  674.                 ->scalarNode('id')->end()
  675.                 ->scalarNode('pool')->end()
  676.             ->end();
  677.         if ($name === 'metadata_cache_driver') {
  678.             $node->setDeprecated(...$this->getDeprecationMsg(
  679.                 'The "metadata_cache_driver" configuration key is deprecated. Remove the configuration to have the cache created automatically.',
  680.                 '2.3'
  681.             ));
  682.         } else {
  683.             $node->addDefaultsIfNotSet();
  684.         }
  685.         return $node;
  686.     }
  687.     /**
  688.      * Find proxy auto generate modes for their names and int values
  689.      *
  690.      * @return array{names: list<string>, values: list<int>}
  691.      */
  692.     private function getAutoGenerateModes(): array
  693.     {
  694.         $constPrefix 'AUTOGENERATE_';
  695.         $prefixLen   strlen($constPrefix);
  696.         $refClass    = new ReflectionClass('Doctrine\Common\Proxy\AbstractProxyFactory');
  697.         $constsArray $refClass->getConstants();
  698.         $namesArray  = [];
  699.         $valuesArray = [];
  700.         foreach ($constsArray as $key => $value) {
  701.             if (strpos($key$constPrefix) !== 0) {
  702.                 continue;
  703.             }
  704.             $namesArray[]  = substr($key$prefixLen);
  705.             $valuesArray[] = (int) $value;
  706.         }
  707.         return [
  708.             'names' => $namesArray,
  709.             'values' => $valuesArray,
  710.         ];
  711.     }
  712.     /**
  713.      * Returns the correct deprecation param's as an array for setDeprecated.
  714.      *
  715.      * Symfony/Config v5.1 introduces a deprecation notice when calling
  716.      * setDeprecation() with less than 3 args and the getDeprecation method was
  717.      * introduced at the same time. By checking if getDeprecation() exists,
  718.      * we can determine the correct param count to use when calling setDeprecated.
  719.      *
  720.      * @return list<string>|array{0:string, 1: numeric-string, string}
  721.      */
  722.     private function getDeprecationMsg(string $messagestring $version): array
  723.     {
  724.         if (method_exists(BaseNode::class, 'getDeprecation')) {
  725.             return [
  726.                 'doctrine/doctrine-bundle',
  727.                 $version,
  728.                 $message,
  729.             ];
  730.         }
  731.         return [$message];
  732.     }
  733. }