Skip to content
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

[Validator] Support "maxSize" given in KiB #10962

Closed
webmozart opened this issue May 22, 2014 · 3 comments
Closed

[Validator] Support "maxSize" given in KiB #10962

webmozart opened this issue May 22, 2014 · 3 comments
Labels
Feature Good first issue Ideal for your first contribution! (some Symfony experience may be required) Validator

Comments

@webmozart
Copy link
Contributor

The File constraint should support the following notations for the "maxSize" option:

new File(array('maxSize' => 1234)); // bytes
new File(array('maxSize' => '2k')); // kilobytes (case insensitive)
new File(array('maxSize' => '2ki')); // kibibytes (case insensitive)
new File(array('maxSize' => '1m')); // megabytes (case insensitive)
new File(array('maxSize' => '1mi')); // mebibytes (case insensitive)

// etc.

The conversion of the passed value to the number of bytes should be done already in the constructor of File, to simplify dealing with the file constraint:

$constraint = new File(array('maxSize' => '1ki'));

assert 1024 === $constraint->maxSize;
@Tobion
Copy link
Contributor

Tobion commented May 22, 2014

The validation message suffix should also depend on the setting.

fabpot added a commit that referenced this issue May 22, 2014
This PR was merged into the 2.5-dev branch.

Discussion
----------

Made use of "kB" vs. "KiB" consistent

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Continuation of #10661.

This PR makes the usage of "kB" and "KiB" consistent across the project. The notations equal the internationally recognized ones:

Short form | Long form | Value in Bytes
--- | --- | ---
B | bytes | 1
kB | kilobytes | 1000
KiB | kibibytes | 1024
MB | megabytes | 1000000
MiB | mebibytes | 1048576
GB | gigabytes | 1000000000
GiB | gibibytes | 1073741824

The reason for differentiating between the two is that several users got confused with the current mix (see #10648, #10917, #10661).

FileValidator, UploadedFile and the ProgressBar helper were changed accordingly.

Follow-up feature request: #10962

Commits
-------

e4c6da5 [Validator] Improved to-string conversion of the file size/size limit
bbe1045 [Validator][Console][HttpFoundation] Use "KiB" everywhere (instead of "kB")
@jderusse
Copy link
Member

jderusse commented Jun 1, 2014

There is a lot of dupplicate code in Symfony about the convertion bytes <-> humanized :

  • Component/Console/Helper/Helper.php
  • Component/Finder/Comparator/NumberComparator.php
  • Component/Form/Extension/Validator/Util/ServerParams.php
  • Component/HttpFoundation/File/UploadedFile.php
  • Component/HttpKernel/DataCollector/MemoryDataCollector.php
  • Component/Validator/Constraints/FileValidator.php

I thinks, we should provide a class responsible for managing those conversions.
In which component should be located this kind of service ?

@fabpot
Copy link
Member

fabpot commented Jun 1, 2014

The duplication was done on purpose. The only way to factor out this code would be to create a new component, but I don't think it is worth it.

fabpot added a commit that referenced this issue Jun 17, 2014
…ussé)

This PR was squashed before being merged into the 2.6-dev branch (closes #11027).

Discussion
----------

[Validator] Support "maxSize" given in KiB

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #10962
| License       | MIT
| Doc PR        | symfony/symfony-docs#3895

To display the constraint validation message with an expected suffix, this PR add a new option in  File constraint.

Commits
-------

48ed754 [Validator] Support "maxSize" given in KiB
@fabpot fabpot closed this as completed Jun 17, 2014
weaverryan added a commit to symfony/symfony-docs that referenced this issue Aug 16, 2014
…sse)

This PR was merged into the master branch.

Discussion
----------

[Validator] Support "maxSize" given in KiB

| Q             | A
| ------------- | ---
| Doc fix?      | no
| New docs?     | symfony/symfony#11027
| Applies to    | 2.6
| Fixed tickets | symfony/symfony#10962

To display the constraint validation message with an expected suffix, this PR add a new option in  File constraint.

Commits
-------

1e8fa48 Replace bullet list by a table
77a0687 Add versionAdded on binary suffix
b414f5c Use comma as thousands separator
7dcd7c3 Move secion "binaryFormat" to the right place
71fdd60 Fix line wrap
3f3f4e0 Provide information about SI and Binary prefixes
deac0c3 Add option binaryFormat in constraint file
e3acdc5 Support MaxSize in KiB and MiB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Good first issue Ideal for your first contribution! (some Symfony experience may be required) Validator
Projects
None yet
Development

No branches or pull requests

5 participants