diff --git a/reference/constraints.rst b/reference/constraints.rst index d81a4eefd37..2e30e3ee19f 100644 --- a/reference/constraints.rst +++ b/reference/constraints.rst @@ -32,6 +32,11 @@ Validation Constraints Reference constraints/Range constraints/DivisibleBy + constraints/Positive + constraints/PositiveOrZero + constraints/Negative + constraints/NegativeOrZero + constraints/Date constraints/DateTime constraints/Time diff --git a/reference/constraints/Negative.rst b/reference/constraints/Negative.rst new file mode 100644 index 00000000000..0a3e91c4fce --- /dev/null +++ b/reference/constraints/Negative.rst @@ -0,0 +1,106 @@ +Negative +======== + +.. versionadded:: 4.3 + + The ``Negative`` constraint was introduced in Symfony 4.3. + +Validates that a value is a negative number. To force that a value is a negative +number or equal to zero, see :doc:`/reference/constraints/NegativeOrZero`. +To force a value is positive, see :doc:`/reference/constraints/Positive`. + +========== =================================================================== +Applies to :ref:`property or method ` +Options - `groups`_ + - `message`_ + - `payload`_ +Class :class:`Symfony\\Component\\Validator\\Constraints\\Negative` +Validator :class:`Symfony\\Component\\Validator\\Constraints\\LesserThanValidator` +========== =================================================================== + +Basic Usage +----------- + +The following constraint ensure that: + +* the ``withdraw`` of a bankaccount ``TransferItem`` is a negative number (lesser than zero) + +.. configuration-block:: + + .. code-block:: php-annotations + + // src/Entity/TransferItem.php + namespace App\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + class TransferItem + { + /** + * @Assert\Negative + */ + protected $withdraw; + } + + .. code-block:: yaml + + # config/validator/validation.yaml + App\Entity\TransferItem: + properties: + withdraw: + - Negative + + .. code-block:: xml + + + + + + + + + + + + + .. code-block:: php + + // src/Entity/TransferItem.php + namespace App\Entity; + + use Symfony\Component\Validator\Mapping\ClassMetadata; + use Symfony\Component\Validator\Constraints as Assert; + + class TransferItem + { + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->addPropertyConstraint('withdraw', new Assert\Negative()); + } + } + +Available Options +----------------- + +.. include:: /reference/constraints/_groups-option.rst.inc + +message +~~~~~~~ + +**type**: ``string`` **default**: ``This value should be negative.`` + +The default message supplied when the value is not less than zero. + +You can use the following parameters in this message: + +============================= ================================================ +Parameter Description +============================= ================================================ +``{{ compared_value }}`` Always zero +``{{ compared_value_type }}`` The expected value type +``{{ value }}`` The current (invalid) value +============================= ================================================ + +.. include:: /reference/constraints/_payload-option.rst.inc diff --git a/reference/constraints/NegativeOrZero.rst b/reference/constraints/NegativeOrZero.rst new file mode 100644 index 00000000000..7d0dc452a5f --- /dev/null +++ b/reference/constraints/NegativeOrZero.rst @@ -0,0 +1,107 @@ +NegativeOrZero +============== + +.. versionadded:: 4.3 + + The ``NegativeOrZero`` constraint was introduced in Symfony 4.3. + +Validates that a value is a negative number or equal to zero. To force that a value +is only a negative number, see :doc:`/reference/constraints/Negative`. +To force a value is positive or equal to zero, +see :doc:`/reference/constraints/PositiveOrZero`. + +========== =================================================================== +Applies to :ref:`property or method ` +Options - `groups`_ + - `message`_ + - `payload`_ +Class :class:`Symfony\\Component\\Validator\\Constraints\\NegativeOrZero` +Validator :class:`Symfony\\Component\\Validator\\Constraints\\LesserThanOrEqualValidator` +========== =================================================================== + +Basic Usage +----------- + +The following constraint ensure that: + +* the ``level`` of a ``UnderGroundGarage`` is a negative number or equal to zero + +.. configuration-block:: + + .. code-block:: php-annotations + + // src/Entity/TransferItem.php + namespace App\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + class UnderGroundGarage + { + /** + * @Assert\NegativeOrZero + */ + protected $level; + } + + .. code-block:: yaml + + # config/validator/validation.yaml + App\Entity\UnderGroundGarage: + properties: + level: + - NegativeOrZero + + .. code-block:: xml + + + + + + + + + + + + + .. code-block:: php + + // src/Entity/UnderGroundGarage.php + namespace App\Entity; + + use Symfony\Component\Validator\Mapping\ClassMetadata; + use Symfony\Component\Validator\Constraints as Assert; + + class UnderGroundGarage + { + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->addPropertyConstraint('level', new Assert\NegativeOrZero()); + } + } + +Available Options +----------------- + +.. include:: /reference/constraints/_groups-option.rst.inc + +message +~~~~~~~ + +**type**: ``string`` **default**: ``This value should be either negative or zero.`` + +The default message supplied when the value is not less than or equal to zero. + +You can use the following parameters in this message: + +============================= ================================================ +Parameter Description +============================= ================================================ +``{{ compared_value }}`` Always zero +``{{ compared_value_type }}`` The expected value type +``{{ value }}`` The current (invalid) value +============================= ================================================ + +.. include:: /reference/constraints/_payload-option.rst.inc \ No newline at end of file diff --git a/reference/constraints/Positive.rst b/reference/constraints/Positive.rst new file mode 100644 index 00000000000..1897758c3bf --- /dev/null +++ b/reference/constraints/Positive.rst @@ -0,0 +1,106 @@ +Positive +======== + +.. versionadded:: 4.3 + + The ``Positive`` constraint was introduced in Symfony 4.3. + +Validates that a value is a positive number. To force that a value is positive +number or equal to zero, see :doc:`/reference/constraints/PositiveOrZero`. +To force a value is negative, see :doc:`/reference/constraints/Negative`. + +========== =================================================================== +Applies to :ref:`property or method ` +Options - `groups`_ + - `message`_ + - `payload`_ +Class :class:`Symfony\\Component\\Validator\\Constraints\\Positive` +Validator :class:`Symfony\\Component\\Validator\\Constraints\\GreaterThanValidator` +========== =================================================================== + +Basic Usage +----------- + +The following constraint ensure that: + +* the ``income`` of an ``Employee`` is a positive number (greater than zero) + +.. configuration-block:: + + .. code-block:: php-annotations + + // src/Entity/Employee.php + namespace App\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + class Employee + { + /** + * @Assert\Positive + */ + protected $income; + } + + .. code-block:: yaml + + # config/validator/validation.yaml + App\Entity\Employee: + properties: + income: + - Positive + + .. code-block:: xml + + + + + + + + + + + + + .. code-block:: php + + // src/Entity/Employee.php + namespace App\Entity; + + use Symfony\Component\Validator\Mapping\ClassMetadata; + use Symfony\Component\Validator\Constraints as Assert; + + class Employee + { + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->addPropertyConstraint('income', new Assert\Positive()); + } + } + +Available Options +----------------- + +.. include:: /reference/constraints/_groups-option.rst.inc + +message +~~~~~~~ + +**type**: ``string`` **default**: ``This value should be positive.`` + +The default message supplied when the value is not greater than zero. + +You can use the following parameters in this message: + +============================= ================================================ +Parameter Description +============================= ================================================ +``{{ compared_value }}`` Always zero +``{{ compared_value_type }}`` The expected value type +``{{ value }}`` The current (invalid) value +============================= ================================================ + +.. include:: /reference/constraints/_payload-option.rst.inc diff --git a/reference/constraints/PositiveOrZero.rst b/reference/constraints/PositiveOrZero.rst new file mode 100644 index 00000000000..44e736ee044 --- /dev/null +++ b/reference/constraints/PositiveOrZero.rst @@ -0,0 +1,107 @@ +PositiveOrZero +============== + +.. versionadded:: 4.3 + + The ``PositiveOrZero`` constraint was introduced in Symfony 4.3. + +Validates that a value is a positive number or equal to zero. To force that +a value is only a positiven umber, see :doc:`/reference/constraints/Positive`. +To force a value is negative or equal to zero, +see :doc:`/reference/constraints/NegativeOrZero`. + +========== =================================================================== +Applies to :ref:`property or method ` +Options - `groups`_ + - `message`_ + - `payload`_ +Class :class:`Symfony\\Component\\Validator\\Constraints\\PositiveOrZero` +Validator :class:`Symfony\\Component\\Validator\\Constraints\\GreaterThanOrEqualValidator` +========== =================================================================== + +Basic Usage +----------- + +The following constraint ensure that: + +* the number of ``siblings`` of a ``Person`` is positive or zero + +.. configuration-block:: + + .. code-block:: php-annotations + + // src/Entity/Person.php + namespace App\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + class Person + { + /** + * @Assert\PositiveOrZero + */ + protected $siblings; + } + + .. code-block:: yaml + + # config/validator/validation.yaml + App\Entity\Person: + properties: + siblings: + - PositiveOrZero + + .. code-block:: xml + + + + + + + + + + + + + .. code-block:: php + + // src/Entity/Person.php + namespace App\Entity; + + use Symfony\Component\Validator\Mapping\ClassMetadata; + use Symfony\Component\Validator\Constraints as Assert; + + class Person + { + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->addPropertyConstraint('siblings', new Assert\PositiveOrZero()); + } + } + +Available Options +----------------- + +.. include:: /reference/constraints/_groups-option.rst.inc + +message +~~~~~~~ + +**type**: ``string`` **default**: ``This value should be either positive or zero.`` + +The default message supplied when the value is not greater than or equal to zero. + +You can use the following parameters in this message: + +============================= ================================================ +Parameter Description +============================= ================================================ +``{{ compared_value }}`` Always zero +``{{ compared_value_type }}`` The expected value type +``{{ value }}`` The current (invalid) value +============================= ================================================ + +.. include:: /reference/constraints/_payload-option.rst.inc diff --git a/reference/constraints/map.rst.inc b/reference/constraints/map.rst.inc index 4f95a168242..5402a2fd0d2 100644 --- a/reference/constraints/map.rst.inc +++ b/reference/constraints/map.rst.inc @@ -38,6 +38,13 @@ Comparison Constraints * :doc:`Range ` * :doc:`DivisibleBy ` +Number Constraints +~~~~~~~~~~~~~~~~~~ +* :doc:`Positive ` +* :doc:`PositiveOrZero ` +* :doc:`Negative ` +* :doc:`NegativeOrZero ` + Date Constraints ~~~~~~~~~~~~~~~~ pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy