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

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