PageRenderTime 68ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/Configuration.php

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