Skip to content

Commit 13c76ab

Browse files
committed
Merge branch '3.4' into 4.0
* 3.4: Documented the findByCodes() validation method Fixed the type of the twig.cache config option Update the argument value resolver article Documented the catchExceptions() method Documented the enableExceptionOnInvalidIndex() method Added the missing attr option in TextType
2 parents 1a5068d + 55017bf commit 13c76ab

File tree

6 files changed

+78
-14
lines changed

6 files changed

+78
-14
lines changed

components/property_access.rst

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,23 @@ method. This is done using the index notation that is used in PHP::
4747
var_dump($propertyAccessor->getValue($person, '[first_name]')); // 'Wouter'
4848
var_dump($propertyAccessor->getValue($person, '[age]')); // null
4949

50-
As you can see, the method will return ``null`` if the index does not exists.
50+
As you can see, the method will return ``null`` if the index does not exist.
51+
But you can change this behavior with the
52+
:method:`Symfony\\Component\\PropertyAccess\\PropertyAccessorBuilder::enableExceptionOnInvalidIndex`
53+
method::
54+
55+
// ...
56+
$propertyAccessor = PropertyAccess::createPropertyAccessorBuilder()
57+
->enableExceptionOnInvalidIndex()
58+
->getPropertyAccessor();
59+
60+
$person = array(
61+
'first_name' => 'Wouter',
62+
);
63+
64+
// instead of returning null, the code now throws an exception of type
65+
// Symfony\Component\PropertyAccess\Exception\NoSuchIndexException
66+
$value = $propertyAccessor->getValue($person, '[age]');
5167

5268
You can also use multi dimensional arrays::
5369

components/validator.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,19 @@ characters long::
5353
}
5454
}
5555

56-
The validator returns the list of violations.
56+
The ``validate()`` method returns the list of violations as an object that
57+
implements :class:`Symfony\\Component\\Validator\\ConstraintViolationListInterface`.
58+
If you have lots of validation errors, you can filter them by error code::
59+
60+
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
61+
62+
$violations = $validator->validate(...);
63+
if (count($violations->findByCodes(UniqueEntity::NOT_UNIQUE_ERROR))) {
64+
// handle this specific error (display some message, send an email, etc.)
65+
}
66+
67+
.. versionadded:: 3.3
68+
The ``findByCodes()`` method was introduced in Symfony 3.3.
5769

5870
Retrieving a Validator Instance
5971
-------------------------------

controller/argument_value_resolver.rst

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,9 @@ Symfony ships with five value resolvers in the HttpKernel component:
4545
Adding a Custom Value Resolver
4646
------------------------------
4747

48-
Adding a new value resolver requires creating one class and one service
49-
definition. In the next example, you'll create a value resolver to inject the
50-
``User`` object from the security system. Given you write the following
51-
controller::
48+
In the next example, you'll create a value resolver to inject the object that
49+
represents the current user whenever a controller method type-hints an argument
50+
with the ``User`` class::
5251

5352
namespace App\Controller;
5453

@@ -63,10 +62,30 @@ controller::
6362
}
6463
}
6564

66-
Somehow you will have to get the ``User`` object and inject it into the controller.
67-
This can be done by implementing the
68-
:class:`Symfony\\Component\\HttpKernel\\Controller\\ArgumentValueResolverInterface`.
69-
This interface specifies that you have to implement two methods:
65+
Beware that this feature is already provided by the `@ParamConverter`_
66+
annotation from the SensioFrameworkExtraBundle. If you have that bundle
67+
installed in your project, add this config to disable the auto-conversion of
68+
type-hinted method arguments:
69+
70+
.. configuration-block::
71+
72+
.. code-block:: yaml
73+
74+
# app/config/config.yml
75+
sensio_framework_extra:
76+
request:
77+
converters: true
78+
auto_convert: false
79+
80+
.. code-block:: xml
81+
82+
<sensio-framework-extra:config>
83+
<request converters="true" auto-convert="true" />
84+
</sensio-framework-extra:config>
85+
86+
Adding a new value resolver requires creating a class that implements
87+
:class:`Symfony\\Component\\HttpKernel\\Controller\\ArgumentValueResolverInterface`
88+
and defining a service for it. The interface defines two methods:
7089

7190
``supports()``
7291
This method is used to check whether the value resolver supports the
@@ -193,4 +212,5 @@ subrequests.
193212
$user = null``). The ``DefaultValueResolver`` is executed as the last
194213
resolver and will use the default value if no value was already resolved.
195214

215+
.. _`@ParamConverter`: https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html
196216
.. _`yield`: http://php.net/manual/en/language.generators.syntax.php

reference/configuration/twig.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,13 @@ application harder to maintain.
121121
cache
122122
~~~~~
123123

124-
**type**: ``string`` **default**: ``'%kernel.cache_dir%/twig'``
124+
**type**: ``string`` | ``false`` | ``Twig\Cache\CacheInterface`` **default**: ``'%kernel.cache_dir%/twig'``
125125

126126
Before using the Twig templates to render some contents, they are compiled into
127127
regular PHP code. Compilation is a costly process, so the result is cached in
128128
the directory defined by this configuration option.
129129

130-
Set this option to ``null`` to disable Twig template compilation. However, this
130+
Set this option to ``false`` to disable Twig template compilation. However, this
131131
is not recommended; not even in the ``dev`` environment, because the
132132
``auto_reload`` option ensures that cached templates which have changed get
133133
compiled again.

reference/forms/types/text.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ The TextType field represents the most basic input text field.
99
+-------------+--------------------------------------------------------------------+
1010
| Rendered as | ``input`` ``text`` field |
1111
+-------------+--------------------------------------------------------------------+
12-
| Inherited | - `data`_ |
13-
| options | - `disabled`_ |
12+
| Inherited | - `attr`_ |
13+
| options | - `data`_ |
14+
| | - `disabled`_ |
1415
| | - `empty_data`_ |
1516
| | - `error_bubbling`_ |
1617
| | - `error_mapping`_ |
@@ -34,6 +35,8 @@ Inherited Options
3435

3536
These options inherit from the :doc:`FormType </reference/forms/types/form>`:
3637

38+
.. include:: /reference/forms/types/options/attr.rst.inc
39+
3740
.. include:: /reference/forms/types/options/data.rst.inc
3841

3942
.. include:: /reference/forms/types/options/disabled.rst.inc

testing.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,19 @@ will no longer be followed::
553553

554554
$client->followRedirects(false);
555555

556+
Reporting Exceptions
557+
~~~~~~~~~~~~~~~~~~~~
558+
559+
.. versionadded:: 3.4
560+
The ``catchExceptions()`` method was introduced in Symfony 3.4.
561+
562+
Debugging exceptions in functional tests may be difficult because by default
563+
they are caught and you need to look at the logs to see which exception was
564+
thrown. Disabling catching of exceptions in the test client allows the exception
565+
to be reported by PHPUnit::
566+
567+
$client->catchExceptions(false);
568+
556569
.. index::
557570
single: Tests; Crawler
558571

0 commit comments

Comments
 (0)