Configuration.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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\MonologBundle\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 Jordi Boggiano <j.boggiano@seld.be>
  19. * @author Christophe Coevoet <stof@notk.org>
  20. */
  21. class Configuration
  22. {
  23. /**
  24. * Generates the configuration tree.
  25. *
  26. * @return \Symfony\Component\Config\Definition\NodeInterface
  27. */
  28. public function getConfigTree()
  29. {
  30. $treeBuilder = new TreeBuilder();
  31. $rootNode = $treeBuilder->root('monolog');
  32. $rootNode
  33. ->fixXmlConfig('handler')
  34. ->fixXmlConfig('processor')
  35. ->children()
  36. ->arrayNode('handlers')
  37. ->canBeUnset()
  38. ->performNoDeepMerging()
  39. ->useAttributeAsKey('name')
  40. ->prototype('array')
  41. ->children()
  42. ->scalarNode('type')
  43. ->isRequired()
  44. ->treatNullLike('null')
  45. ->beforeNormalization()
  46. ->always()
  47. ->then(function($v) { return strtolower($v); })
  48. ->end()
  49. ->end()
  50. ->scalarNode('id')->end()
  51. ->scalarNode('level')->defaultValue('DEBUG')->end()
  52. ->booleanNode('bubble')->defaultFalse()->end()
  53. ->scalarNode('path')->end() // stream specific
  54. ->scalarNode('action_level')->end() // fingerscrossed specific
  55. ->scalarNode('buffer_size')->end() // fingerscrossed specific
  56. ->scalarNode('handler')->end() // fingerscrossed specific
  57. ->scalarNode('formatter')->end()
  58. ->end()
  59. ->append($this->getProcessorsNode())
  60. ->validate()
  61. ->ifTrue(function($v) { return 'fingerscrossed' === $v['type'] && !isset($v['handler']); })
  62. ->thenInvalid('The handler has to be specified to use a FingersCrossedHandler')
  63. ->end()
  64. ->validate()
  65. ->ifTrue(function($v) { return 'service' === $v['type'] && !isset($v['id']); })
  66. ->thenInvalid('The id has to be specified to use a service as handler')
  67. ->end()
  68. ->end()
  69. ->validate()
  70. ->ifTrue(function($v) { return isset($v['debug']); })
  71. ->thenInvalid('The "debug" name cannot be used as it is reserved for the handler of the profiler')
  72. ->end()
  73. ->end()
  74. ->end()
  75. ->append($this->getProcessorsNode())
  76. ;
  77. return $treeBuilder->buildTree();
  78. }
  79. private function getProcessorsNode()
  80. {
  81. $treeBuilder = new TreeBuilder();
  82. $node = $treeBuilder->root('processors');
  83. $node
  84. ->canBeUnset()
  85. ->performNoDeepMerging()
  86. ->prototype('scalar')
  87. ->beforeNormalization()
  88. ->ifTrue(function($v) { return is_array($v) && isset($v['callback']); })
  89. ->then(function($v){ return $v['callback']; })
  90. ->end()
  91. ->end()
  92. ;
  93. return $node;
  94. }
  95. }