vendor/twig/extra-bundle/DependencyInjection/Configuration.php line 30

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of Twig.
  4. *
  5. * (c) Fabien Potencier
  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 Twig\Extra\TwigExtraBundle\DependencyInjection;
  11. use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
  12. use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  13. use Symfony\Component\Config\Definition\ConfigurationInterface;
  14. use Twig\Extra\TwigExtraBundle\Extensions;
  15. class Configuration implements ConfigurationInterface
  16. {
  17. public function getConfigTreeBuilder(): TreeBuilder
  18. {
  19. $treeBuilder = new TreeBuilder('twig_extra');
  20. $rootNode = $treeBuilder->getRootNode();
  21. foreach (Extensions::getClasses() as $name => $class) {
  22. $rootNode
  23. ->children()
  24. ->arrayNode($name)
  25. ->{class_exists($class) ? 'canBeDisabled' : 'canBeEnabled'}()
  26. ->end()
  27. ->end()
  28. ;
  29. }
  30. $this->addCommonMarkConfiguration($rootNode);
  31. return $treeBuilder;
  32. }
  33. /**
  34. * Full configuration from {@link https://commonmark.thephpleague.com/2.7/configuration}.
  35. */
  36. private function addCommonMarkConfiguration(ArrayNodeDefinition $rootNode): void
  37. {
  38. $rootNode
  39. ->children()
  40. ->arrayNode('commonmark')
  41. ->ignoreExtraKeys(false)
  42. ->children()
  43. ->arrayNode('renderer')
  44. ->info('Array of options for rendering HTML.')
  45. ->children()
  46. ->scalarNode('block_separator')->end()
  47. ->scalarNode('inner_separator')->end()
  48. ->scalarNode('soft_break')->end()
  49. ->end()
  50. ->end()
  51. ->enumNode('html_input')
  52. ->info('How to handle HTML input.')
  53. ->values(['strip', 'allow', 'escape'])
  54. ->end()
  55. ->booleanNode('allow_unsafe_links')
  56. ->info('Remove risky link and image URLs by setting this to false.')
  57. ->defaultTrue()
  58. ->end()
  59. ->integerNode('max_nesting_level')
  60. ->info('The maximum nesting level for blocks.')
  61. ->defaultValue(\PHP_INT_MAX)
  62. ->end()
  63. ->integerNode('max_delimiters_per_line')
  64. ->info('The maximum number of strong/emphasis delimiters per line.')
  65. ->defaultValue(\PHP_INT_MAX)
  66. ->end()
  67. ->arrayNode('slug_normalizer')
  68. ->info('Array of options for configuring how URL-safe slugs are created.')
  69. ->children()
  70. ->variableNode('instance')->end()
  71. ->integerNode('max_length')->defaultValue(255)->end()
  72. ->variableNode('unique')->end()
  73. ->end()
  74. ->end()
  75. ->arrayNode('commonmark')
  76. ->info('Array of options for configuring the CommonMark core extension.')
  77. ->children()
  78. ->booleanNode('enable_em')->defaultTrue()->end()
  79. ->booleanNode('enable_strong')->defaultTrue()->end()
  80. ->booleanNode('use_asterisk')->defaultTrue()->end()
  81. ->booleanNode('use_underscore')->defaultTrue()->end()
  82. ->arrayNode('unordered_list_markers')
  83. ->scalarPrototype()->end()
  84. ->defaultValue([['-', '*', '+']])->end()
  85. ->end()
  86. ->end()
  87. ->end()
  88. ->end()
  89. ->end();
  90. }
  91. }