Configuration.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. use Symfony\Component\Config\Definition\ConfigurationInterface;
  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. * @author Christophe Coevoet <stof@notk.org>
  21. */
  22. class Configuration implements ConfigurationInterface
  23. {
  24. /**
  25. * Generates the configuration tree builder.
  26. *
  27. * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
  28. */
  29. public function getConfigTreeBuilder()
  30. {
  31. $treeBuilder = new TreeBuilder();
  32. $rootNode = $treeBuilder->root('monolog');
  33. $rootNode
  34. ->fixXmlConfig('handler')
  35. ->children()
  36. ->arrayNode('handlers')
  37. ->canBeUnset()
  38. ->useAttributeAsKey('name')
  39. ->prototype('array')
  40. ->fixXmlConfig('member')
  41. ->canBeUnset()
  42. ->children()
  43. ->scalarNode('type')
  44. ->isRequired()
  45. ->treatNullLike('null')
  46. ->beforeNormalization()
  47. ->always()
  48. ->then(function($v) { return strtolower($v); })
  49. ->end()
  50. ->end()
  51. ->scalarNode('id')->end()
  52. ->scalarNode('priority')->defaultValue(0)->end()
  53. ->scalarNode('level')->defaultValue('DEBUG')->end()
  54. ->booleanNode('bubble')->defaultTrue()->end()
  55. ->scalarNode('path')->defaultValue('%kernel.logs_dir%/%kernel.environment%.log')->end() // stream and rotating
  56. ->scalarNode('ident')->defaultFalse()->end() // syslog
  57. ->scalarNode('facility')->defaultValue('user')->end() // syslog
  58. ->scalarNode('max_files')->defaultValue(0)->end() // rotating
  59. ->scalarNode('action_level')->defaultValue('WARNING')->end() // fingers_crossed
  60. ->booleanNode('stop_buffering')->defaultTrue()->end()// fingers_crossed
  61. ->scalarNode('buffer_size')->defaultValue(0)->end() // fingers_crossed and buffer
  62. ->scalarNode('handler')->end() // fingers_crossed and buffer
  63. ->arrayNode('members') // group
  64. ->canBeUnset()
  65. ->performNoDeepMerging()
  66. ->prototype('scalar')->end()
  67. ->end()
  68. ->scalarNode('from_email')->end() // swift_mailer and native_mailer
  69. ->scalarNode('to_email')->end() // swift_mailer and native_mailer
  70. ->scalarNode('subject')->end() // swift_mailer and native_mailer
  71. ->arrayNode('email_prototype') // swift_mailer
  72. ->canBeUnset()
  73. ->beforeNormalization()
  74. ->ifString()
  75. ->then(function($v) { return array('id' => $v); })
  76. ->end()
  77. ->children()
  78. ->scalarNode('id')->isRequired()->end()
  79. ->scalarNode('factory-method')->defaultNull()->end()
  80. ->end()
  81. ->end()
  82. ->scalarNode('formatter')->end()
  83. ->end()
  84. ->validate()
  85. ->ifTrue(function($v) { return ('fingers_crossed' === $v['type'] || 'buffer' === $v['type']) && 1 !== count($v['handler']); })
  86. ->thenInvalid('The handler has to be specified to use a FingersCrossedHandler or BufferHandler')
  87. ->end()
  88. ->validate()
  89. ->ifTrue(function($v) { return 'swift_mailer' === $v['type'] && empty($v['email_prototype']) && (empty($v['from_email']) || empty($v['to_email']) || empty($v['subject'])); })
  90. ->thenInvalid('The sender, recipient and subject or an email prototype have to be specified to use a SwiftMailerHandler')
  91. ->end()
  92. ->validate()
  93. ->ifTrue(function($v) { return 'native_mailer' === $v['type'] && (empty($v['from_email']) || empty($v['to_email']) || empty($v['subject'])); })
  94. ->thenInvalid('The sender, recipient and subject have to be specified to use a NativeMailerHandler')
  95. ->end()
  96. ->validate()
  97. ->ifTrue(function($v) { return 'service' === $v['type'] && !isset($v['id']); })
  98. ->thenInvalid('The id has to be specified to use a service as handler')
  99. ->end()
  100. ->end()
  101. ->validate()
  102. ->ifTrue(function($v) { return isset($v['debug']); })
  103. ->thenInvalid('The "debug" name cannot be used as it is reserved for the handler of the profiler')
  104. ->end()
  105. ->end()
  106. ->end()
  107. ;
  108. return $treeBuilder;
  109. }
  110. }