Skip to content

Commit c483ac6

Browse files
committed
Merge branch '2.3' into 2.4
2 parents f634600 + 003230f commit c483ac6

24 files changed

+241
-88
lines changed

book/forms.rst

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ going to need to build a form. But before you begin, first focus on the generic
4848
{
4949
return $this->dueDate;
5050
}
51+
5152
public function setDueDate(\DateTime $dueDate = null)
5253
{
5354
$this->dueDate = $dueDate;

book/http_cache.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -795,13 +795,13 @@ Gateway caches are a great way to make your website perform better. But they
795795
have one limitation: they can only cache whole pages. If you can't cache
796796
whole pages or if parts of a page has "more" dynamic parts, you are out of
797797
luck. Fortunately, Symfony2 provides a solution for these cases, based on a
798-
technology called `ESI`_, or Edge Side Includes. Akamaï wrote this specification
798+
technology called `ESI`_, or Edge Side Includes. Akamai wrote this specification
799799
almost 10 years ago, and it allows specific parts of a page to have a different
800800
caching strategy than the main page.
801801

802802
The ESI specification describes tags you can embed in your pages to communicate
803803
with the gateway cache. Only one tag is implemented in Symfony2, ``include``,
804-
as this is the only useful one outside of Akamaï context:
804+
as this is the only useful one outside of Akamai context:
805805

806806
.. code-block:: html
807807

@@ -936,7 +936,7 @@ used ``render``.
936936

937937
.. note::
938938

939-
Symfony2 detects if a gateway cache supports ESI via another Akamaï
939+
Symfony2 detects if a gateway cache supports ESI via another Akamai
940940
specification that is supported out of the box by the Symfony2 reverse
941941
proxy.
942942

book/security.rst

+6-6
Original file line numberDiff line numberDiff line change
@@ -764,13 +764,13 @@ is used to enforce access.
764764
Each ``access_control`` has several options that configure two different
765765
things:
766766

767-
* (a) :ref:`should the incoming request match this access control entry <security-book-access-control-matching-options>`
768-
* (b) :ref:`once it matches, should some sort of access restriction be enforced <security-book-access-control-enforcement-options>`:
767+
#. :ref:`should the incoming request match this access control entry <security-book-access-control-matching-options>`
768+
#. :ref:`once it matches, should some sort of access restriction be enforced <security-book-access-control-enforcement-options>`:
769769

770770
.. _security-book-access-control-matching-options:
771771

772-
(a) Matching Options
773-
....................
772+
1. Matching Options
773+
...................
774774

775775
Symfony2 creates an instance of :class:`Symfony\\Component\\HttpFoundation\\RequestMatcher`
776776
for each ``access_control`` entry, which determines whether or not a given
@@ -865,8 +865,8 @@ will match any ``ip``, ``host`` or ``method``:
865865

866866
.. _security-book-access-control-enforcement-options:
867867

868-
(b) Access Enforcement
869-
......................
868+
2. Access Enforcement
869+
.....................
870870

871871
Once Symfony2 has decided which ``access_control`` entry matches (if any),
872872
it then *enforces* access restrictions based on the ``roles`` and ``requires_channel``

book/translation.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ key ``Symfony2 is great``. To find the French translation, Symfony actually
392392
checks translation resources for several different locales:
393393

394394
1. First, Symfony looks for the translation in a ``fr_FR`` translation resource
395-
(e.g. ``messages.fr_FR.xfliff``);
395+
(e.g. ``messages.fr_FR.xliff``);
396396

397397
2. If it wasn't found, Symfony looks for the translation in a ``fr`` translation
398398
resource (e.g. ``messages.fr.xliff``);

components/config/definition.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,8 @@ process is used to remove some of the differences that result from different
396396
configuration formats, mainly the differences between YAML and XML.
397397

398398
The separator used in keys is typically ``_`` in YAML and ``-`` in XML. For
399-
example, ``auto_connect`` in YAML and ``auto-connect``. The normalization would
400-
make both of these ``auto_connect``.
399+
example, ``auto_connect`` in YAML and ``auto-connect`` in XML.
400+
The normalization would make both of these ``auto_connect``.
401401

402402
.. caution::
403403

components/console/helpers/dialoghelper.rst

+10-6
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ helper set, which you can get by calling
1212
$dialog = $this->getHelperSet()->get('dialog');
1313

1414
All the methods inside the Dialog Helper have an
15-
:class:`Symfony\\Component\\Console\\Output\\OutputInterface` as first the
16-
argument, the question as the second argument and the default value as last
15+
:class:`Symfony\\Component\\Console\\Output\\OutputInterface` as the first
16+
argument, the question as the second argument and the default value as the last
1717
argument.
1818

1919
Asking the User for confirmation
@@ -52,8 +52,9 @@ if you want to know a bundle name, you can add this to your command::
5252
);
5353

5454
The user will be asked "Please enter the name of the bundle". They can type
55-
some name which will be returned by the ``ask`` method. If they leave it empty,
56-
the default value (``AcmeDemoBundle`` here) is returned.
55+
some name which will be returned by the
56+
:method:`Symfony\\Component\\Console\\Helper\\DialogHelper::ask` method.
57+
If they leave it empty, the default value (``AcmeDemoBundle`` here) is returned.
5758

5859
Autocompletion
5960
~~~~~~~~~~~~~~
@@ -235,9 +236,12 @@ this set the seventh argument to ``true``::
235236
return $colors[$c];
236237
}, $selected);
237238

238-
$output->writeln('You have just selected: ' . implode(', ', $selectedColors));
239+
$output->writeln(
240+
'You have just selected: ' . implode(', ', $selectedColors)
241+
);
239242

240-
Now, when the user enters ``1,2``, the result will be: ``You have just selected: blue, yellow``.
243+
Now, when the user enters ``1,2``, the result will be:
244+
``You have just selected: blue, yellow``.
241245

242246
Testing a Command which expects input
243247
-------------------------------------

components/dependency_injection/parameters.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ keywords (respectively ``true``, ``false`` and ``null``):
295295
.. code-block:: xml
296296
297297
<parameters>
298-
<parameter key="mailer.send_all_in_once">false</parameters>
298+
<parameter key="mailer.send_all_in_once">false</parameter>
299299
</parameters>
300300
301301
<!-- after parsing

components/dependency_injection/tags.rst

-3
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,6 @@ To begin with, change the ``TransportChain`` class::
199199
if (array_key_exists($alias, $this->transports)) {
200200
return $this->transports[$alias];
201201
}
202-
else {
203-
return;
204-
}
205202
}
206203
}
207204

components/dom_crawler.rst

+9-7
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ interacting with html links and forms as you traverse through the HTML tree.
5555
.. note::
5656

5757
The DomCrawler will attempt to automatically fix your HTML to match the
58-
official specification. For example, if you nest a `` <p>`` tag inside
59-
another `` <p>`` tag, it will be moved to be a sibling of the parent tag.
58+
official specification. For example, if you nest a ``<p>`` tag inside
59+
another ``<p>`` tag, it will be moved to be a sibling of the parent tag.
6060
This is expected and is part of the HTML5 spec. But if you're getting
6161
unexpected behavior, this could be a cause. And while the DomCrawler
62-
isn't meant to dump content, you can see the "fixed" version if your HTML
62+
isn't meant to dump content, you can see the "fixed" version of your HTML
6363
by :ref:`dumping it <component-dom-crawler-dumping>`.
6464

6565
Node Filtering
@@ -83,10 +83,12 @@ Anonymous function can be used to filter with more complex criteria::
8383
use Symfony\Component\DomCrawler\Crawler;
8484
// ...
8585

86-
$crawler = $crawler->filter('body > p')->reduce(function (Crawler $node, $i) {
87-
// filter even nodes
88-
return ($i % 2) == 0;
89-
});
86+
$crawler = $crawler
87+
->filter('body > p')
88+
->reduce(function (Crawler $node, $i) {
89+
// filter even nodes
90+
return ($i % 2) == 0;
91+
});
9092

9193
To remove a node the anonymous function must return false.
9294

components/options_resolver.rst

+60-41
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@ The advantages of doing this will become more obvious as you continue::
5050
$this->options = $resolver->resolve($options);
5151
}
5252

53-
The options property now is a well defined array with all resolved options readily available::
53+
The options property now is a well defined array with all resolved options
54+
readily available::
5455

5556
// ...
56-
public function getHost()
57+
public function sendMail($from, $to)
5758
{
58-
return $this->options['host'];
59-
}
60-
61-
public function getPassword()
62-
{
63-
return $this->options['password'];
59+
$mail = ...;
60+
$mail->setHost($this->options['host']);
61+
$mail->setUsername($this->options['username']);
62+
$mail->setPassword($this->options['password']);
63+
// ...
6464
}
6565

6666
Configuring the OptionsResolver
@@ -70,6 +70,7 @@ Now, try to actually use the class::
7070

7171
$mailer = new Mailer(array(
7272
'host' => 'smtp.example.org',
73+
'username' => 'user',
7374
'password' => 'pa$$word',
7475
));
7576

@@ -86,7 +87,7 @@ knows which options should be resolved.
8687
function.
8788

8889
A best practice is to put the configuration in a method (e.g.
89-
``setDefaultOptions``). You call this method in the constructor to configure
90+
``configureOptions``). You call this method in the constructor to configure
9091
the ``OptionsResolver`` class::
9192

9293
use Symfony\Component\OptionsResolver\OptionsResolver;
@@ -99,17 +100,38 @@ the ``OptionsResolver`` class::
99100
public function __construct(array $options = array())
100101
{
101102
$resolver = new OptionsResolver();
102-
$this->setDefaultOptions($resolver);
103+
$this->configureOptions($resolver);
103104

104105
$this->options = $resolver->resolve($options);
105106
}
106107

107-
protected function setDefaultOptions(OptionsResolverInterface $resolver)
108+
protected function configureOptions(OptionsResolverInterface $resolver)
108109
{
109110
// ... configure the resolver, you will learn this in the sections below
110111
}
111112
}
112113

114+
Set Default Values
115+
~~~~~~~~~~~~~~~~~~
116+
117+
Most of the options have a default value. You can configure these options by
118+
calling :method:`Symfony\\Component\\OptionsResolver\\OptionsResolver::setDefaults`::
119+
120+
// ...
121+
protected function setDefaultOptions(OptionsResolverInterface $resolver)
122+
{
123+
// ...
124+
125+
$resolver->setDefaults(array(
126+
'username' => 'root',
127+
));
128+
}
129+
130+
This would add an option - ``username`` - and give it a default value of
131+
``root``. If the user passes in a ``username`` option, that value will
132+
override this default. You don't need to configure ``username`` as an optional
133+
option.
134+
113135
Required Options
114136
~~~~~~~~~~~~~~~~
115137

@@ -135,15 +157,18 @@ If you don't pass a required option, a
135157
:class:`Symfony\\Component\\OptionsResolver\\Exception\\MissingOptionsException`
136158
will be thrown.
137159

138-
To determine if an option is required, you can use the
139-
:method:`Symfony\\Component\\OptionsResolver\\OptionsResolver::isRequired`
140-
method.
160+
.. tip::
161+
162+
To determine if an option is required, you can use the
163+
:method:`Symfony\\Component\\OptionsResolver\\OptionsResolver::isRequired`
164+
method.
141165

142166
Optional Options
143167
~~~~~~~~~~~~~~~~
144168

145169
Sometimes, an option can be optional (e.g. the ``password`` option in the
146-
``Mailer`` class). You can configure these options by calling
170+
``Mailer`` class), but it doesn't have a default value. You can configure
171+
these options by calling
147172
:method:`Symfony\\Component\\OptionsResolver\\OptionsResolver::setOptional`::
148173

149174
// ...
@@ -154,34 +179,23 @@ Sometimes, an option can be optional (e.g. the ``password`` option in the
154179
$resolver->setOptional(array('password'));
155180
}
156181

157-
Set Default Values
158-
~~~~~~~~~~~~~~~~~~
159-
160-
Most of the optional options have a default value. You can configure these
161-
options by calling
162-
:method:`Symfony\\Component\\OptionsResolver\\OptionsResolver::setDefaults`::
182+
Options with defaults are already marked as optional.
163183

164-
// ...
165-
protected function setDefaultOptions(OptionsResolverInterface $resolver)
166-
{
167-
// ...
184+
.. tip::
168185

169-
$resolver->setDefaults(array(
170-
'username' => 'root',
171-
));
172-
}
186+
When setting an option as optional, you can't be sure if it's in the array
187+
or not. You have to check if the option exists before using it.
173188

174-
This would add a third option - ``username`` - and give it a default value
175-
of ``root``. If the user passes in a ``username`` option, that value will
176-
override this default. You don't need to configure ``username`` as an optional
177-
option. The ``OptionsResolver`` already knows that options with a default
178-
value are optional.
189+
To avoid checking if it exists everytime, you can also set a default of
190+
``null`` to an option using the ``setDefaults()`` method (see `Set Default Values`_),
191+
this means the element always exists in the array, but with a default of
192+
``null``.
179193

180-
Default Values that depend on another Option
194+
Default Values that Depend on another Option
181195
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
182196

183197
Suppose you add a ``port`` option to the ``Mailer`` class, whose default
184-
value you guess based on the host. You can do that easily by using a
198+
value you guess based on the encryption. You can do that easily by using a
185199
closure as the default value::
186200

187201
use Symfony\Component\OptionsResolver\Options;
@@ -193,16 +207,21 @@ closure as the default value::
193207
// ...
194208

195209
$resolver->setDefaults(array(
210+
'encryption' => null,
196211
'port' => function (Options $options) {
197-
if (in_array($options['host'], array('127.0.0.1', 'localhost'))) {
198-
return 80;
212+
if ('ssl' === $options['encryption']) {
213+
return 465;
199214
}
200215

201216
return 25;
202217
},
203218
));
204219
}
205220

221+
The :class:`Symfony\\Component\\OptionsResolver\\Options` class implements
222+
:phpclass:`ArrayAccess`, :phpclass:`Iterator` and :phpclass:`Countable`. That
223+
means you can handle it just like a normal array containing the options.
224+
206225
.. caution::
207226

208227
The first argument of the closure must be typehinted as ``Options``,
@@ -296,16 +315,16 @@ a ``transport`` option, it can only be one of ``sendmail``, ``mail`` or
296315
// ...
297316

298317
$resolver->setAllowedValues(array(
299-
'transport' => array('sendmail', 'mail', 'smtp'),
318+
'encryption' => array(null, 'ssl', 'tls'),
300319
));
301320
}
302321

303322
There is also an
304323
:method:`Symfony\\Component\\OptionsResolver\\OptionsResolver::addAllowedValues`
305324
method, which you can use if you want to add an allowed value to the previously
306-
set allowed values.
325+
configured allowed values.
307326

308-
Configure allowed Types
327+
Configure Allowed Types
309328
~~~~~~~~~~~~~~~~~~~~~~~
310329

311330
You can also specify allowed types. For instance, the ``port`` option can

0 commit comments

Comments
 (0)