Configuration.php 101 KB

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