@@ -9,8 +9,7 @@ The OptionsResolver Component
9
9
arrays. It supports default values, option constraints and lazy options.
10
10
11
11
.. versionadded :: 2.1
12
- The OptionsResolver Component is new in Symfony2.1, it can be found in the
13
- Form component in older versions.
12
+ The OptionsResolver Component is new in Symfony2.1
14
13
15
14
Installation
16
15
------------
@@ -201,7 +200,7 @@ Default values that depend on another option
201
200
202
201
If you add a ``gender `` option to the ``Person `` class, it should get a
203
202
default value which guess the gender based on the first name. You can do that
204
- easilly by using a Closure as default value::
203
+ easily by using a Closure as default value::
205
204
206
205
use Symfony\Component\OptionsResolver\Options;
207
206
@@ -221,6 +220,11 @@ easilly by using a Closure as default value::
221
220
));
222
221
}
223
222
223
+ .. caution ::
224
+
225
+ The first argument of the Closure must be typehinted as `Options `,
226
+ otherwise it is considered as the value.
227
+
224
228
Configure allowed values
225
229
------------------------
226
230
@@ -261,6 +265,11 @@ be anything, but it must be a string. You can configure these types by calling
261
265
));
262
266
}
263
267
268
+ Possible types are the one associated with the ``is_* `` php functions or a
269
+ class name. You can also pass an array of types as value. For instance,
270
+ ``array('null', 'string') `` allows ``firstName `` to be ``null `` or a
271
+ ``string ``.
272
+
264
273
There is also a
265
274
:method: `Symfony\\ Component\\ OptionsResolver\\ OptionsResolver::addAllowedTypes `
266
275
method, which you can use to add an allowed type to the previous allowed types.
0 commit comments