Configuration.php 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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\SwiftmailerBundle\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 Christophe Coevoet <stof@notk.org>
  20. */
  21. class Configuration implements ConfigurationInterface
  22. {
  23. private $debug;
  24. /**
  25. * Constructor.
  26. *
  27. * @param Boolean $debug The kernel.debug value
  28. */
  29. public function __construct($debug)
  30. {
  31. $this->debug = (Boolean) $debug;
  32. }
  33. /**
  34. * Generates the configuration tree builder.
  35. *
  36. * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
  37. */
  38. public function getConfigTreeBuilder()
  39. {
  40. $treeBuilder = new TreeBuilder();
  41. $rootNode = $treeBuilder->root('swiftmailer');
  42. $rootNode
  43. ->children()
  44. ->scalarNode('transport')->defaultValue('smtp')->end()
  45. ->scalarNode('username')->defaultNull()->end()
  46. ->scalarNode('password')->defaultNull()->end()
  47. ->scalarNode('host')->defaultValue('localhost')->end()
  48. ->scalarNode('port')->defaultFalse()->end()
  49. ->scalarNode('timeout')->defaultValue(30)->end()
  50. ->scalarNode('source_ip')->defaultNull()->end()
  51. ->scalarNode('encryption')
  52. ->defaultNull()
  53. ->validate()
  54. ->ifNotInArray(array('tls', 'ssl', null))
  55. ->thenInvalid('The %s encryption is not supported')
  56. ->end()
  57. ->end()
  58. ->scalarNode('auth_mode')
  59. ->defaultNull()
  60. ->validate()
  61. ->ifNotInArray(array('plain', 'login', 'cram-md5', null))
  62. ->thenInvalid('The %s authentication mode is not supported')
  63. ->end()
  64. ->end()
  65. ->arrayNode('spool')
  66. ->children()
  67. ->scalarNode('type')->defaultValue('file')->end()
  68. ->scalarNode('path')->defaultValue('%kernel.cache_dir%/swiftmailer/spool')->end()
  69. ->end()
  70. ->end()
  71. ->scalarNode('sender_address')->end()
  72. ->arrayNode('antiflood')
  73. ->children()
  74. ->scalarNode('threshold')->defaultValue(99)->end()
  75. ->scalarNode('sleep')->defaultValue(0)->end()
  76. ->end()
  77. ->end()
  78. ->scalarNode('delivery_address')->end()
  79. ->end()
  80. ->fixXmlConfig('delivery_whitelist_pattern', 'delivery_whitelist')
  81. ->children()
  82. ->arrayNode('delivery_whitelist')
  83. ->prototype('scalar')
  84. ->end()
  85. ->end()
  86. ->booleanNode('disable_delivery')->end()
  87. ->booleanNode('logging')->defaultValue($this->debug)->end()
  88. ->end()
  89. ;
  90. return $treeBuilder;
  91. }
  92. }