22======
33
44Validates 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.
78
89.. seealso ::
910
@@ -21,6 +22,7 @@ are considered different elements (a string and an integer, respectively).
2122Applies to :ref: `property or method <validation-property-target >`
2223Options - `groups `_
2324 - `message `_
25+ - `normalizer `_
2426 - `payload `_
2527Class :class: `Symfony\\ Component\\ Validator\\ Constraints\\ Unique `
2628Validator :class: `Symfony\\ Component\\ Validator\\ Constraints\\ UniqueValidator `
@@ -123,4 +125,22 @@ Parameter Description
123125``{{ value }} `` The current (invalid) value
124126============================= ================================================
125127
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+
126144.. include :: /reference/constraints/_payload-option.rst.inc
145+
146+ .. _`PHP callable` : https://www.php.net/callable
0 commit comments