Configuration.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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\SwiftmailerBundle\DependencyInjection;
  11. use Symfony\Component\DependencyInjection\Configuration\Builder\NodeBuilder;
  12. use Symfony\Component\DependencyInjection\Configuration\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. * @return \Symfony\Component\DependencyInjection\Configuration\NodeInterface
  27. */
  28. public function getConfigTree()
  29. {
  30. $treeBuilder = new TreeBuilder();
  31. $rootNode = $treeBuilder->root('swiftmailer', 'array');
  32. $rootNode
  33. ->scalarNode('transport')
  34. ->defaultValue('smtp')
  35. ->validate()
  36. ->ifNotInArray(array ('smtp', 'mail', 'sendmail', 'gmail'))
  37. ->thenInvalid('The %s transport is not supported')
  38. ->end()
  39. ->end()
  40. ->scalarNode('username')->defaultNull()->end()
  41. ->scalarNode('password')->defaultNull()->end()
  42. ->scalarNode('host')->defaultValue('localhost')->end()
  43. ->scalarNode('port')->defaultValue(25)->end()
  44. ->scalarNode('encryption')
  45. ->defaultNull()
  46. ->validate()
  47. ->ifNotInArray(array ('tls', 'ssl', null))
  48. ->thenInvalid('The %s encryption is not supported')
  49. ->end()
  50. ->end()
  51. ->scalarNode('auth_mode')
  52. ->defaultNull()
  53. ->validate()
  54. ->ifNotInArray(array ('plain', 'login', 'cram-md5', null))
  55. ->thenInvalid('The %s authentication mode is not supported')
  56. ->end()
  57. ->end()
  58. ->arrayNode('spool')
  59. ->addDefaultsIfNotSet()
  60. ->scalarNode('type')->defaultValue('file')->end()
  61. ->scalarNode('path')->defaultValue('%kernel.cache_dir%/swiftmailer/pool')->end()
  62. ->end()
  63. ->scalarNode('delivery_adress')->end()
  64. ->booleanNode('disable_delivery')->end();
  65. return $treeBuilder->buildTree();
  66. }
  67. }