Skip to content

Fixing error at Class Constraint Validator #11180

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
Mar 18, 2019
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
14 changes: 7 additions & 7 deletions validation/custom_constraint.rst
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,15 @@ with the necessary ``validator.constraint_validator``. This means you can
Class Constraint Validator
~~~~~~~~~~~~~~~~~~~~~~~~~~

Beside validating a class property, a constraint can have a class scope by
providing a target in its ``Constraint`` class::
Besides validating a single property, a constraint can have an entire class
as its scope. Just add this to the ``Constraint`` class::

public function getTargets()
{
return self::CLASS_CONSTRAINT;
}

With this, the validator ``validate()`` method gets an object as its first argument::
With this, the validator's ``validate()`` method gets an object as its first argument::

class ProtocolClassValidator extends ConstraintValidator
{
Expand All @@ -206,15 +206,15 @@ With this, the validator ``validate()`` method gets an object as its first argum
associated to. Use any :doc:`valid PropertyAccess syntax </components/property_access>`
to define that property.

Note that a class constraint validator is applied to the class itself, and
A class constraint validator is applied to the class itself, and
not to the property:

.. configuration-block::

.. code-block:: php-annotations

/**
* @AcmeAssert\ProtocolClassValidator
* @AcmeAssert\ProtocolClass
*/
class AcmeEntity
{
Expand All @@ -226,11 +226,11 @@ not to the property:
# src/AppBundle/Resources/config/validation.yml
AppBundle\Entity\AcmeEntity:
constraints:
- AppBundle\Validator\Constraints\ProtocolClassValidator: ~
- AppBundle\Validator\Constraints\ProtocolClass: ~

.. code-block:: xml

<!-- src/AppBundle/Resources/config/validation.xml -->
<class name="AppBundle\Entity\AcmeEntity">
<constraint name="AppBundle\Validator\Constraints\ProtocolClassValidator"/>
<constraint name="AppBundle\Validator\Constraints\ProtocolClass"/>
</class>