ExampleConfiguration.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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\Component\Config\Tests\Fixtures\Configuration;
  11. use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  12. use Symfony\Component\Config\Definition\ConfigurationInterface;
  13. class ExampleConfiguration implements ConfigurationInterface
  14. {
  15. public function getConfigTreeBuilder()
  16. {
  17. $treeBuilder = new TreeBuilder('acme_root');
  18. $treeBuilder->getRootNode()
  19. ->fixXmlConfig('parameter')
  20. ->fixXmlConfig('connection')
  21. ->fixXmlConfig('cms_page')
  22. ->children()
  23. ->booleanNode('boolean')->defaultTrue()->end()
  24. ->scalarNode('scalar_empty')->end()
  25. ->scalarNode('scalar_null')->defaultNull()->end()
  26. ->scalarNode('scalar_true')->defaultTrue()->end()
  27. ->scalarNode('scalar_false')->defaultFalse()->end()
  28. ->scalarNode('scalar_default')->defaultValue('default')->end()
  29. ->scalarNode('scalar_array_empty')->defaultValue([])->end()
  30. ->scalarNode('scalar_array_defaults')->defaultValue(['elem1', 'elem2'])->end()
  31. ->scalarNode('scalar_required')->isRequired()->end()
  32. ->scalarNode('scalar_deprecated')->setDeprecated()->end()
  33. ->scalarNode('scalar_deprecated_with_message')->setDeprecated('Deprecation custom message for "%node%" at "%path%"')->end()
  34. ->scalarNode('node_with_a_looong_name')->end()
  35. ->enumNode('enum_with_default')->values(['this', 'that'])->defaultValue('this')->end()
  36. ->enumNode('enum')->values(['this', 'that'])->end()
  37. ->arrayNode('array')
  38. ->info('some info')
  39. ->canBeUnset()
  40. ->children()
  41. ->scalarNode('child1')->end()
  42. ->scalarNode('child2')->end()
  43. ->scalarNode('child3')
  44. ->info(
  45. "this is a long\n".
  46. "multi-line info text\n".
  47. 'which should be indented'
  48. )
  49. ->example('example setting')
  50. ->end()
  51. ->end()
  52. ->end()
  53. ->arrayNode('scalar_prototyped')
  54. ->prototype('scalar')->end()
  55. ->end()
  56. ->arrayNode('parameters')
  57. ->useAttributeAsKey('name')
  58. ->prototype('scalar')->info('Parameter name')->end()
  59. ->end()
  60. ->arrayNode('connections')
  61. ->prototype('array')
  62. ->children()
  63. ->scalarNode('user')->end()
  64. ->scalarNode('pass')->end()
  65. ->end()
  66. ->end()
  67. ->end()
  68. ->arrayNode('cms_pages')
  69. ->useAttributeAsKey('page')
  70. ->prototype('array')
  71. ->useAttributeAsKey('locale')
  72. ->prototype('array')
  73. ->children()
  74. ->scalarNode('title')->isRequired()->end()
  75. ->scalarNode('path')->isRequired()->end()
  76. ->end()
  77. ->end()
  78. ->end()
  79. ->end()
  80. ->arrayNode('pipou')
  81. ->useAttributeAsKey('name')
  82. ->prototype('array')
  83. ->prototype('array')
  84. ->children()
  85. ->scalarNode('didou')
  86. ->end()
  87. ->end()
  88. ->end()
  89. ->end()
  90. ->end()
  91. ->end()
  92. ;
  93. return $treeBuilder;
  94. }
  95. }