Skip to content

Commit bb611e2

Browse files
committed
[Validator] Documented the divisibleBy option of the Count constraint
1 parent 8bf1f5e commit bb611e2

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

reference/constraints/Count.rst

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ Countable) element count is *between* some minimum and maximum value.
66

77
========== ===================================================================
88
Applies to :ref:`property or method <validation-property-target>`
9-
Options - `exactMessage`_
9+
Options - `divisibleBy`_
10+
- `divisibleByMessage`_
11+
- `exactMessage`_
1012
- `groups`_
1113
- `max`_
1214
- `maxMessage`_
@@ -101,6 +103,44 @@ you might add the following:
101103
Options
102104
-------
103105

106+
divisibleBy
107+
~~~~~~~~~~~
108+
109+
**type**: ``integer`` **default**: null
110+
111+
.. versionadded:: 5.1
112+
113+
The ``divisibleBy`` option was introduced in Symfony 5.1.
114+
115+
Validates that the number of elements of the given collection is divisible by
116+
a certain number.
117+
118+
.. seealso::
119+
120+
If you need to validate that other types of data different from collections
121+
are divisible by a certain number, use the
122+
:doc:`DivisibleBy </reference/constraints/DivisibleBy>` constraint.
123+
124+
divisibleByMessage
125+
~~~~~~~~~~~~~~~~~~
126+
127+
**type**: ``string`` **default**: ``The number of elements in this collection should be a multiple of {{ compared_value }}.``
128+
129+
.. versionadded:: 5.1
130+
131+
The ``divisibleByMessage`` option was introduced in Symfony 5.1.
132+
133+
The message that will be shown if the number of elements of the given collection
134+
is not divisible by the number defined in the ``divisibleBy`` option.
135+
136+
You can use the following parameters in this message:
137+
138+
======================== ===================================================
139+
Parameter Description
140+
======================== ===================================================
141+
``{{ compared_value }}`` The number configured in the ``divisibleBy`` option
142+
======================== ===================================================
143+
104144
exactMessage
105145
~~~~~~~~~~~~
106146

reference/constraints/DivisibleBy.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ DivisibleBy
33

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

6+
.. seealso::
7+
8+
If you need to validate that the number of elements in a collection is
9+
divisible by a certain number, use the :doc:`Count </reference/constraints/Count>`
10+
constraint with the ``divisibleBy`` option.
11+
612
========== ===================================================================
713
Applies to :ref:`property or method <validation-property-target>`
814
Options - `groups`_

0 commit comments

Comments
 (0)