Skip to content

Commit 7d0f449

Browse files
committed
feature #17948 [Validator] Implement countUnit option for Length constraint (spackmat)
This PR was squashed before being merged into the 6.3 branch. Discussion ---------- [Validator] Implement countUnit option for Length constraint Resolves #17945 Commits ------- 6e2e2f7 Update reference/constraints/Length.rst ce4b915 [Validator] Implement countUnit option for Length constraint
2 parents ba8b4c4 + 6e2e2f7 commit 7d0f449

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

reference/constraints/Length.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,29 @@ Parameter Description
123123
``{{ value }}`` The current (invalid) value
124124
================= ============================================================
125125

126+
``countUnit``
127+
~~~~~~~~~~~~~
128+
129+
**type**: ``string`` **default**: ``Length::COUNT_CODEPOINTS``
130+
131+
The character count unit to use for the length check. By default :phpfunction:`mb_strlen`
132+
is used, which counts Unicode code points.
133+
134+
Can be one of the following constants of the
135+
:class:`Symfony\\Component\\Validator\\Constraints\\Length` class:
136+
137+
* ``COUNT_BYTES``: Uses :phpfunction:`strlen` counting the length of the string in bytes.
138+
* ``COUNT_CODEPOINTS``: Uses :phpfunction:`mb_strlen` counting the length of the string in Unicode
139+
code points. This was the sole behavior until Symfony 6.2 and is the default since Symfony 6.3.
140+
Simple (multibyte) Unicode characters count as 1 character, while for example ZWJ sequences of
141+
composed emojis count as multiple characters.
142+
* ``COUNT_GRAPHEMES``: Uses :phpfunction:`grapheme_strlen` counting the length of the string in
143+
graphemes, i.e. even emojis and ZWJ sequences of composed emojis count as 1 character.
144+
145+
.. versionadded:: 6.3
146+
147+
The ``countUnit`` option was introduced in Symfony 6.3.
148+
126149
``exactly``
127150
~~~~~~~~~~~
128151

0 commit comments

Comments
 (0)