Skip to content

[Validator] Added option for specifying the size format for the File validator #10917

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

Closed
wants to merge 1 commit into from
Closed

[Validator] Added option for specifying the size format for the File validator #10917

wants to merge 1 commit into from

Conversation

csarrazi
Copy link
Contributor

Q A
Bug fix? yes
New feature? yes
BC breaks? yes and no, as the current calculation is not consistent
Deprecations? no
Tests pass? yes
Fixed tickets #10648
License MIT
Doc PR -

This lets someone choose between binary (multiples of 1024) and decimal (multiple of 1000) formats for specifying the size.

Example:

use Symfony\Component\Validator\Constraints as Assert;

class Curriculum
{
    /**
     * @Assert\File(size=2000, sizeFormat="decimal")
    */
    public $file;
}

By default, the size format is in binary.

@csarrazi
Copy link
Contributor Author

Oh! And I'll make a doc PR asap

@fabpot
Copy link
Member

fabpot commented May 16, 2014

Not sure I like to add yet another option for this. Why not choose one format (whatever it is) and document that we only support this one. That would be much better I think in the long run.

@csarrazi
Copy link
Contributor Author

Actually, there is a default format, which you may override. Both are alright I think. In any case, we don't want to change this at a later date.

@@ -25,6 +25,7 @@ class File extends Constraint
{
public $maxSize = null;
public $mimeTypes = array();
public $sizeFormat = 'binary';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the constant FileValidator::SIZE_FORMAT_BINARY

@jderusse
Copy link
Member

Should binary be the default value ?
I think that the "bad usage" (1kB = 1024B) should be the exception. Just my 0.02$ opinion BTW

This lets someone choose between binary (multiples of 1024) and decimal (multiple of 1000) formats for specifying the size
@csarrazi
Copy link
Contributor Author

Took @jeremy-derusse's feedback into account.

@webmozart
Copy link
Contributor

Replaced by #10951 and #10962.

@webmozart webmozart closed this May 22, 2014
fabpot added a commit that referenced this pull request 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")
@csarrazi csarrazi deleted the add-size-format-to-file-validator branch January 27, 2016 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants