Skip to content

Commit 4052620

Browse files
committed
minor #11949 validation config path (wimme002)
This PR was submitted for the 4.2 branch but it was merged into the 4.3 branch instead (closes #11949). Discussion ---------- validation config path When looking at the docs, it seems that you can only use 1 file (validation.yaml|xml) for your validation config. Symfony looks for all the files in config/validator <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/roadmap for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `master` for features of unreleased versions). --> Commits ------- 643b1a9 Update validation.rst
2 parents 242aed3 + 643b1a9 commit 4052620

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

validation.rst

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ application. The goal of validation is to tell you if the data
4444
of an object is valid. For this to work, you'll configure a list of rules
4545
(called :ref:`constraints <validation-constraints>`) that the object must
4646
follow in order to be valid. These rules are usually defined using PHP code or
47-
annotations but they can also be defined as a ``validation.yaml`` or
48-
``validation.xml`` file inside the ``config/validator/`` directory:
47+
annotations but they can also be defined as ``.yaml`` or
48+
``.xml`` files inside the ``config/validator/`` directory:
4949

5050
For example, to guarantee that the ``$name`` property is not empty, add the
5151
following:
@@ -279,6 +279,53 @@ previous configuration by the following:
279279
],
280280
]);
281281
282+
By default, config files are located in the ``config/validator/`` directory.
283+
It is possible to define an array of paths with files or directories where the component will look for additional validation files:
284+
285+
.. configuration-block::
286+
287+
.. code-block:: yaml
288+
289+
# config/packages/framework.yaml
290+
framework:
291+
validation:
292+
mapping:
293+
paths:
294+
- "%kernel.project_dir%/validation/"
295+
296+
.. code-block:: xml
297+
298+
<!-- config/packages/framework.xml -->
299+
<?xml version="1.0" encoding="UTF-8" ?>
300+
<container xmlns="http://symfony.com/schema/dic/services"
301+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
302+
xmlns:framework="http://symfony.com/schema/dic/symfony"
303+
xsi:schemaLocation="http://symfony.com/schema/dic/services
304+
https://symfony.com/schema/dic/services/services-1.0.xsd
305+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
306+
307+
<framework:config>
308+
<framework:validation>
309+
<framework:mapping>
310+
<framework:path>%kernel.project_dir%/validation</framework:path>
311+
</framework:mapping>
312+
</framework:validation>
313+
</framework:config>
314+
</container>
315+
316+
.. code-block:: php
317+
318+
// config/packages/framework.php
319+
$container->loadFromExtension('framework', [
320+
'validation' => [
321+
'mapping' => [
322+
'paths' => [
323+
'%kernel.project_dir%/validation',
324+
],
325+
],
326+
],
327+
]);
328+
282329
.. index::
283330
single: Validation; Constraints
284331

0 commit comments

Comments
 (0)