-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Validator] Support "maxSize" given in KiB #3895
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e3acdc5
Support MaxSize in KiB and MiB
deac0c3
Add option binaryFormat in constraint file
jderusse 3f3f4e0
Provide information about SI and Binary prefixes
jderusse 71fdd60
Fix line wrap
jderusse 7dcd7c3
Move secion "binaryFormat" to the right place
jderusse b414f5c
Use comma as thousands separator
77a0687
Add versionAdded on binary suffix
1e8fa48
Replace bullet list by a table
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -20,6 +20,7 @@ form type. | |||||||||||||
| Applies to | :ref:`property or method <validation-property-target>` | | ||||||||||||||
+----------------+---------------------------------------------------------------------+ | ||||||||||||||
| Options | - `maxSize`_ | | ||||||||||||||
| | - `binaryFormat`_ | | ||||||||||||||
| | - `mimeTypes`_ | | ||||||||||||||
| | - `maxSizeMessage`_ | | ||||||||||||||
| | - `mimeTypesMessage`_ | | ||||||||||||||
|
@@ -78,7 +79,6 @@ below a certain file size and a valid PDF, add the following: | |||||||||||||
maxSize: 1024k | ||||||||||||||
mimeTypes: [application/pdf, application/x-pdf] | ||||||||||||||
mimeTypesMessage: Please upload a valid PDF | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
.. code-block:: php-annotations | ||||||||||||||
|
||||||||||||||
|
@@ -154,19 +154,46 @@ Options | |||||||||||||
maxSize | ||||||||||||||
~~~~~~~ | ||||||||||||||
|
||||||||||||||
.. versionadded:: 2.6 | ||||||||||||||
The suffixes ``Ki`` and ``Mi`` were introduced in Symfony 2.6. | ||||||||||||||
|
||||||||||||||
**type**: ``mixed`` | ||||||||||||||
|
||||||||||||||
If set, the size of the underlying file must be below this file size in order | ||||||||||||||
to be valid. The size of the file can be given in one of the following formats: | ||||||||||||||
|
||||||||||||||
* **bytes**: To specify the ``maxSize`` in bytes, pass a value that is entirely | ||||||||||||||
numeric (e.g. ``4096``); | ||||||||||||||
+--------+-----------+-----------------+------+ | ||||||||||||||
| Suffix | Unit Name | value | e.g. | | ||||||||||||||
+========+===========+=================+======+ | ||||||||||||||
| | byte | 1 byte | 4096 | | ||||||||||||||
+--------+-----------+-----------------+------+ | ||||||||||||||
| k | kilobyte | 1,000 bytes | 200k | | ||||||||||||||
+--------+-----------+-----------------+------+ | ||||||||||||||
| M | megabyte | 1,000,000 bytes | 2M | | ||||||||||||||
+--------+-----------+-----------------+------+ | ||||||||||||||
| Ki | kibibyte | 1,024 bytes | 32Ki | | ||||||||||||||
+--------+-----------+-----------------+------+ | ||||||||||||||
| Mi | mebibyte | 1,048,576 bytes | 8Mi | | ||||||||||||||
+--------+-----------+-----------------+------+ | ||||||||||||||
|
||||||||||||||
For more information about the difference between binary and SI suffixes, | ||||||||||||||
see `Wikipedia: Binary prefix`_. | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are the What do you all think about replacing the bullet points with a table of examples? Something like:
etc |
||||||||||||||
|
||||||||||||||
binaryFormat | ||||||||||||||
~~~~~~~~~~~~ | ||||||||||||||
|
||||||||||||||
.. versionadded:: 2.6 | ||||||||||||||
The ``binaryFormat`` option was introduced in Symfony 2.6. | ||||||||||||||
|
||||||||||||||
**type**: ``boolean`` **default**: ``null`` | ||||||||||||||
|
||||||||||||||
* **kilobytes**: To specify the ``maxSize`` in kilobytes, pass a number and | ||||||||||||||
suffix it with a lowercase "k" (e.g. ``200k``); | ||||||||||||||
When ``true``, the sizes will be displayed in messages with binary suffixes | ||||||||||||||
(KiB, MiB). When ``false``, the sizes will be displayed with SI suffixes (kB, | ||||||||||||||
MB). When ``null``, then the binaryFormat will be guessed from the suffix | ||||||||||||||
defined in the ``maxSize`` option. | ||||||||||||||
|
||||||||||||||
* **megabytes**: To specify the ``maxSize`` in megabytes, pass a number and | ||||||||||||||
suffix it with a capital "M" (e.g. ``4M``). | ||||||||||||||
For more information about the difference between binary and SI suffixes, | ||||||||||||||
see `Wikipedia: Binary prefix`_. | ||||||||||||||
|
||||||||||||||
mimeTypes | ||||||||||||||
~~~~~~~~~ | ||||||||||||||
|
@@ -238,3 +265,4 @@ to disk. | |||||||||||||
|
||||||||||||||
|
||||||||||||||
.. _`IANA website`: http://www.iana.org/assignments/media-types/index.html | ||||||||||||||
.. _`Wikipedia: Binary prefix`: http://en.wikipedia.org/wiki/Binary_prefix |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why you are speaking about "suffix". It's a prefix for the unit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depend on the context:
BTW: at line https://github.com/symfony/symfony-docs/pull/3895/files#diff-aa9fd68c6e685f7e2773332c00fbcb68R179 it should be "binary and SI prefixes". But I choose to use the word suffixes to avoid user confusion...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also like suffix, since the user will use this as the suffix for their value. But the distinction actually hadn't occurred to me :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jeremy-derusse I opened a pull request addressing this (see #4136). If you like to, I'll be happy to see your comments there.