Skip to content

Commit 7b77976

Browse files
committed
feature #20906 [Validator] Add filenameCharset and filenameCountUnit options to File constraint (alamirault)
This PR was merged into the 7.3 branch. Discussion ---------- [Validator] Add `filenameCharset` and `filenameCountUnit` options to `File` constraint Fix #20703 (Inspired by `Length` options descriptions) Commits ------- e7613b0 [Validator] Add filenameCharset and filenameCountUnit options to File constraint
2 parents 50c531c + e7613b0 commit 7b77976

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

Diff for: reference/constraints/File.rst

+54
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,31 @@ You can find a list of existing mime types on the `IANA website`_.
274274
If set, the validator will check that the filename of the underlying file
275275
doesn't exceed a certain length.
276276

277+
``filenameCountUnit``
278+
~~~~~~~~~~~~~~~~~~~~~
279+
280+
**type**: ``string`` **default**: ``File::FILENAME_COUNT_BYTES``
281+
282+
The character count unit to use for the filename max length check.
283+
By default :phpfunction:`strlen` is used, which counts the length of the string in bytes.
284+
285+
Can be one of the following constants of the
286+
:class:`Symfony\\Component\\Validator\\Constraints\\File` class:
287+
288+
* ``FILENAME_COUNT_BYTES``: Uses :phpfunction:`strlen` counting the length of the
289+
string in bytes.
290+
* ``FILENAME_COUNT_CODEPOINTS``: Uses :phpfunction:`mb_strlen` counting the length
291+
of the string in Unicode code points. Simple (multibyte) Unicode characters count
292+
as 1 character, while for example ZWJ sequences of composed emojis count as
293+
multiple characters.
294+
* ``FILENAME_COUNT_GRAPHEMES``: Uses :phpfunction:`grapheme_strlen` counting the
295+
length of the string in graphemes, i.e. even emojis and ZWJ sequences of composed
296+
emojis count as 1 character.
297+
298+
.. versionadded:: 7.3
299+
300+
The ``filenameCountUnit`` option was introduced in Symfony 7.3.
301+
277302
``filenameTooLongMessage``
278303
~~~~~~~~~~~~~~~~~~~~~~~~~~
279304

@@ -290,6 +315,35 @@ Parameter Description
290315
``{{ filename_max_length }}`` Maximum number of characters allowed
291316
============================== ==============================================================
292317

318+
``filenameCharset``
319+
~~~~~~~~~~~~~~~~~~~
320+
321+
**type**: ``string`` **default**: ``null``
322+
323+
The charset to be used when computing value's filename max length with the
324+
:phpfunction:`mb_check_encoding` and :phpfunction:`mb_strlen`
325+
PHP functions.
326+
327+
``filenameCharsetMessage``
328+
~~~~~~~~~~~~~~~~~~~~~~~~~~
329+
330+
**type**: ``string`` **default**: ``This filename does not match the expected charset.``
331+
332+
The message that will be shown if the value is not using the given `filenameCharsetMessage`_.
333+
334+
You can use the following parameters in this message:
335+
336+
================= ============================================================
337+
Parameter Description
338+
================= ============================================================
339+
``{{ charset }}`` The expected charset
340+
``{{ name }}`` The current (invalid) value
341+
================= ============================================================
342+
343+
.. versionadded:: 7.3
344+
345+
The ``filenameCharset`` and ``filenameCharsetMessage`` options were introduced in Symfony 7.3.
346+
293347
``extensionsMessage``
294348
~~~~~~~~~~~~~~~~~~~~~
295349

0 commit comments

Comments
 (0)