From 16de4a9f8a7620b04abec7fd7fd2282fe7d09f48 Mon Sep 17 00:00:00 2001 From: popsorin Date: Thu, 21 Oct 2021 15:21:37 +0300 Subject: [PATCH 1/5] [Validator] Add documentation for the CidrValidator --- reference/constraints/Cidr.rst | 155 +++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 reference/constraints/Cidr.rst diff --git a/reference/constraints/Cidr.rst b/reference/constraints/Cidr.rst new file mode 100644 index 00000000000..8f415162437 --- /dev/null +++ b/reference/constraints/Cidr.rst @@ -0,0 +1,155 @@ +Cidr +== + +Validates that a value is a valid CIDR notation. By default, this will validate +the CIDR's IP and netmask both for version 4 and version 6, with the option of allowing +only one type of IP version to be valid. It also supports a minimum and maximum range +constraint in which the value of the netmask is valid. + +========== =================================================================== +Applies to :ref:`property or method ` +Options - `groups`_ + - `message`_ + - `netmaskRangeViolationMessage`_ + - `payload`_ + - `version`_ +Class :class:`Symfony\\Component\\Validator\\Constraints\\Cidr` +Validator :class:`Symfony\\Component\\Validator\\Constraints\\CidrValidator` +========== =================================================================== + +Basic Usage +----------- + +.. configuration-block:: + + .. code-block:: php-annotations + + // src/Entity/Author.php + namespace App\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + class Author + { + /** + * @Assert\Cidr + */ + protected $cidrNotation; + } + + .. code-block:: php-attributes + + // src/Entity/Author.php + namespace App\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + class Author + { + #[Assert\Cidr] + protected $cidrNotation; + } + + .. code-block:: yaml + + # config/validator/validation.yaml + App\Entity\Author: + properties: + cidrNotation: + - Cidr: ~ + + .. code-block:: xml + + + + + + + + + + + + + .. code-block:: php + + // src/Entity/Author.php + namespace App\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + use Symfony\Component\Validator\Mapping\ClassMetadata; + + class Author + { + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->addPropertyConstraint('cidrNotation', new Assert\Cidr()); + } + } + +.. include:: /reference/constraints/_empty-values-are-valid.rst.inc + +Options +------- + +.. include:: /reference/constraints/_groups-option.rst.inc + +``message`` +~~~~~~~~~~~ + +**type**: ``string`` **default**: ``This value is not a valid CIDR notation.`` + +This message is shown if the string is not a valid CIDR notation. + +``netmaskMin`` +~~~~~~~~~~~ + +**type**: ``integer`` **default**: ``0`` + +It's a constraint for the lowest value a valid netmask may have. + +``netmaskMax`` +~~~~~~~~~~~ + +**type**: ``string`` **default**: ``32 for IPv4 or 128 for IPv6`` + +It's a constraint for the biggest value a valid netmask may have. + +``netmaskRangeViolationMessage`` +~~~~~~~~~~~ + +**type**: ``string`` **default**: ``The value of the netmask should be between {{ min }} and {{ max }}.`` + +This message is shown if the value of the CIDR's netmask is bigger then the value of the `max_` or lower than +the value of the `min_`. + +You can use the following parameters in this message: + +=============== ============================================================== +Parameter Description +=============== ============================================================== +``{{ min }}`` The minimum value a CIDR netmask may have +``{{ max }}`` The maximum value a CIDR netmask may have +=============== ============================================================== + +.. include:: /reference/constraints/_payload-option.rst.inc + +``version`` +~~~~~~~~~~~ + +**type**: ``string`` **default**: ``all`` + +This determines exactly *how* the CIDR notation is validated and can take one +of a variety of different values: + +**All ranges** + +``4`` + Validates for CIDR notations that have an IPv4. +``6`` + Validates for CIDR notations that have an IPv6. +``all`` + Validates all CIDR formats + From f32ee434c78f0210b1630aecf31b2c89a80f0074 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Sat, 6 Nov 2021 16:30:26 +0100 Subject: [PATCH 2/5] Minor tweaks --- reference/constraints/Cidr.rst | 20 ++++++++++---------- reference/constraints/map.rst.inc | 1 + 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/reference/constraints/Cidr.rst b/reference/constraints/Cidr.rst index 8f415162437..658a9910b7c 100644 --- a/reference/constraints/Cidr.rst +++ b/reference/constraints/Cidr.rst @@ -1,18 +1,17 @@ Cidr -== +==== -Validates that a value is a valid CIDR notation. By default, this will validate -the CIDR's IP and netmask both for version 4 and version 6, with the option of allowing -only one type of IP version to be valid. It also supports a minimum and maximum range -constraint in which the value of the netmask is valid. +.. versionadded:: 5.4 + + The ``Cidr`` constraint was introduced in Symfony 5.4. + +Validates that a value is a valid `CIDR`_ (Classless Inter-Domain Routing) notation. +By default, this will validate the CIDR's IP and netmask both for version 4 and 6, +with the option of allowing only one type of IP version to be valid. It also supports +a minimum and maximum range constraint in which the value of the netmask is valid. ========== =================================================================== Applies to :ref:`property or method ` -Options - `groups`_ - - `message`_ - - `netmaskRangeViolationMessage`_ - - `payload`_ - - `version`_ Class :class:`Symfony\\Component\\Validator\\Constraints\\Cidr` Validator :class:`Symfony\\Component\\Validator\\Constraints\\CidrValidator` ========== =================================================================== @@ -153,3 +152,4 @@ of a variety of different values: ``all`` Validates all CIDR formats +.. _`CIDR`: https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing diff --git a/reference/constraints/map.rst.inc b/reference/constraints/map.rst.inc index d6b974cefb3..9f8eb4b8c3f 100644 --- a/reference/constraints/map.rst.inc +++ b/reference/constraints/map.rst.inc @@ -22,6 +22,7 @@ String Constraints * :doc:`Regex ` * :doc:`Hostname ` * :doc:`Ip ` +* :doc:`Cidr ` * :doc:`Json ` * :doc:`Uuid ` * :doc:`Ulid ` From 1fb1f9919b36cc1b78ff9ebea6378e313b905147 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Sat, 6 Nov 2021 16:42:26 +0100 Subject: [PATCH 3/5] Remove the versionadded directive --- reference/constraints/Cidr.rst | 4 ---- 1 file changed, 4 deletions(-) diff --git a/reference/constraints/Cidr.rst b/reference/constraints/Cidr.rst index 658a9910b7c..3bc3dcf3dec 100644 --- a/reference/constraints/Cidr.rst +++ b/reference/constraints/Cidr.rst @@ -1,10 +1,6 @@ Cidr ==== -.. versionadded:: 5.4 - - The ``Cidr`` constraint was introduced in Symfony 5.4. - Validates that a value is a valid `CIDR`_ (Classless Inter-Domain Routing) notation. By default, this will validate the CIDR's IP and netmask both for version 4 and 6, with the option of allowing only one type of IP version to be valid. It also supports From d92e0f8c566ee62840caf12b0a6eb5cbe61b5941 Mon Sep 17 00:00:00 2001 From: BahmanMD Date: Sun, 7 Nov 2021 10:01:01 +0330 Subject: [PATCH 4/5] Update setup.rst for V5.4 Creating the correct command and fixing the installation problem of version 5.4 --- setup.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.rst b/setup.rst index d766fbfc5dd..122294b2e49 100644 --- a/setup.rst +++ b/setup.rst @@ -54,10 +54,10 @@ application: .. code-block:: terminal # run this if you are building a traditional web application - $ symfony new my_project_name --version=next --full + $ symfony new my_project_name --version="5.4.x@dev" --full # run this if you are building a microservice, console application or API - $ symfony new my_project_name --version=next + $ symfony new my_project_name --version="5.4.x@dev" The only difference between these two commands is the number of packages installed by default. The ``--full`` option installs all the packages that you From 3976f357240458a9ebc59de44c0ccfd0cfa7dfa1 Mon Sep 17 00:00:00 2001 From: BahmanMD Date: Sun, 7 Nov 2021 10:04:56 +0330 Subject: [PATCH 5/5] Update setup.rst for V6.0 Creating the correct command and fixing the installation problem of version 6.0 --- setup.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.rst b/setup.rst index 5d1ac071551..f6e35a764f5 100644 --- a/setup.rst +++ b/setup.rst @@ -54,10 +54,10 @@ application: .. code-block:: terminal # run this if you are building a traditional web application - $ symfony new my_project_name --version="5.4.x@dev" --full + $ symfony new my_project_name --version="6.0.x@dev" --full # run this if you are building a microservice, console application or API - $ symfony new my_project_name --version="5.4.x@dev" + $ symfony new my_project_name --version="6.0.x@dev" The only difference between these two commands is the number of packages installed by default. The ``--full`` option installs all the packages that you