Skip to content

Commit d65b968

Browse files
committed
Merge branch '2.2' into 2.3
2 parents c59cb0f + c753260 commit d65b968

File tree

4 files changed

+96
-25
lines changed

4 files changed

+96
-25
lines changed

components/console/helpers/dialoghelper.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ the following to your command::
3131
return;
3232
}
3333

34-
In this case, the user will be asked "Continue with this action?", and will return
35-
``true`` if the user answers with ``y`` or false in any other case. The third
36-
argument to ``askConfirmation`` is the default value to return if the user doesn't
37-
enter any input.
34+
In this case, the user will be asked "Continue with this action?", and will
35+
return ``true`` if the user answers with ``y`` or ``false`` if the user answers
36+
with ``n``. The third argument to
37+
:method:`Symfony\\Component\\Console\\Helper\\DialogHelper::askConfirmation`
38+
is the default value to return if the user doesn't enter any input. Any other
39+
input will ask the same question again.
3840

3941
Asking the User for Information
4042
-------------------------------

components/options_resolver.rst

Lines changed: 77 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -177,21 +177,12 @@ override this default. You don't need to configure ``username`` as an optional
177177
option. The ``OptionsResolver`` already knows that options with a default
178178
value are optional.
179179

180-
The OptionsResolver component also has an
181-
:method:`Symfony\\Component\\OptionsResolver\\OptionsResolver::replaceDefaults`
182-
method. This can be used to override the previous default value. The closure
183-
that is passed has 2 parameters:
184-
185-
* ``$options`` (an :class:`Symfony\\Component\\OptionsResolver\\Options`
186-
instance), with all the default options
187-
* ``$value``, the previous set default value
188-
189180
Default Values that depend on another Option
190181
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
191182

192183
Suppose you add a ``port`` option to the ``Mailer`` class, whose default
193184
value you guess based on the host. You can do that easily by using a
194-
Closure as the default value::
185+
closure as the default value::
195186

196187
use Symfony\Component\OptionsResolver\Options;
197188
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
@@ -214,9 +205,83 @@ Closure as the default value::
214205

215206
.. caution::
216207

217-
The first argument of the Closure must be typehinted as ``Options``,
208+
The first argument of the closure must be typehinted as ``Options``,
218209
otherwise it is considered as the value.
219210

211+
Overwriting Default Values
212+
~~~~~~~~~~~~~~~~~~~~~~~~~~
213+
214+
A previously set default value can be overwritten by invoking
215+
:method:`Symfony\\Component\\OptionsResolver\\OptionsResolver::setDefaults`
216+
again. When using a closure as the new value it is passed 2 arguments:
217+
218+
* ``$options``: an :class:`Symfony\\Component\\OptionsResolver\\Options`
219+
instance with all the other default options
220+
* ``$previousValue``: the previous set default value
221+
222+
.. code-block:: php
223+
224+
use Symfony\Component\OptionsResolver\Options;
225+
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
226+
227+
// ...
228+
protected function setDefaultOptions(OptionsResolverInterface $resolver)
229+
{
230+
// ...
231+
$resolver->setDefaults(array(
232+
'encryption' => 'ssl',
233+
'host' => 'localhost',
234+
));
235+
236+
// ...
237+
$resolver->setDefaults(array(
238+
'encryption' => 'tls', // simple overwrite
239+
'host' => function (Options $options, $previousValue) {
240+
return 'localhost' == $previousValue ? '127.0.0.1' : $previousValue;
241+
},
242+
));
243+
}
244+
245+
.. tip::
246+
247+
If the previous default value is calculated by an expensive closure and
248+
you don't need access to it, you can use the
249+
:method:`Symfony\\Component\\OptionsResolver\\OptionsResolver::replaceDefaults`
250+
method instead. It acts like ``setDefaults`` but simply erases the
251+
previous value to improve performance. This means that the previous
252+
default value is not available when overwriting with another closure::
253+
254+
use Symfony\Component\OptionsResolver\Options;
255+
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
256+
257+
// ...
258+
protected function setDefaultOptions(OptionsResolverInterface $resolver)
259+
{
260+
// ...
261+
$resolver->setDefaults(array(
262+
'encryption' => 'ssl',
263+
'heavy' => function (Options $options) {
264+
// Some heavy calculations to create the $result
265+
266+
return $result;
267+
},
268+
));
269+
270+
$resolver->replaceDefaults(array(
271+
'encryption' => 'tls', // simple overwrite
272+
'heavy' => function (Options $options) {
273+
// $previousValue not available
274+
// ...
275+
276+
return $someOtherResult;
277+
},
278+
));
279+
}
280+
281+
.. note::
282+
283+
Existing option keys that you do not mention when overwriting are preserved.
284+
220285
Configure allowed Values
221286
~~~~~~~~~~~~~~~~~~~~~~~~
222287

@@ -270,7 +335,7 @@ Normalize the Options
270335

271336
Some values need to be normalized before you can use them. For instance,
272337
pretend that the ``host`` should always start with ``http://``. To do that,
273-
you can write normalizers. These Closures will be executed after all options
338+
you can write normalizers. These closures will be executed after all options
274339
are passed and should return the normalized value. You can configure these
275340
normalizers by calling
276341
:method:`Symfony\\Components\\OptionsResolver\\OptionsResolver::setNormalizers`::

cookbook/form/form_customization.rst

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ You can also render each of the three parts of the field individually:
4141
.. code-block:: php
4242
4343
<div>
44-
<?php echo $view['form']->label($form['age']) }} ?>
45-
<?php echo $view['form']->errors($form['age']) }} ?>
46-
<?php echo $view['form']->widget($form['age']) }} ?>
44+
<?php echo $view['form']->label($form['age']); ?>
45+
<?php echo $view['form']->errors($form['age']); ?>
46+
<?php echo $view['form']->widget($form['age']); ?>
4747
</div>
4848
4949
In both cases, the form label, errors and HTML widget are rendered by using
@@ -71,7 +71,7 @@ just one line:
7171
7272
.. code-block:: php
7373
74-
<?php echo $view['form']->widget($form) }} ?>
74+
<?php echo $view['form']->widget($form); ?>
7575
7676
The remainder of this recipe will explain how every part of the form's markup
7777
can be modified at several different levels. For more information about form
@@ -646,7 +646,6 @@ customize the ``name`` field only:
646646
<?php echo $view['form']->widget($form['name']); ?>
647647

648648
<!-- src/Acme/DemoBundle/Resources/views/Form/_product_name_widget.html.php -->
649-
650649
<div class="text_widget">
651650
echo $view['form']->block('form_widget_simple') ?>
652651
</div>
@@ -667,7 +666,6 @@ You can also override the markup for an entire field row using the same method:
667666

668667
.. code-block:: html+jinja
669668

670-
{# _product_name_row.html.twig #}
671669
{% form_theme form _self %}
672670

673671
{% block _product_name_row %}
@@ -678,10 +676,16 @@ You can also override the markup for an entire field row using the same method:
678676
</div>
679677
{% endblock %}
680678

679+
{{ form_row(form.name) }}
680+
681681
.. code-block:: html+php
682682

683-
<!-- _product_name_row.html.php -->
683+
<!-- Main template -->
684+
<?php echo $view['form']->setTheme($form, array('AcmeDemoBundle:Form')); ?>
685+
686+
<?php echo $view['form']->row($form['name']); ?>
684687

688+
<!-- src/Acme/DemoBundle/Resources/views/Form/_product_name_row.html.php -->
685689
<div class="name_row">
686690
<?php echo $view['form']->label($form) ?>
687691
<?php echo $view['form']->errors($form) ?>

cookbook/logging/monolog.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ The basic handler is the ``StreamHandler`` which writes logs in a stream
4646
Monolog comes also with a powerful built-in handler for the logging in
4747
prod environment: ``FingersCrossedHandler``. It allows you to store the
4848
messages in a buffer and to log them only if a message reaches the
49-
action level (ERROR in the configuration provided in the standard
50-
edition) by forwarding the messages to another handler.
49+
action level (``error`` in the configuration provided in the Standard
50+
Edition) by forwarding the messages to another handler.
5151

5252
Using several handlers
5353
~~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)