Skip to content

[Validator] Cidr constraint tweaks #16099

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 12, 2021
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
45 changes: 20 additions & 25 deletions reference/constraints/Cidr.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ Basic Usage

.. code-block:: php-annotations

// src/Entity/Author.php
// src/Entity/NetworkSettings.php
namespace App\Entity;

use Symfony\Component\Validator\Constraints as Assert;

class Author
class NetworkSettings
{
/**
* @Assert\Cidr
Expand All @@ -38,12 +38,12 @@ Basic Usage

.. code-block:: php-attributes

// src/Entity/Author.php
// src/Entity/NetworkSettings.php
namespace App\Entity;

use Symfony\Component\Validator\Constraints as Assert;

class Author
class NetworkSettings
{
#[Assert\Cidr]
protected $cidrNotation;
Expand All @@ -52,7 +52,7 @@ Basic Usage
.. code-block:: yaml

# config/validator/validation.yaml
App\Entity\Author:
App\Entity\NetworkSettings:
properties:
cidrNotation:
- Cidr: ~
Expand All @@ -65,7 +65,7 @@ Basic Usage
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\Author">
<class name="App\Entity\NetworkSettings">
<property name="cidrNotation">
<constraint name="Cidr"/>
</property>
Expand All @@ -74,13 +74,13 @@ Basic Usage

.. code-block:: php

// src/Entity/Author.php
// src/Entity/NetworkSettings.php
namespace App\Entity;

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

class Author
class NetworkSettings
{
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
Expand All @@ -103,34 +103,34 @@ Options
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``
**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_`.
This message is shown if the value of the CIDR's netmask is bigger than the
``netmaskMax`` value or lower than the ``netmaskMin`` value.

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
``{{ 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
Expand All @@ -141,15 +141,10 @@ Parameter Description
**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**
of these values:

``4``
Validates for CIDR notations that have an IPv4.
``6``
Validates for CIDR notations that have an IPv6.
``all``
Validates all CIDR formats
* ``4``: validates for CIDR notations that have an IPv4;
* ``6``: validates for CIDR notations that have an IPv6;
* ``all``: validates all CIDR formats.

.. _`CIDR`: https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing