Skip to content

Commit 92072d9

Browse files
henry2778javiereguiluz
authored andcommitted
[Validator] Add normalizer option to Unique constraint
1 parent 9c6529b commit 92072d9

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

reference/constraints/Unique.rst

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ Unique
22
======
33

44
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.
78

89
.. seealso::
910

@@ -21,6 +22,7 @@ are considered different elements (a string and an integer, respectively).
2122
Applies to :ref:`property or method <validation-property-target>`
2223
Options - `groups`_
2324
- `message`_
25+
- `normalizer`_
2426
- `payload`_
2527
Class :class:`Symfony\\Component\\Validator\\Constraints\\Unique`
2628
Validator :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

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy