|
1 <?php |
|
2 |
|
3 /* |
|
4 * This file is part of the FOSUserBundle package. |
|
5 * |
|
6 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> |
|
7 * |
|
8 * For the full copyright and license information, please view the LICENSE |
|
9 * file that was distributed with this source code. |
|
10 */ |
|
11 |
|
12 namespace FOS\UserBundle\DependencyInjection; |
|
13 |
|
14 use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
|
15 use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
|
16 use Symfony\Component\Config\Definition\ConfigurationInterface; |
|
17 |
|
18 /** |
|
19 * This class contains the configuration information for the bundle |
|
20 * |
|
21 * This information is solely responsible for how the different configuration |
|
22 * sections are normalized, and merged. |
|
23 * |
|
24 * @author Christophe Coevoet <stof@notk.org> |
|
25 */ |
|
26 class Configuration implements ConfigurationInterface |
|
27 { |
|
28 /** |
|
29 * Generates the configuration tree. |
|
30 * |
|
31 * @return TreeBuilder |
|
32 */ |
|
33 public function getConfigTreeBuilder() |
|
34 { |
|
35 $treeBuilder = new TreeBuilder(); |
|
36 $rootNode = $treeBuilder->root('fos_user'); |
|
37 |
|
38 $rootNode |
|
39 ->children() |
|
40 ->scalarNode('db_driver')->cannotBeOverwritten()->isRequired()->cannotBeEmpty()->end() |
|
41 ->scalarNode('user_class')->isRequired()->cannotBeEmpty()->end() |
|
42 ->scalarNode('firewall_name')->isRequired()->cannotBeEmpty()->end() |
|
43 ->scalarNode('model_manager_name')->defaultNull()->end() |
|
44 ->booleanNode('use_listener')->defaultTrue()->end() |
|
45 ->booleanNode('use_username_form_type')->defaultTrue()->end() |
|
46 ->arrayNode('from_email') |
|
47 ->addDefaultsIfNotSet() |
|
48 ->children() |
|
49 ->scalarNode('address')->defaultValue('webmaster@example.com')->cannotBeEmpty()->end() |
|
50 ->scalarNode('sender_name')->defaultValue('webmaster')->cannotBeEmpty()->end() |
|
51 ->end() |
|
52 ->end() |
|
53 ->end(); |
|
54 |
|
55 $this->addProfileSection($rootNode); |
|
56 $this->addChangePasswordSection($rootNode); |
|
57 $this->addRegistrationSection($rootNode); |
|
58 $this->addResettingSection($rootNode); |
|
59 $this->addServiceSection($rootNode); |
|
60 $this->addEncoderSection($rootNode); |
|
61 $this->addTemplateSection($rootNode); |
|
62 $this->addGroupSection($rootNode); |
|
63 |
|
64 return $treeBuilder; |
|
65 } |
|
66 |
|
67 private function addProfileSection(ArrayNodeDefinition $node) |
|
68 { |
|
69 $node |
|
70 ->children() |
|
71 ->arrayNode('profile') |
|
72 ->addDefaultsIfNotSet() |
|
73 ->canBeUnset() |
|
74 ->children() |
|
75 ->arrayNode('form') |
|
76 ->addDefaultsIfNotSet() |
|
77 ->children() |
|
78 ->scalarNode('type')->defaultValue('fos_user_profile')->end() |
|
79 ->scalarNode('handler')->defaultValue('fos_user.profile.form.handler.default')->end() |
|
80 ->scalarNode('name')->defaultValue('fos_user_profile_form')->cannotBeEmpty()->end() |
|
81 ->arrayNode('validation_groups') |
|
82 ->prototype('scalar')->end() |
|
83 ->defaultValue(array('Profile')) |
|
84 ->end() |
|
85 ->end() |
|
86 ->end() |
|
87 ->end() |
|
88 ->end() |
|
89 ->end(); |
|
90 } |
|
91 |
|
92 private function addRegistrationSection(ArrayNodeDefinition $node) |
|
93 { |
|
94 $node |
|
95 ->children() |
|
96 ->arrayNode('registration') |
|
97 ->addDefaultsIfNotSet() |
|
98 ->canBeUnset() |
|
99 ->children() |
|
100 ->arrayNode('confirmation') |
|
101 ->addDefaultsIfNotSet() |
|
102 ->children() |
|
103 ->booleanNode('enabled')->defaultFalse()->end() |
|
104 ->scalarNode('template')->defaultValue('FOSUserBundle:Registration:email.txt.twig')->end() |
|
105 ->arrayNode('from_email') |
|
106 ->canBeUnset() |
|
107 ->children() |
|
108 ->scalarNode('address')->isRequired()->cannotBeEmpty()->end() |
|
109 ->scalarNode('sender_name')->isRequired()->cannotBeEmpty()->end() |
|
110 ->end() |
|
111 ->end() |
|
112 ->end() |
|
113 ->end() |
|
114 ->arrayNode('form') |
|
115 ->addDefaultsIfNotSet() |
|
116 ->children() |
|
117 ->scalarNode('type')->defaultValue('fos_user_registration')->end() |
|
118 ->scalarNode('handler')->defaultValue('fos_user.registration.form.handler.default')->end() |
|
119 ->scalarNode('name')->defaultValue('fos_user_registration_form')->cannotBeEmpty()->end() |
|
120 ->arrayNode('validation_groups') |
|
121 ->prototype('scalar')->end() |
|
122 ->defaultValue(array('Registration')) |
|
123 ->end() |
|
124 ->end() |
|
125 ->end() |
|
126 ->end() |
|
127 ->end() |
|
128 ->end(); |
|
129 } |
|
130 |
|
131 private function addResettingSection(ArrayNodeDefinition $node) |
|
132 { |
|
133 $node |
|
134 ->children() |
|
135 ->arrayNode('resetting') |
|
136 ->addDefaultsIfNotSet() |
|
137 ->canBeUnset() |
|
138 ->children() |
|
139 ->scalarNode('token_ttl')->defaultValue(86400)->end() |
|
140 ->arrayNode('email') |
|
141 ->addDefaultsIfNotSet() |
|
142 ->children() |
|
143 ->scalarNode('template')->defaultValue('FOSUserBundle:Resetting:email.txt.twig')->end() |
|
144 ->arrayNode('from_email') |
|
145 ->canBeUnset() |
|
146 ->children() |
|
147 ->scalarNode('address')->isRequired()->cannotBeEmpty()->end() |
|
148 ->scalarNode('sender_name')->isRequired()->cannotBeEmpty()->end() |
|
149 ->end() |
|
150 ->end() |
|
151 ->end() |
|
152 ->end() |
|
153 ->arrayNode('form') |
|
154 ->addDefaultsIfNotSet() |
|
155 ->children() |
|
156 ->scalarNode('type')->defaultValue('fos_user_resetting')->end() |
|
157 ->scalarNode('handler')->defaultValue('fos_user.resetting.form.handler.default')->end() |
|
158 ->scalarNode('name')->defaultValue('fos_user_resetting_form')->cannotBeEmpty()->end() |
|
159 ->arrayNode('validation_groups') |
|
160 ->prototype('scalar')->end() |
|
161 ->defaultValue(array('ResetPassword')) |
|
162 ->end() |
|
163 ->end() |
|
164 ->end() |
|
165 ->end() |
|
166 ->end() |
|
167 ->end(); |
|
168 } |
|
169 |
|
170 private function addChangePasswordSection(ArrayNodeDefinition $node) |
|
171 { |
|
172 $node |
|
173 ->children() |
|
174 ->arrayNode('change_password') |
|
175 ->addDefaultsIfNotSet() |
|
176 ->canBeUnset() |
|
177 ->children() |
|
178 ->arrayNode('form') |
|
179 ->addDefaultsIfNotSet() |
|
180 ->children() |
|
181 ->scalarNode('type')->defaultValue('fos_user_change_password')->end() |
|
182 ->scalarNode('handler')->defaultValue('fos_user.change_password.form.handler.default')->end() |
|
183 ->scalarNode('name')->defaultValue('fos_user_change_password_form')->cannotBeEmpty()->end() |
|
184 ->arrayNode('validation_groups') |
|
185 ->prototype('scalar')->end() |
|
186 ->defaultValue(array('ChangePassword')) |
|
187 ->end() |
|
188 ->end() |
|
189 ->end() |
|
190 ->end() |
|
191 ->end() |
|
192 ->end(); |
|
193 } |
|
194 |
|
195 private function addServiceSection(ArrayNodeDefinition $node) |
|
196 { |
|
197 $node |
|
198 ->addDefaultsIfNotSet() |
|
199 ->children() |
|
200 ->arrayNode('service') |
|
201 ->addDefaultsIfNotSet() |
|
202 ->children() |
|
203 ->scalarNode('mailer')->defaultValue('fos_user.mailer.default')->end() |
|
204 ->scalarNode('email_canonicalizer')->defaultValue('fos_user.util.email_canonicalizer.default')->end() |
|
205 ->scalarNode('username_canonicalizer')->defaultValue('fos_user.util.username_canonicalizer.default')->end() |
|
206 ->scalarNode('user_manager')->defaultValue('fos_user.user_manager.default')->end() |
|
207 ->end() |
|
208 ->end() |
|
209 ->end() |
|
210 ->end(); |
|
211 } |
|
212 |
|
213 private function addEncoderSection(ArrayNodeDefinition $node) |
|
214 { |
|
215 $node |
|
216 ->children() |
|
217 ->arrayNode('encoder') |
|
218 ->addDefaultsIfNotSet() |
|
219 ->children() |
|
220 ->scalarNode('algorithm')->defaultValue('sha512')->end() |
|
221 ->booleanNode('encode_as_base64')->defaultFalse()->end() |
|
222 ->scalarNode('iterations')->defaultValue(1)->end() |
|
223 ->end() |
|
224 ->end() |
|
225 ->end(); |
|
226 } |
|
227 |
|
228 private function addTemplateSection(ArrayNodeDefinition $node) |
|
229 { |
|
230 $node |
|
231 ->children() |
|
232 ->arrayNode('template') |
|
233 ->addDefaultsIfNotSet() |
|
234 ->children() |
|
235 ->scalarNode('engine')->defaultValue('twig')->end() |
|
236 ->scalarNode('theme')->defaultValue('FOSUserBundle::form.html.twig')->end() |
|
237 ->end() |
|
238 ->end() |
|
239 ->end(); |
|
240 } |
|
241 |
|
242 private function addGroupSection(ArrayNodeDefinition $node) |
|
243 { |
|
244 $node |
|
245 ->children() |
|
246 ->arrayNode('group') |
|
247 ->canBeUnset() |
|
248 ->children() |
|
249 ->scalarNode('group_class')->isRequired()->cannotBeEmpty()->end() |
|
250 ->scalarNode('group_manager')->defaultValue('fos_user.group_manager.default')->end() |
|
251 ->arrayNode('form') |
|
252 ->addDefaultsIfNotSet() |
|
253 ->children() |
|
254 ->scalarNode('type')->defaultValue('fos_user_group')->end() |
|
255 ->scalarNode('handler')->defaultValue('fos_user.group.form.handler.default')->end() |
|
256 ->scalarNode('name')->defaultValue('fos_user_group_form')->cannotBeEmpty()->end() |
|
257 ->arrayNode('validation_groups') |
|
258 ->prototype('scalar')->end() |
|
259 ->defaultValue(array('Registration')) |
|
260 ->end() |
|
261 ->end() |
|
262 ->end() |
|
263 ->end() |
|
264 ->end() |
|
265 ->end(); |
|
266 } |
|
267 } |