Skip to content

[Validator] Documented the divisibleBy option of the Count constraint #13220

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 6, 2020
Merged
Show file tree
Hide file tree
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
42 changes: 41 additions & 1 deletion reference/constraints/Count.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Countable) element count is *between* some minimum and maximum value.

========== ===================================================================
Applies to :ref:`property or method <validation-property-target>`
Options - `exactMessage`_
Options - `divisibleBy`_
- `divisibleByMessage`_
- `exactMessage`_
- `groups`_
- `max`_
- `maxMessage`_
Expand Down Expand Up @@ -101,6 +103,44 @@ you might add the following:
Options
-------

divisibleBy
~~~~~~~~~~~

**type**: ``integer`` **default**: null

.. versionadded:: 5.1

The ``divisibleBy`` option was introduced in Symfony 5.1.

Validates that the number of elements of the given collection is divisible by
a certain number.

.. seealso::

If you need to validate that other types of data different from collections
are divisible by a certain number, use the
:doc:`DivisibleBy </reference/constraints/DivisibleBy>` constraint.

divisibleByMessage
~~~~~~~~~~~~~~~~~~

**type**: ``string`` **default**: ``The number of elements in this collection should be a multiple of {{ compared_value }}.``

.. versionadded:: 5.1

The ``divisibleByMessage`` option was introduced in Symfony 5.1.

The message that will be shown if the number of elements of the given collection
is not divisible by the number defined in the ``divisibleBy`` option.

You can use the following parameters in this message:

======================== ===================================================
Parameter Description
======================== ===================================================
``{{ compared_value }}`` The number configured in the ``divisibleBy`` option
======================== ===================================================

exactMessage
~~~~~~~~~~~~

Expand Down
6 changes: 6 additions & 0 deletions reference/constraints/DivisibleBy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ DivisibleBy

Validates that a value is divisible by another value, defined in the options.

.. seealso::

If you need to validate that the number of elements in a collection is
divisible by a certain number, use the :doc:`Count </reference/constraints/Count>`
constraint with the ``divisibleBy`` option.

========== ===================================================================
Applies to :ref:`property or method <validation-property-target>`
Options - `groups`_
Expand Down