@@ -66,6 +66,9 @@ means you can handle it just like a normal array::
66
66
return $this->options['password'];
67
67
}
68
68
69
+ Configuring the OptionsResolver
70
+ -------------------------------
71
+
69
72
Now, try to actually use the class::
70
73
71
74
$mailer = new Mailer(array(
@@ -113,7 +116,7 @@ the ``OptionsResolver`` class::
113
116
}
114
117
115
118
Required Options
116
- ----------------
119
+ ~~~~~~~~~~~~~~~~
117
120
118
121
The ``host `` option is required: the class can't work without it. You can set
119
122
the required options by calling
@@ -131,7 +134,7 @@ You are now able to use the class without errors::
131
134
'host' => 'smtp.example.org',
132
135
));
133
136
134
- echo $person ->getHost(); // 'smtp.example.org'
137
+ echo $mailer ->getHost(); // 'smtp.example.org'
135
138
136
139
If you don't pass a required option, a
137
140
:class: `Symfony\\ Component\\ OptionsResolver\\ Exception\\ MissingOptionsException `
@@ -142,7 +145,7 @@ To determine if an option is required, you can use the
142
145
method.
143
146
144
147
Optional Options
145
- ----------------
148
+ ~~~~~~~~~~~~~~~~
146
149
147
150
Sometimes, an option can be optional (e.g. the ``password `` option in the
148
151
``Mailer `` class). You can configure these options by calling
@@ -157,7 +160,7 @@ Sometimes, an option can be optional (e.g. the ``password`` option in the
157
160
}
158
161
159
162
Set Default Values
160
- ------------------
163
+ ~~~~~~~~~~~~~~~~~~
161
164
162
165
Most of the optional options have a default value. You can configure these
163
166
options by calling
@@ -173,10 +176,11 @@ options by calling
173
176
));
174
177
}
175
178
176
- The default username will be ``root `` now. When the user specifies an age, it
177
- gets replaced. You don't need to configure ``root `` as an optional option. The
178
- ``OptionsResolver `` already knows that options with a default value are
179
- optional.
179
+ This would add a third option - ``username `` - and give it a default value
180
+ of ``root ``. If the user passes in a ``username `` option, that value will
181
+ override this default. You don't need to configure ``username `` as an optional
182
+ option. The ``OptionsResolver `` already knows that options with a default
183
+ value are optional.
180
184
181
185
The ``OptionsResolver `` component also has an
182
186
:method: `Symfony\\ Component\\ OptionsResolver\\ OptionsResolver::replaceDefaults `
@@ -218,7 +222,7 @@ Closure as the default value::
218
222
otherwise it is considered as the value.
219
223
220
224
Configure allowed Values
221
- ------------------------
225
+ ~~~~~~~~~~~~~~~~~~~~~~~~
222
226
223
227
Not all values are valid values for options. Suppose the ``Mailer `` class has
224
228
a ``transport `` option, it can only be one of ``sendmail ``, ``mail `` or
@@ -237,7 +241,7 @@ a ``transport`` option, it can only be one of ``sendmail``, ``mail`` or
237
241
238
242
There is also an
239
243
:method: `Symfony\\ Component\\ OptionsResolver\\ OptionsResolver::addAllowedValues `
240
- method, which you can use if you want to add an allowed value to the previous
244
+ method, which you can use if you want to add an allowed value to the previously
241
245
set allowed values.
242
246
243
247
Configure allowed Types
@@ -266,13 +270,13 @@ There is also an
266
270
method, which you can use to add an allowed type to the previous allowed types.
267
271
268
272
Normalize the Options
269
- ---------------------
273
+ ~~~~~~~~~~~~~~~~~~~~~
270
274
271
- Some values need to be normalized before you can use them. For instance, the
272
- ``host `` should always start ``http:// ``. To do that, you can
273
- write normalizers. These Closures will be executed after all options are
274
- passed and return the normalized value. You can configure these normalizers by
275
- calling
275
+ Some values need to be normalized before you can use them. For instance,
276
+ pretend that the ``host `` should always start with ``http:// ``. To do that,
277
+ you can write normalizers. These Closures will be executed after all options
278
+ are passed and should return the normalized value. You can configure these
279
+ normalizers by calling
276
280
:method: `Symfony\\ Components\\ OptionsResolver\\ OptionsResolver::setNormalizers `::
277
281
278
282
// ...
@@ -291,7 +295,7 @@ calling
291
295
));
292
296
}
293
297
294
- You see that the closure also get an ``$options `` parameter. Sometimes, you
298
+ You see that the closure also gets an ``$options `` parameter. Sometimes, you
295
299
need to use the other options for normalizing::
296
300
297
301
// ...
0 commit comments