Skip to content

Commit cbb304f

Browse files
committed
[#2547] Proofreading nice changes by @wouterj to the OptionsResolver component
1 parent d29eceb commit cbb304f

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

components/options_resolver.rst

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ means you can handle it just like a normal array::
6666
return $this->options['password'];
6767
}
6868

69+
Configuring the OptionsResolver
70+
-------------------------------
71+
6972
Now, try to actually use the class::
7073

7174
$mailer = new Mailer(array(
@@ -113,7 +116,7 @@ the ``OptionsResolver`` class::
113116
}
114117

115118
Required Options
116-
----------------
119+
~~~~~~~~~~~~~~~~
117120

118121
The ``host`` option is required: the class can't work without it. You can set
119122
the required options by calling
@@ -131,7 +134,7 @@ You are now able to use the class without errors::
131134
'host' => 'smtp.example.org',
132135
));
133136

134-
echo $person->getHost(); // 'smtp.example.org'
137+
echo $mailer->getHost(); // 'smtp.example.org'
135138

136139
If you don't pass a required option, a
137140
:class:`Symfony\\Component\\OptionsResolver\\Exception\\MissingOptionsException`
@@ -142,7 +145,7 @@ To determine if an option is required, you can use the
142145
method.
143146

144147
Optional Options
145-
----------------
148+
~~~~~~~~~~~~~~~~
146149

147150
Sometimes, an option can be optional (e.g. the ``password`` option in the
148151
``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
157160
}
158161

159162
Set Default Values
160-
------------------
163+
~~~~~~~~~~~~~~~~~~
161164

162165
Most of the optional options have a default value. You can configure these
163166
options by calling
@@ -173,10 +176,11 @@ options by calling
173176
));
174177
}
175178

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.
180184

181185
The ``OptionsResolver`` component also has an
182186
:method:`Symfony\\Component\\OptionsResolver\\OptionsResolver::replaceDefaults`
@@ -218,7 +222,7 @@ Closure as the default value::
218222
otherwise it is considered as the value.
219223

220224
Configure allowed Values
221-
------------------------
225+
~~~~~~~~~~~~~~~~~~~~~~~~
222226

223227
Not all values are valid values for options. Suppose the ``Mailer`` class has
224228
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
237241

238242
There is also an
239243
: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
241245
set allowed values.
242246

243247
Configure allowed Types
@@ -266,13 +270,13 @@ There is also an
266270
method, which you can use to add an allowed type to the previous allowed types.
267271

268272
Normalize the Options
269-
---------------------
273+
~~~~~~~~~~~~~~~~~~~~~
270274

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
276280
:method:`Symfony\\Components\\OptionsResolver\\OptionsResolver::setNormalizers`::
277281

278282
// ...
@@ -291,7 +295,7 @@ calling
291295
));
292296
}
293297

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
295299
need to use the other options for normalizing::
296300

297301
// ...

0 commit comments

Comments
 (0)