Skip to content

Updated validation/* articles to Symfony 4 #8756

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion validation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ returned. Take this simple example from inside a controller::
use App\Entity\Author;

// ...
public function authorAction()
public function author()
{
$author = new Author();

Expand Down
8 changes: 4 additions & 4 deletions validation/custom_constraint.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Using custom validators is very easy, just as the ones provided by Symfony itsel

.. code-block:: yaml

# src/Resources/config/validation.yml
# config/validator/validation.yaml
App\Entity\AcmeEntity:
properties:
name:
Expand All @@ -116,7 +116,7 @@ Using custom validators is very easy, just as the ones provided by Symfony itsel

.. code-block:: xml

<!-- src/Resources/config/validation.xml -->
<!-- config/validator/validation.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand Down Expand Up @@ -202,14 +202,14 @@ not to the property:

.. code-block:: yaml

# src/Resources/config/validation.yml
# config/validator/validation.yaml
App\Entity\AcmeEntity:
constraints:
- App\Validator\Constraints\ContainsAlphanumeric: ~

.. code-block:: xml

<!-- src/Resources/config/validation.xml -->
<!-- config/validator/validation.xml -->
<class name="App\Entity\AcmeEntity">
<constraint name="App\Validator\Constraints\ContainsAlphanumeric" />
</class>
4 changes: 2 additions & 2 deletions validation/groups.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ user registers and when a user updates their contact information later:

.. code-block:: yaml

# src/Resources/config/validation.yml
# config/validator/validation.yaml
App\Entity\User:
properties:
email:
Expand All @@ -58,7 +58,7 @@ user registers and when a user updates their contact information later:

.. code-block:: xml

<!-- src/Resources/config/validation.xml -->
<!-- config/validator/validation.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand Down
2 changes: 1 addition & 1 deletion validation/raw_values.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ looks like this::
use Symfony\Component\Validator\Validator\ValidatorInterface;

// ...
public function addEmailAction($email, ValidatorInterface $validator)
public function addEmail($email, ValidatorInterface $validator)
{
$emailConstraint = new Assert\Email();
// all constraint "options" can be set this way
Expand Down
14 changes: 7 additions & 7 deletions validation/sequence_provider.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ username and the password are different only if all other validation passes

.. code-block:: yaml

# src/Resources/config/validation.yml
# config/validator/validation.yaml
App\Entity\User:
group_sequence:
- User
Expand All @@ -67,7 +67,7 @@ username and the password are different only if all other validation passes

.. code-block:: xml

<!-- src/Resources/config/validation.xml -->
<!-- config/validator/validation.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand Down Expand Up @@ -145,7 +145,7 @@ You can also define a group sequence in the ``validation_groups`` form option::
use Symfony\Component\Validator\Constraints\GroupSequence;
use Symfony\Component\Form\AbstractType;
// ...

class MyType extends AbstractType
{
// ...
Expand Down Expand Up @@ -195,7 +195,7 @@ entity and a new constraint group called ``Premium``:

.. code-block:: yaml

# src/Resources/config/validation.yml
# config/validator/validation.yaml
App\Entity\User:
properties:
name:
Expand All @@ -207,7 +207,7 @@ entity and a new constraint group called ``Premium``:

.. code-block:: xml

<!-- src/Resources/config/validation.xml -->
<!-- config/validator/validation.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand Down Expand Up @@ -308,13 +308,13 @@ provides a sequence of groups to be validated:

.. code-block:: yaml

# src/Resources/config/validation.yml
# config/validator/validation.yaml
App\Entity\User:
group_sequence_provider: true

.. code-block:: xml

<!-- src/Resources/config/validation.xml -->
<!-- config/validator/validation.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand Down
4 changes: 2 additions & 2 deletions validation/severity.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Use the ``payload`` option to configure the error level for each constraint:

.. code-block:: yaml

# src/Resources/config/validation.yml
# config/validator/validation.yaml
App\Entity\User:
properties:
username:
Expand All @@ -70,7 +70,7 @@ Use the ``payload`` option to configure the error level for each constraint:

.. code-block:: xml

<!-- src/Resources/config/validation.xml -->
<!-- config/validator/validation.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand Down
8 changes: 4 additions & 4 deletions validation/translations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ property is not empty, add the following:
}
}

Now, create a ``validators`` catalog file in the ``config/translations/`` directory:
Now, create a ``validators`` catalog file in the ``translations/`` directory:

.. configuration-block::

.. code-block:: xml

<!-- config/translations/validators.en.xlf -->
<!-- translations/validators.en.xlf -->
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
Expand All @@ -105,12 +105,12 @@ Now, create a ``validators`` catalog file in the ``config/translations/`` direct

.. code-block:: yaml

# config/translations/validators.en.yaml
# translations/validators.en.yaml
author.name.not_blank: Please enter an author name.

.. code-block:: php

// config/translations/validators.en.php
// translations/validators.en.php
return array(
'author.name.not_blank' => 'Please enter an author name.',
);
Expand Down