Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit92072d9

Browse files
henry2778javiereguiluz
authored andcommitted
[Validator] Add normalizer option to Unique constraint
1 parent9c6529b commit92072d9

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)

[8]ページ先頭

©2009-2025 Movatter.jp