Configuration.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /*
  3. * This file is part of the Sonata project.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  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 Sonata\BaseApplicationBundle\DependencyInjection;
  11. use Symfony\Component\Config\Definition\Builder;
  12. use Symfony\Component\Config\Definition\Builder\NodeBuilder;
  13. use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  14. /**
  15. * This class contains the configuration information for the bundle
  16. *
  17. * This information is solely responsible for how the different configuration
  18. * sections are normalized, and merged.
  19. *
  20. * @author Michael Williams <mtotheikle@gmail.com>
  21. */
  22. class Configuration
  23. {
  24. /**
  25. * Generates the configuration tree.
  26. *
  27. * @return \Symfony\Component\Config\Definition\NodeInterface
  28. */
  29. public function getConfigTree($kernelDebug)
  30. {
  31. $treeBuilder = new TreeBuilder();
  32. $rootNode = $treeBuilder->root('sonata_base_application', 'array');
  33. $rootNode
  34. ->arrayNode('entities')
  35. ->isRequired()
  36. ->useAttributeAsKey('entity_name')
  37. ->requiresAtLeastOneElement()
  38. ->prototype('array')
  39. ->scalarNode('label')->cannotBeEmpty()->defaultValue('default')->end()
  40. ->scalarNode('group')->cannotBeEmpty()->defaultValue('default')->end()
  41. ->scalarNode('class')->isRequired()->cannotBeEmpty()->end()
  42. ->scalarNode('entity')->isRequired()->cannotBeEmpty()->end()
  43. ->scalarNode('controller')->isRequired()->end()
  44. ->arrayNode('children')
  45. ->useAttributeAsKey('entity_name')
  46. ->prototype('array')
  47. ->scalarNode('label')->cannotBeEmpty()->defaultValue('default')->end()
  48. ->scalarNode('group')->cannotBeEmpty()->defaultValue('default')->end()
  49. ->scalarNode('class')->isRequired()->cannotBeEmpty()->end()
  50. ->scalarNode('entity')->isRequired()->cannotBeEmpty()->end()
  51. ->scalarNode('controller')->isRequired()->end()
  52. ->end()
  53. ->end()
  54. ->arrayNode('options')
  55. ->addDefaultsIfNotSet()
  56. ->booleanNode('show_in_dashboard')->defaultTrue()->end()
  57. ->end()
  58. ->end()
  59. ->end()
  60. ->arrayNode('templates')
  61. ->scalarNode('layout')->cannotBeEmpty()->end()
  62. ->scalarNode('ajax')->cannotBeEmpty()->end()
  63. ->end();
  64. return $treeBuilder->buildTree();
  65. }
  66. }