From ce4b915961ed90eb85b03a171c92588467d788b3 Mon Sep 17 00:00:00 2001 From: spackmat Date: Tue, 21 Feb 2023 15:56:38 +0100 Subject: [PATCH 1/2] [Validator] Implement countUnit option for Length constraint Resolves https://github.com/symfony/symfony-docs/issues/17945 --- reference/constraints/Length.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/reference/constraints/Length.rst b/reference/constraints/Length.rst index 89e8b02547d..b00ba485ee0 100644 --- a/reference/constraints/Length.rst +++ b/reference/constraints/Length.rst @@ -123,6 +123,29 @@ Parameter Description ``{{ value }}`` The current (invalid) value ================= ============================================================ +``countUnit`` +~~~~~~~~~~~~~~~~~~ + +**type**: ``string`` **default**: ``Length::COUNT_CODEPOINTS`` + +The character count unit to use for the length check. By default :phpfunction:`mb_strlen` +is used, which counts Unicode code points. + +Can be one of the following constants of the +:class:`Symfony\\Component\\Validator\\Constraints\\Length` class: + +* ``COUNT_BYTES``: Uses :phpfunction:`strlen` counting the length of the string in bytes. +* ``COUNT_CODEPOINTS``: Uses :phpfunction:`mb_strlen` counting the length of the string in Unicode + code points. This was the sole behavior until Symfony 6.2 and is the default since Symfony 6.3. + Simple (multibyte) Unicode characters count as 1 character, while for example ZWJ sequences of + composed emojis count as multiple characters. +* ``COUNT_GRAPHEMES``: Uses :phpfunction:`grapheme_strlen` counting the length of the string in + graphemes, i.e. even emojis and ZWJ sequences of composed emojis count as 1 character. + +.. versionadded:: 6.3 + + The ``countUnit`` option was introduced in Symfony 6.3. + ``exactly`` ~~~~~~~~~~~ From 6e2e2f79ce2b89a2f139df0ee06feb435d75bc39 Mon Sep 17 00:00:00 2001 From: Gregor Nathanael Meyer Date: Tue, 21 Feb 2023 16:23:44 +0100 Subject: [PATCH 2/2] Update reference/constraints/Length.rst Co-authored-by: Oskar Stark --- reference/constraints/Length.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/constraints/Length.rst b/reference/constraints/Length.rst index b00ba485ee0..7ed54ea3289 100644 --- a/reference/constraints/Length.rst +++ b/reference/constraints/Length.rst @@ -124,7 +124,7 @@ Parameter Description ================= ============================================================ ``countUnit`` -~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~ **type**: ``string`` **default**: ``Length::COUNT_CODEPOINTS``