PageRenderTime 25ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/bundles/FOS/UserBundle/DependencyInjection/Configuration.php

https://bitbucket.org/Leimz/leimzwebsite
PHP | 275 lines | 238 code | 15 blank | 22 comment | 4 complexity | 8a9d1137ef02540f65f05d032a8f6e67 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1, LGPL-3.0, BSD-2-Clause, BSD-3-Clause
  1. <?php
  2. /*
  3. * This file is part of the FOSUserBundle package.
  4. *
  5. * (c) FriendsOfSymfony <http://friendsofsymfony.github.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 FOS\UserBundle\DependencyInjection;
  11. use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  12. use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
  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. /**
  25. * Generates the configuration tree.
  26. *
  27. * @return TreeBuilder
  28. */
  29. public function getConfigTreeBuilder()
  30. {
  31. $treeBuilder = new TreeBuilder();
  32. $rootNode = $treeBuilder->root('fos_user');
  33. $supportedDrivers = array('orm', 'mongodb', 'couchdb', 'propel', 'custom');
  34. $rootNode
  35. ->validate()
  36. ->ifTrue(function($v){return 'propel' === $v['db_driver'] && empty($v['propel_user_class']);})
  37. ->thenInvalid('The propel model class must be defined by using the "propel_user_class" key.')
  38. ->end()
  39. ->children()
  40. ->scalarNode('db_driver')
  41. ->validate()
  42. ->ifNotInArray($supportedDrivers)
  43. ->thenInvalid('The driver %s is not supported. Please choose one of '.json_encode($supportedDrivers))
  44. ->end()
  45. ->cannotBeOverwritten()
  46. ->isRequired()
  47. ->cannotBeEmpty()
  48. ->end()
  49. ->scalarNode('user_class')->isRequired()->cannotBeEmpty()->end()
  50. ->scalarNode('propel_user_class')->end()
  51. ->scalarNode('firewall_name')->isRequired()->cannotBeEmpty()->end()
  52. ->scalarNode('model_manager_name')->defaultNull()->end()
  53. ->booleanNode('use_listener')->defaultTrue()->end()
  54. ->booleanNode('use_username_form_type')->defaultTrue()->end()
  55. ->arrayNode('from_email')
  56. ->addDefaultsIfNotSet()
  57. ->children()
  58. ->scalarNode('address')->defaultValue('webmaster@example.com')->cannotBeEmpty()->end()
  59. ->scalarNode('sender_name')->defaultValue('webmaster')->cannotBeEmpty()->end()
  60. ->end()
  61. ->end()
  62. ->end()
  63. // Using the custom driver requires changing the manager services
  64. ->validate()
  65. ->ifTrue(function($v){return 'custom' === $v['db_driver'] && 'fos_user.user_manager.default' === $v['service']['user_manager'];})
  66. ->thenInvalid('You need to specify your own user manager service when using the "custom" driver.')
  67. ->end()
  68. ->validate()
  69. ->ifTrue(function($v){return 'custom' === $v['db_driver'] && !empty($v['group']) && 'fos_user.group_manager.default' === $v['group']['group_manager'];})
  70. ->thenInvalid('You need to specify your own group manager service when using the "custom" driver.')
  71. ->end();
  72. $this->addProfileSection($rootNode);
  73. $this->addChangePasswordSection($rootNode);
  74. $this->addRegistrationSection($rootNode);
  75. $this->addResettingSection($rootNode);
  76. $this->addServiceSection($rootNode);
  77. $this->addTemplateSection($rootNode);
  78. $this->addGroupSection($rootNode);
  79. return $treeBuilder;
  80. }
  81. private function addProfileSection(ArrayNodeDefinition $node)
  82. {
  83. $node
  84. ->children()
  85. ->arrayNode('profile')
  86. ->addDefaultsIfNotSet()
  87. ->canBeUnset()
  88. ->children()
  89. ->arrayNode('form')
  90. ->addDefaultsIfNotSet()
  91. ->children()
  92. ->scalarNode('type')->defaultValue('fos_user_profile')->end()
  93. ->scalarNode('handler')->defaultValue('fos_user.profile.form.handler.default')->end()
  94. ->scalarNode('name')->defaultValue('fos_user_profile_form')->cannotBeEmpty()->end()
  95. ->arrayNode('validation_groups')
  96. ->prototype('scalar')->end()
  97. ->defaultValue(array('Profile', 'Default'))
  98. ->end()
  99. ->end()
  100. ->end()
  101. ->end()
  102. ->end()
  103. ->end();
  104. }
  105. private function addRegistrationSection(ArrayNodeDefinition $node)
  106. {
  107. $node
  108. ->children()
  109. ->arrayNode('registration')
  110. ->addDefaultsIfNotSet()
  111. ->canBeUnset()
  112. ->children()
  113. ->arrayNode('confirmation')
  114. ->addDefaultsIfNotSet()
  115. ->children()
  116. ->booleanNode('enabled')->defaultFalse()->end()
  117. ->scalarNode('template')->defaultValue('FOSUserBundle:Registration:email.txt.twig')->end()
  118. ->arrayNode('from_email')
  119. ->canBeUnset()
  120. ->children()
  121. ->scalarNode('address')->isRequired()->cannotBeEmpty()->end()
  122. ->scalarNode('sender_name')->isRequired()->cannotBeEmpty()->end()
  123. ->end()
  124. ->end()
  125. ->end()
  126. ->end()
  127. ->arrayNode('form')
  128. ->addDefaultsIfNotSet()
  129. ->children()
  130. ->scalarNode('type')->defaultValue('fos_user_registration')->end()
  131. ->scalarNode('handler')->defaultValue('fos_user.registration.form.handler.default')->end()
  132. ->scalarNode('name')->defaultValue('fos_user_registration_form')->cannotBeEmpty()->end()
  133. ->arrayNode('validation_groups')
  134. ->prototype('scalar')->end()
  135. ->defaultValue(array('Registration', 'Default'))
  136. ->end()
  137. ->end()
  138. ->end()
  139. ->end()
  140. ->end()
  141. ->end();
  142. }
  143. private function addResettingSection(ArrayNodeDefinition $node)
  144. {
  145. $node
  146. ->children()
  147. ->arrayNode('resetting')
  148. ->addDefaultsIfNotSet()
  149. ->canBeUnset()
  150. ->children()
  151. ->scalarNode('token_ttl')->defaultValue(86400)->end()
  152. ->arrayNode('email')
  153. ->addDefaultsIfNotSet()
  154. ->children()
  155. ->scalarNode('template')->defaultValue('FOSUserBundle:Resetting:email.txt.twig')->end()
  156. ->arrayNode('from_email')
  157. ->canBeUnset()
  158. ->children()
  159. ->scalarNode('address')->isRequired()->cannotBeEmpty()->end()
  160. ->scalarNode('sender_name')->isRequired()->cannotBeEmpty()->end()
  161. ->end()
  162. ->end()
  163. ->end()
  164. ->end()
  165. ->arrayNode('form')
  166. ->addDefaultsIfNotSet()
  167. ->children()
  168. ->scalarNode('type')->defaultValue('fos_user_resetting')->end()
  169. ->scalarNode('handler')->defaultValue('fos_user.resetting.form.handler.default')->end()
  170. ->scalarNode('name')->defaultValue('fos_user_resetting_form')->cannotBeEmpty()->end()
  171. ->arrayNode('validation_groups')
  172. ->prototype('scalar')->end()
  173. ->defaultValue(array('ResetPassword', 'Default'))
  174. ->end()
  175. ->end()
  176. ->end()
  177. ->end()
  178. ->end()
  179. ->end();
  180. }
  181. private function addChangePasswordSection(ArrayNodeDefinition $node)
  182. {
  183. $node
  184. ->children()
  185. ->arrayNode('change_password')
  186. ->addDefaultsIfNotSet()
  187. ->canBeUnset()
  188. ->children()
  189. ->arrayNode('form')
  190. ->addDefaultsIfNotSet()
  191. ->children()
  192. ->scalarNode('type')->defaultValue('fos_user_change_password')->end()
  193. ->scalarNode('handler')->defaultValue('fos_user.change_password.form.handler.default')->end()
  194. ->scalarNode('name')->defaultValue('fos_user_change_password_form')->cannotBeEmpty()->end()
  195. ->arrayNode('validation_groups')
  196. ->prototype('scalar')->end()
  197. ->defaultValue(array('ChangePassword', 'Default'))
  198. ->end()
  199. ->end()
  200. ->end()
  201. ->end()
  202. ->end()
  203. ->end();
  204. }
  205. private function addServiceSection(ArrayNodeDefinition $node)
  206. {
  207. $node
  208. ->addDefaultsIfNotSet()
  209. ->children()
  210. ->arrayNode('service')
  211. ->addDefaultsIfNotSet()
  212. ->children()
  213. ->scalarNode('mailer')->defaultValue('fos_user.mailer.default')->end()
  214. ->scalarNode('email_canonicalizer')->defaultValue('fos_user.util.canonicalizer.default')->end()
  215. ->scalarNode('username_canonicalizer')->defaultValue('fos_user.util.canonicalizer.default')->end()
  216. ->scalarNode('user_manager')->defaultValue('fos_user.user_manager.default')->end()
  217. ->end()
  218. ->end()
  219. ->end()
  220. ->end();
  221. }
  222. private function addTemplateSection(ArrayNodeDefinition $node)
  223. {
  224. $node
  225. ->children()
  226. ->arrayNode('template')
  227. ->addDefaultsIfNotSet()
  228. ->children()
  229. ->scalarNode('engine')->defaultValue('twig')->end()
  230. ->scalarNode('theme')->defaultValue('FOSUserBundle::form.html.twig')->end()
  231. ->end()
  232. ->end()
  233. ->end();
  234. }
  235. private function addGroupSection(ArrayNodeDefinition $node)
  236. {
  237. $node
  238. ->children()
  239. ->arrayNode('group')
  240. ->canBeUnset()
  241. ->children()
  242. ->scalarNode('group_class')->isRequired()->cannotBeEmpty()->end()
  243. ->scalarNode('group_manager')->defaultValue('fos_user.group_manager.default')->end()
  244. ->arrayNode('form')
  245. ->addDefaultsIfNotSet()
  246. ->children()
  247. ->scalarNode('type')->defaultValue('fos_user_group')->end()
  248. ->scalarNode('handler')->defaultValue('fos_user.group.form.handler.default')->end()
  249. ->scalarNode('name')->defaultValue('fos_user_group_form')->cannotBeEmpty()->end()
  250. ->arrayNode('validation_groups')
  251. ->prototype('scalar')->end()
  252. ->defaultValue(array('Registration', 'Default'))
  253. ->end()
  254. ->end()
  255. ->end()
  256. ->end()
  257. ->end()
  258. ->end();
  259. }
  260. }