2
2
======
3
3
4
4
Validates that all the elements of the given collection are unique (none of them
5
- is present more than once). Elements are compared strictly, so ``'7' `` and ``7 ``
6
- are considered different elements (a string and an integer, respectively).
5
+ is present more than once). By default elements are compared strictly,
6
+ so ``'7' `` and ``7 `` are considered different elements (a string and an integer, respectively).
7
+ If you want any other comparison logic to be applied, use the `normalizer `_ option.
7
8
8
9
.. seealso ::
9
10
@@ -21,6 +22,7 @@ are considered different elements (a string and an integer, respectively).
21
22
Applies to :ref: `property or method <validation-property-target >`
22
23
Options - `groups `_
23
24
- `message `_
25
+ - `normalizer `_
24
26
- `payload `_
25
27
Class :class: `Symfony\\ Component\\ Validator\\ Constraints\\ Unique `
26
28
Validator :class: `Symfony\\ Component\\ Validator\\ Constraints\\ UniqueValidator `
@@ -123,4 +125,22 @@ Parameter Description
123
125
``{{ value }} `` The current (invalid) value
124
126
============================= ================================================
125
127
128
+ ``normalizer ``
129
+ ~~~~~~~~~~~~~~
130
+
131
+ **type **: a `PHP callable `_ **default **: ``null ``
132
+
133
+ .. versionadded :: 5.3
134
+
135
+ The ``normalizer `` option was introduced in Symfony 5.3.
136
+
137
+ This option allows to define the PHP callable applied to each element of the given collection before
138
+ checking if the collection is valid.
139
+
140
+ For example, you may want to pass the ``'trim' `` string to apply the
141
+ :phpfunction: `trim ` PHP function to each element of the collection in order to ignore leading and trailing
142
+ whitespace during validation.
143
+
126
144
.. include :: /reference/constraints/_payload-option.rst.inc
145
+
146
+ .. _`PHP callable` : https://www.php.net/callable
0 commit comments