Skip to content
Closed
Changes from 1 commit
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
20 changes: 10 additions & 10 deletions reference/constraints/NegativeOrZero.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Basic Usage

The following constraint ensure that:

* the ``withdraw`` of a bankaccount ``TransferItem`` is a negative number or equal to zero
* the ``level`` of a ``UnderGroundGarage`` is a negative number or equal to zero

.. configuration-block::

Expand All @@ -35,20 +35,20 @@ The following constraint ensure that:

use Symfony\Component\Validator\Constraints as Assert;

class TransferItem
class UnderGroundGarage
{
/**
* @Assert\NegativeOrZero
*/
protected $withdraw;
protected $level;
}

.. code-block:: yaml

# config/validator/validation.yaml
App\Entity\TransferItem:
App\Entity\UnderGroundGarage:
properties:
withdraw:
level:
- NegativeOrZero

.. code-block:: xml
Expand All @@ -59,26 +59,26 @@ The following constraint ensure that:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping https://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">

<class name="App\Entity\TransferItem">
<property name="withdraw">
<class name="App\Entity\UnderGroundGarage">
<property name="level">
<constraint name="NegativeOrZero"></constraint>
</property>
</class>
</constraint-mapping>

.. code-block:: php

// src/Entity/TransferItem.php
// src/Entity/UnderGroundGarage.php
namespace App\Entity;

use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints as Assert;

class TransferItem
class UnderGroundGarage
{
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('withdraw', new Assert\NegativeOrZero());
$metadata->addPropertyConstraint('level', new Assert\NegativeOrZero());
}
}

Expand Down