Configuration.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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\ArrayNodeDefinition;
  12. use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  13. use Symfony\Component\Config\Definition\ConfigurationInterface;
  14. /**
  15. * This class contains the configuration information for the bundle
  16. *
  17. * This information is solely responsible for how the different configuration
  18. * sections are normalized, and merged.
  19. *
  20. * @author Christophe Coevoet <stof@notk.org>
  21. */
  22. class Configuration implements ConfigurationInterface
  23. {
  24. private $debug;
  25. /**
  26. * Constructor.
  27. *
  28. * @param Boolean $debug The kernel.debug value
  29. */
  30. public function __construct($debug)
  31. {
  32. $this->debug = (Boolean) $debug;
  33. }
  34. /**
  35. * Generates the configuration tree builder.
  36. *
  37. * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
  38. */
  39. public function getConfigTreeBuilder()
  40. {
  41. $treeBuilder = new TreeBuilder();
  42. $rootNode = $treeBuilder->root('swiftmailer');
  43. $rootNode
  44. ->children()
  45. ->scalarNode('transport')
  46. ->defaultValue('smtp')
  47. ->validate()
  48. ->ifNotInArray(array('smtp', 'mail', 'sendmail', 'gmail', null))
  49. ->thenInvalid('The %s transport is not supported')
  50. ->end()
  51. ->end()
  52. ->scalarNode('username')->defaultNull()->end()
  53. ->scalarNode('password')->defaultNull()->end()
  54. ->scalarNode('host')->defaultValue('localhost')->end()
  55. ->scalarNode('port')->defaultValue(false)->end()
  56. ->scalarNode('encryption')
  57. ->defaultNull()
  58. ->validate()
  59. ->ifNotInArray(array('tls', 'ssl', null))
  60. ->thenInvalid('The %s encryption is not supported')
  61. ->end()
  62. ->end()
  63. ->scalarNode('auth_mode')
  64. ->defaultNull()
  65. ->validate()
  66. ->ifNotInArray(array('plain', 'login', 'cram-md5', null))
  67. ->thenInvalid('The %s authentication mode is not supported')
  68. ->end()
  69. ->end()
  70. ->arrayNode('spool')
  71. ->children()
  72. ->scalarNode('type')->defaultValue('file')->end()
  73. ->scalarNode('path')->defaultValue('%kernel.cache_dir%/swiftmailer/spool')->end()
  74. ->end()
  75. ->end()
  76. ->scalarNode('delivery_address')->end()
  77. ->booleanNode('disable_delivery')->end()
  78. ->booleanNode('logging')->defaultValue($this->debug)->end()
  79. ->end()
  80. ;
  81. return $treeBuilder;
  82. }
  83. }