Skip to content

Commit d190831

Browse files
committed
Tweaks after proofreading the 2.6 OptionsResolver stuff
1 parent 1117741 commit d190831

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

components/options_resolver.rst

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
The OptionsResolver Component
66
=============================
77

8-
The OptionsResolver component is `array_replace()` on steroids.
8+
The OptionsResolver component is `array_replace()` on steroids. It
9+
allows you to create an options system with required options, defaults,
10+
validation (type, value), normalization and more.
911

1012
Installation
1113
------------
@@ -21,7 +23,7 @@ Notes on Previous Versions
2123
.. versionadded:: 2.6
2224
This documentation was written for Symfony 2.6 and later. If you use an older
2325
version, please read the corresponding documentation using the version
24-
drop-down on the upper right.
26+
drop-down on the upper right. For a list of changes, see the `CHANGELOG`_
2527

2628
Usage
2729
-----
@@ -65,7 +67,7 @@ check which options are set::
6567
}
6668

6769
This boilerplate is hard to read and repetitive. Also, the default values of the
68-
options are buried in the business logic of your code. We can use
70+
options are buried in the business logic of your code. We can use the
6971
:phpfunction:`array_replace` to fix that::
7072

7173
class Mailer
@@ -91,10 +93,9 @@ the ``Mailer`` class does a mistake?
9193
'usernme' => 'johndoe',
9294
));
9395
94-
No error will be shown. In the best case, the bug will be appear during testing.
95-
The developer will possibly spend a lot of time looking for the problem. In the
96-
worst case, however, the bug won't even appear and will be deployed to the live
97-
system.
96+
No error will be shown. In the best case, the bug will appear during testing,
97+
but the developer will spend time looking for the problem. In the worst case,
98+
the bug might not appear until it's deployed to the live system.
9899

99100
Let's use the :class:`Symfony\\Component\\OptionsResolver\\OptionsResolver`
100101
class to fix this problem::
@@ -268,8 +269,8 @@ retrieve the names of all required options::
268269

269270
If you want to check whether a required option is still missing from the default
270271
options, you can use :method:`Symfony\\Component\\OptionsResolver\\OptionsResolver::isMissing`.
271-
The difference to :method:`Symfony\\Component\\OptionsResolver\\OptionsResolver::isRequired`
272-
is that this method will return false for required options that have already
272+
The difference between this and :method:`Symfony\\Component\\OptionsResolver\\OptionsResolver::isRequired`
273+
is that this method will return false if a required option has already
273274
been set::
274275

275276
// ...
@@ -360,8 +361,8 @@ Value Validation
360361
Some options can only take one of a fixed list of predefined values. For
361362
example, suppose the ``Mailer`` class has a ``transport`` option which can be
362363
one of ``sendmail``, ``mail`` and ``smtp``. Use the method
363-
:method:`Symfony\\Component\\OptionsResolver\\OptionsResolver::setAllowedValues` to verify
364-
that the passed option contains one of these values::
364+
:method:`Symfony\\Component\\OptionsResolver\\OptionsResolver::setAllowedValues`
365+
to verify that the passed option contains one of these values::
365366

366367
// ...
367368
class Mailer
@@ -470,9 +471,9 @@ Suppose you want to set the default value of the ``port`` option based on the
470471
encryption chosen by the user of the ``Mailer`` class. More precisely, we want
471472
to set the port to ``465`` if SSL is used and to ``25`` otherwise.
472473

473-
You can implement this feature by passing a closure as default value of the
474-
``port`` option. The closure receives the options as argument. Based on these
475-
options, you can return the desired default value::
474+
You can implement this feature by passing a closure as the default value of
475+
the ``port`` option. The closure receives the options as argument. Based on
476+
these options, you can return the desired default value::
476477

477478
use Symfony\Component\OptionsResolver\Options;
478479

@@ -546,8 +547,10 @@ Options without Default Values
546547
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
547548

548549
In some cases, it is useful to define an option without setting a default value.
549-
Mostly, you will need this when you want to know whether an option was passed
550-
or not. If you set a default value for that option, this is not possible::
550+
This is useful if you need to know whether or not the user *actually* set
551+
an option or not. For example, if you set the default value for an option,
552+
it's not possible to know whether the user passed this value or if it simply
553+
comes from the default::
551554

552555
// ...
553556
class Mailer
@@ -713,3 +716,4 @@ options in your code.
713716

714717
.. _Packagist: https://packagist.org/packages/symfony/options-resolver
715718
.. _Form component: http://symfony.com/doc/current/components/form/introduction.html
719+
.. _CHANGELOG: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/OptionsResolver/CHANGELOG.md

0 commit comments

Comments
 (0)