Skip to content

[Validator] Removing the recommended Constraints subdirectory #14621

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 27, 2020
Merged
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
24 changes: 12 additions & 12 deletions validation/custom_constraint.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Creating the Constraint Class

First you need to create a Constraint class and extend :class:`Symfony\\Component\\Validator\\Constraint`::

// src/Validator/Constraints/ContainsAlphanumeric.php
namespace App\Validator\Constraints;
// src/Validator/ContainsAlphanumeric.php
namespace App\Validator;

use Symfony\Component\Validator\Constraint;

Expand Down Expand Up @@ -54,8 +54,8 @@ when actually performing the validation.

The validator class only has one required method ``validate()``::

// src/Validator/Constraints/ContainsAlphanumericValidator.php
namespace App\Validator\Constraints;
// src/Validator/ContainsAlphanumericValidator.php
namespace App\Validator;

use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
Expand All @@ -71,7 +71,7 @@ The validator class only has one required method ``validate()``::
}

// custom constraints should ignore null and empty values to allow
// other constraints (NotBlank, NotNull, etc.) take care of that
// other constraints (NotBlank, NotNull, etc.) to take care of that
if (null === $value || '' === $value) {
return;
}
Expand Down Expand Up @@ -117,7 +117,7 @@ You can use custom validators like the ones provided by Symfony itself:
// src/Entity/AcmeEntity.php
namespace App\Entity;

use App\Validator\Constraints as AcmeAssert;
use App\Validator as AcmeAssert;
use Symfony\Component\Validator\Constraints as Assert;

class AcmeEntity
Expand All @@ -140,7 +140,7 @@ You can use custom validators like the ones provided by Symfony itself:
properties:
name:
- NotBlank: ~
- App\Validator\Constraints\ContainsAlphanumeric: ~
- App\Validator\ContainsAlphanumeric: ~

.. code-block:: xml

Expand All @@ -153,7 +153,7 @@ You can use custom validators like the ones provided by Symfony itself:
<class name="App\Entity\AcmeEntity">
<property name="name">
<constraint name="NotBlank"/>
<constraint name="App\Validator\Constraints\ContainsAlphanumeric"/>
<constraint name="App\Validator\ContainsAlphanumeric"/>
</property>
</class>
</constraint-mapping>
Expand All @@ -163,7 +163,7 @@ You can use custom validators like the ones provided by Symfony itself:
// src/Entity/AcmeEntity.php
namespace App\Entity;

use App\Validator\Constraints\ContainsAlphanumeric;
use App\Validator\ContainsAlphanumeric;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Mapping\ClassMetadata;

Expand Down Expand Up @@ -241,21 +241,21 @@ not to the property:
# config/validator/validation.yaml
App\Entity\AcmeEntity:
constraints:
- App\Validator\Constraints\ProtocolClass: ~
- App\Validator\ProtocolClass: ~

.. code-block:: xml

<!-- config/validator/validation.xml -->
<class name="App\Entity\AcmeEntity">
<constraint name="App\Validator\Constraints\ProtocolClass"/>
<constraint name="App\Validator\ProtocolClass"/>
</class>

.. code-block:: php

// src/Entity/AcmeEntity.php
namespace App\Entity;

use App\Validator\Constraints\ProtocolClass;
use App\Validator\ProtocolClass;
use Symfony\Component\Validator\Mapping\ClassMetadata;

class AcmeEntity
Expand Down