Configuration.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. /**
  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
  22. {
  23. /**
  24. * Generates the configuration tree.
  25. *
  26. * @param Boolean $kernelDebug
  27. *
  28. * @return \Symfony\Component\Config\Definition\ArrayNode The config tree
  29. */
  30. public function getConfigTree($kernelDebug)
  31. {
  32. $treeBuilder = new TreeBuilder();
  33. $rootNode = $treeBuilder->root('swiftmailer');
  34. $rootNode
  35. ->children()
  36. ->scalarNode('transport')
  37. ->defaultValue('smtp')
  38. ->validate()
  39. ->ifNotInArray(array ('smtp', 'mail', 'sendmail', 'gmail', null))
  40. ->thenInvalid('The %s transport is not supported')
  41. ->end()
  42. ->end()
  43. ->scalarNode('username')->defaultNull()->end()
  44. ->scalarNode('password')->defaultNull()->end()
  45. ->scalarNode('host')->defaultValue('localhost')->end()
  46. ->scalarNode('port')->defaultValue(false)->end()
  47. ->scalarNode('encryption')
  48. ->defaultNull()
  49. ->validate()
  50. ->ifNotInArray(array ('tls', 'ssl', null))
  51. ->thenInvalid('The %s encryption is not supported')
  52. ->end()
  53. ->end()
  54. ->scalarNode('auth_mode')
  55. ->defaultNull()
  56. ->validate()
  57. ->ifNotInArray(array ('plain', 'login', 'cram-md5', null))
  58. ->thenInvalid('The %s authentication mode is not supported')
  59. ->end()
  60. ->end()
  61. ->arrayNode('spool')
  62. ->children()
  63. ->scalarNode('type')->defaultValue('file')->end()
  64. ->scalarNode('path')->defaultValue('%kernel.cache_dir%/swiftmailer/spool')->end()
  65. ->end()
  66. ->end()
  67. ->scalarNode('delivery_address')->end()
  68. ->booleanNode('disable_delivery')->end()
  69. ->booleanNode('logging')->defaultValue($kernelDebug)->end()
  70. ->end()
  71. ;
  72. return $treeBuilder->buildTree();
  73. }
  74. }