Configuration.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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\MonologBundle\DependencyInjection;
  11. use Symfony\Component\Config\Definition\Builder\NodeBuilder;
  12. use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  13. /**
  14. * This class contains the configuration information for the bundle
  15. *
  16. * This information is solely responsible for how the different configuration
  17. * sections are normalized, and merged.
  18. *
  19. * @author Jordi Boggiano <j.boggiano@seld.be>
  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', 'array');
  32. $handlersPrototype = $rootNode
  33. ->fixXmlConfig('handler')
  34. ->arrayNode('handlers')
  35. ->canBeUnset()
  36. ->performNoDeepMerging()
  37. ->useAttributeAsKey('name')
  38. ->prototype('array')
  39. ->scalarNode('action_level')->end() // fingerscrossed specific
  40. ->scalarNode('buffer_size')->end() // fingerscrossed specific
  41. ->builder($this->getHandlerSubnode())
  42. ->validate()
  43. ->ifTrue(function($v) { return 'fingerscrossed' === $v['type'] && !isset($v['handler']); })
  44. ->thenInvalid('The handler has to be specified to use a FingersCrossedHandler')
  45. ->end()
  46. ;
  47. $this->addHandlerSection($handlersPrototype);
  48. return $treeBuilder->buildTree();
  49. }
  50. private function addHandlerSection(NodeBuilder $node)
  51. {
  52. $node
  53. ->performNoDeepMerging()
  54. ->scalarNode('type')
  55. ->isRequired()
  56. ->treatNullLike('null')
  57. ->beforeNormalization()
  58. ->always()
  59. ->then(function($v) { return strtolower($v); })
  60. ->end()
  61. ->end()
  62. ->scalarNode('level')->defaultValue('DEBUG')->end()
  63. ->booleanNode('bubble')->defaultFalse()->end()
  64. ->scalarNode('path')->end() // stream specific
  65. ->validate()
  66. ->ifTrue(function($v) { return 'stream' === $v['type'] && !isset($v['path']); })
  67. ->thenInvalid('The path has to be specified to use a StreamHandler')
  68. ->end()
  69. ;
  70. }
  71. private function getHandlerSubnode()
  72. {
  73. $node = new NodeBuilder('handler', 'array');
  74. $this->addHandlerSection($node);
  75. return $node;
  76. }
  77. }