8000 Merge branch '4.1' · symfony/symfony-docs@de0f01a · GitHub
[go: up one dir, main page]

Skip to content

Commit de0f01a

Browse files
committed
Merge branch '4.1'
* 4.1: Updated the Symfony Flex server Updated some config for Symfony 4 practices 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 5ae6670 + 0746f65 commit de0f01a

File tree

9 files changed

+110
-58
lines changed

9 files changed

+110
-58
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

doctrine/multiple_entity_managers.rst

Lines changed: 28 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,17 @@ The following configuration code shows how you can configure two entity managers
3434
default_connection: default
3535
connections:
3636
default:
37-
driver: pdo_mysql
38-
host: '%database_host%'
39-
port: '%database_port%'
40-
dbname: '%database_name%'
41-
user: '%database_user%'
42-
password: '%database_password%'
43-
charset: UTF8
37+
# configure these for your database server
38+
url: '%env(DATABASE_URL)%'
39+
driver: 'pdo_mysql'
40+
server_version: '5.7'
41+
charset: utf8mb4
4442
customer:
45-
driver: pdo_mysql
46-
host: '%database_host2%'
47-
port: '%database_port2%'
48-
dbname: '%database_name2%'
49-
user: '%database_user2%'
50-
password: '%database_password2%'
51-
charset: UTF8
43+
# configure these for your database server
44+
url: '%env(DATABASE_CUSTOMER_URL)%'
45+
driver: 'pdo_mysql'
46+
server_version: '5.7'
47+
charset: utf8mb4
5248
5349
orm:
5450
default_entity_manager: default
@@ -86,24 +82,20 @@ The following configuration code shows how you can configure two entity managers
8682
8783
<doctrine:config>
8884
<doctrine:dbal default-connection="default">
85+
<!-- configure these for your database server -->
8986
<doctrine:connection name="default"
87+
url="%env(DATABASE_URL)%"
9088
driver="pdo_mysql"
91-
host="%database_host%"
92-
port="%database_port%"
93-
dbname="%database_name%"
94-
user="%database_user%"
95-
password="%database_password%"
96-
charset="UTF8"
89+
server_version="5.7"
90+
charset="utf8mb4"
9791
/>
9892
93+
<!-- configure these for your database server -->
9994
<doctrine:connection name="customer"
95+
url="%env(DATABASE_CUSTOMER_URL)%"
10096
driver="pdo_mysql"
101-
host="%database_host2%"
102-
port="%database_port2%"
103-
dbname="%database_name2%"
104-
user="%database_user2%"
105-
password="%database_password2%"
106-
charset="UTF8"
97+
server_version="5.7"
98+
charset="utf8mb4"
10799
/>
108100
</doctrine:dbal>
109101
@@ -140,23 +132,19 @@ The following configuration code shows how you can configure two entity managers
140132
'dbal' => array(
141133
'default_connection' => 'default',
142134
'connections' => array(
135+
// configure these for your database server
143136
'default' => array(
144-
'driver' => 'pdo_mysql',
145-
'host' => '%database_host%',
146-
'port' => '%database_port%',
147-
'dbname' => '%database_name%',
148-
'user' => '%database_user%',
149-
'password' => '%database_password%',
150-
'charset' => 'UTF8',
137+
'url' => '%env(DATABASE_URL)%',
138+
'driver' => 'pdo_mysql',
139+
'server_version' => '5.7',
140+
'charset' => 'utf8mb4',
151141
),
142+
// configure these for your database server
152143
'customer' => array(
153-
'driver' => 'pdo_mysql',
154-
'host' => '%database_host2%',
155-
'port' => '%database_port2%',
156-
'dbname' => '%database_name2%',
157-
'user' => '%database_user2%',
158-
'password' => '%database_password2%',
159-
'charset' => 'UTF8',
144+
'url' => '%env(DATABASE_CUSTOMER_URL)%',
145+
'driver' => 'pdo_mysql',
146+
'server_version' => '5.7',
147+
'charset' => 'utf8mb4',
160148
),
161149
),
162150
),

page_creation.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ that Flex resolves to ``sensio/framework-extra-bundle``.
147147

148148
Second, after this package was downloaded, Flex executed a *recipe*, which is a
149149
set of automated instructions that tell Symfony how to integrate an external
150-
package. Flex recipes exist for many packages (see `symfony.sh`_) and have the ability
150+
package. `Flex recipes`_ exist for many packages and have the ability
151151
to do a lot, like adding configuration files, creating directories, updating ``.gitignore``
152152
and adding new config to your ``.env`` file. Flex *automates* the installation of
153153
packages so you can get back to coding.
@@ -355,4 +355,4 @@ Go Deeper with HTTP & Framework Fundamentals
355355
.. _`Twig`: https://twig.symfony.com
356356
.. _`Composer`: https://getcomposer.org
357357
.. _`Stellar Development with Symfony`: https://knpuniversity.com/screencast/symfony/setup
358-
.. _`symfony.sh`: https://symfony.sh/
358+
.. _`Flex recipes`: https://flex.symfony.com

quick_tour/flex_recipes.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ It's a way for a library to automatically configure itself by adding and modifyi
5353
files. Thanks to recipes, adding features is seamless and automated: install a package
5454
and you're done!
5555

56-
You can find a full list of recipes and aliases by going to `https://symfony.sh`_.
56+
You can find a full list of recipes and aliases by going to `https://flex.symfony.com`_.
5757

5858
What did this recipe do? In addition to automatically enabling the feature in
5959
``config/bundles.php``, it added 3 things:
@@ -258,6 +258,6 @@ and it's the most important yet. I want to show you how Symfony empowers you to
258258
build features *without* sacrificing code quality or performance. It's all about
259259
the service container, and it's Symfony's super power. Read on: about :doc:`/quick_tour/the_architecture`.
260260

261-
.. _`https://symfony.sh`: https://symfony.sh
261+
.. _`https://flex.symfony.com`: https://flex.symfony.com
262262
.. _`Api Platform`: https://api-platform.com/
263263
.. _`Twig`: https://twig.symfony.com/

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`_ |
@@ -35,6 +36,8 @@ Inherited Options
3536

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

39+
.. include:: /reference/forms/types/options/attr.rst.inc
40+
3841
.. include:: /reference/forms/types/options/data.rst.inc
3942

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

testing.rst

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

572572
$client->followRedirects(false);
573573

574+
Reporting Exceptions
575+
~~~~~~~~~~~~~~~~~~~~
576+
577+
.. versionadded:: 3.4
578+
The ``catchExceptions()`` method was introduced in Symfony 3.4.
579+
580+
Debugging exceptions in functional tests may be difficult because by default
581+
they are caught and you need to look at the logs to see which exception was
582+
thrown. Disabling catching of exceptions in the test client allows the exception
583+
to be reported by PHPUnit::
584+
585+
$client->catchExceptions(false);
586+
574587
.. index::
575588
single: Tests; Crawler
576589

0 commit comments

Comments
 (0)
0