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

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