Configuration.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.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\AsseticBundle\DependencyInjection;
  11. use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  12. /**
  13. * This class contains the configuration information for the bundle
  14. *
  15. * This information is solely responsible for how the different configuration
  16. * sections are normalized, and merged.
  17. *
  18. * @author Christophe Coevoet <stof@notk.org>
  19. */
  20. class Configuration
  21. {
  22. /**
  23. * Generates the configuration tree.
  24. *
  25. * @return Symfony\Component\Config\Definition\NodeInterface The config tree
  26. */
  27. public function getConfigTree($debug, $bundles)
  28. {
  29. $tree = new TreeBuilder();
  30. $tree->root('assetic', 'array')
  31. ->booleanNode('debug')->defaultValue($debug)->end()
  32. ->booleanNode('use_controller')->defaultValue($debug)->end()
  33. ->scalarNode('read_from')->defaultValue('%kernel.root_dir%/../web')->end()
  34. ->scalarNode('write_to')->defaultValue('%assetic.read_from%')->end()
  35. ->scalarNode('closure')->end()
  36. ->scalarNode('yui')->end()
  37. ->scalarNode('default_javascripts_output')->defaultValue('js/*.js')->end()
  38. ->scalarNode('default_stylesheets_output')->defaultValue('css/*.css')->end()
  39. ->fixXmlConfig('bundle')
  40. ->arrayNode('bundles')
  41. ->defaultValue($bundles)
  42. ->requiresAtLeastOneElement()
  43. ->beforeNormalization()
  44. ->ifTrue(function($v){ return !is_array($v); })
  45. ->then(function($v){ return array($v); })
  46. ->end()
  47. ->prototype('scalar')
  48. ->beforeNormalization()
  49. ->ifTrue(function($v) { return is_array($v) && isset($v['name']); })
  50. ->then(function($v){ return $v['name']; })
  51. ->end()
  52. ->end()
  53. ->end();
  54. return $tree->buildTree();
  55. }
  56. }