Skip to content

Commit e20dee1

Browse files
committed
Merge branch '5.2' into 5.3
* 5.2: Remove manual enabling of validation and validator annotations
2 parents 59044d0 + 4e7f2cb commit e20dee1

File tree

2 files changed

+12
-88
lines changed

2 files changed

+12
-88
lines changed

reference/configuration/framework.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2621,6 +2621,8 @@ enabled
26212621

26222622
**type**: ``boolean`` **default**: ``true`` or ``false`` depending on your installation
26232623

2624+
.. _reference-validation:
2625+
26242626
validation
26252627
~~~~~~~~~~
26262628

validation.rst

Lines changed: 10 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ into a database or passed to a web service.
1111
Symfony provides a `Validator`_ component to handle this for you. This
1212
component is based on the `JSR303 Bean Validation specification`_.
1313

14+
.. index::
15+
pair: Validation; Installation
16+
pair: Validation; Configuration
17+
1418
Installation
1519
------------
1620

@@ -21,6 +25,12 @@ install the validator before using it:
2125
2226
$ composer require symfony/validator doctrine/annotations
2327
28+
.. note::
29+
30+
If your application doesn't use Symfony Flex, you might need to do some
31+
manual configuration to enable validation. Check out the
32+
:ref:`Validation configuration reference <reference-validation>`.
33+
2434
.. index::
2535
single: Validation; The basics
2636

@@ -220,94 +230,6 @@ Inside the template, you can output the list of errors exactly as needed:
220230
Each validation error (called a "constraint violation"), is represented by
221231
a :class:`Symfony\\Component\\Validator\\ConstraintViolation` object.
222232

223-
.. index::
224-
pair: Validation; Configuration
225-
226-
Configuration
227-
-------------
228-
229-
Before using the Symfony validator, make sure it's enabled in the main config
230-
file:
231-
232-
.. configuration-block::
233-
234-
.. code-block:: yaml
235-
236-
# config/packages/framework.yaml
237-
framework:
238-
validation: { enabled: true }
239-
240-
.. code-block:: xml
241-
242-
<!-- config/packages/framework.xml -->
243-
<?xml version="1.0" encoding="UTF-8" ?>
244-
<container xmlns="http://symfony.com/schema/dic/services"
245-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
246-
xmlns:framework="http://symfony.com/schema/dic/symfony"
247-
xsi:schemaLocation="http://symfony.com/schema/dic/services
248-
https://symfony.com/schema/dic/services/services-1.0.xsd
249-
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
250-
251-
<framework:config>
252-
<framework:validation enabled="true"/>
253-
</framework:config>
254-
</container>
255-
256-
.. code-block:: php
257-
258-
// config/packages/framework.php
259-
use Symfony\Config\FrameworkConfig;
260-
261-
return static function (FrameworkConfig $framework) {
262-
$framework->validation()
263-
->enabled(true)
264-
;
265-
};
266-
267-
Besides, if you plan to use annotations to configure validation, replace the
268-
previous configuration by the following:
269-
270-
.. configuration-block::
271-
272-
.. code-block:: yaml
273-
274-
# config/packages/framework.yaml
275-
framework:
276-
validation: { enable_annotations: true }
277-
278-
.. code-block:: xml
279-
280-
<!-- config/packages/framework.xml -->
281-
<?xml version="1.0" encoding="UTF-8" ?>
282-
<container xmlns="http://symfony.com/schema/dic/services"
283-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
284-
xmlns:framework="http://symfony.com/schema/dic/symfony"
285-
xsi:schemaLocation="http://symfony.com/schema/dic/services
286-
https://symfony.com/schema/dic/services/services-1.0.xsd
287-
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
288-
289-
<framework:config>
290-
<framework:validation enable-annotations="true"/>
291-
</framework:config>
292-
</container>
293-
294-
.. code-block:: php
295-
296-
// config/packages/framework.php
297-
use Symfony\Config\FrameworkConfig;
298-
299-
return static function (FrameworkConfig $framework) {
300-
$framework->validation()
301-
->enableAnnotations(true)
302-
;
303-
};
304-
305-
.. tip::
306-
307-
When using PHP, YAML, and XML files instead of annotations, Symfony looks
308-
for by default in the ``config/validator/`` directory, but you can configure
309-
other directories with the :ref:`validation.mapping.paths <reference-validation-mapping>` option.
310-
311233
.. index::
312234
single: Validation; Constraints
313235

0 commit comments

Comments
 (0)