[Validator] smaller fixes for binary format
This commit is contained in:
parent
3b4afe78df
commit
967576aaa9
@ -49,19 +49,19 @@ class File extends Constraint
|
||||
if ($this->maxSize) {
|
||||
if (ctype_digit((string) $this->maxSize)) {
|
||||
$this->maxSize = (int) $this->maxSize;
|
||||
$this->binaryFormat = $this->binaryFormat === null ? false : $this->binaryFormat;
|
||||
$this->binaryFormat = null === $this->binaryFormat ? false : $this->binaryFormat;
|
||||
} elseif (preg_match('/^\d++k$/i', $this->maxSize)) {
|
||||
$this->maxSize = $this->maxSize * 1000;
|
||||
$this->binaryFormat = $this->binaryFormat === null ? false : $this->binaryFormat;
|
||||
$this->binaryFormat = null === $this->binaryFormat ? false : $this->binaryFormat;
|
||||
} elseif (preg_match('/^\d++M$/i', $this->maxSize)) {
|
||||
$this->maxSize = $this->maxSize * 1000000;
|
||||
$this->binaryFormat = $this->binaryFormat === null ? false : $this->binaryFormat;
|
||||
} elseif (preg_match('/^\d++ki$/i', $this->maxSize)) {
|
||||
$this->binaryFormat = null === $this->binaryFormat ? false : $this->binaryFormat;
|
||||
} elseif (preg_match('/^\d++Ki$/i', $this->maxSize)) {
|
||||
$this->maxSize = $this->maxSize << 10;
|
||||
$this->binaryFormat = $this->binaryFormat === null ? true : $this->binaryFormat;
|
||||
$this->binaryFormat = null === $this->binaryFormat ? true : $this->binaryFormat;
|
||||
} elseif (preg_match('/^\d++Mi$/i', $this->maxSize)) {
|
||||
$this->maxSize = $this->maxSize << 20;
|
||||
$this->binaryFormat = $this->binaryFormat === null ? true : $this->binaryFormat;
|
||||
$this->binaryFormat = null === $this->binaryFormat ? true : $this->binaryFormat;
|
||||
} else {
|
||||
throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum size', $this->maxSize));
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ class FileValidator extends ConstraintValidator
|
||||
switch ($value->getError()) {
|
||||
case UPLOAD_ERR_INI_SIZE:
|
||||
if ($constraint->maxSize) {
|
||||
$limitInBytes = min(UploadedFile::getMaxFilesize(), (int) $constraint->maxSize);
|
||||
$limitInBytes = min(UploadedFile::getMaxFilesize(), $constraint->maxSize);
|
||||
} else {
|
||||
$limitInBytes = UploadedFile::getMaxFilesize();
|
||||
}
|
||||
@ -118,7 +118,7 @@ class FileValidator extends ConstraintValidator
|
||||
if (0 === $sizeInBytes) {
|
||||
$this->context->addViolation($constraint->disallowEmptyMessage);
|
||||
} elseif ($constraint->maxSize) {
|
||||
$limitInBytes = (int) $constraint->maxSize;
|
||||
$limitInBytes = $constraint->maxSize;
|
||||
|
||||
if ($sizeInBytes > $limitInBytes) {
|
||||
// Convert the limit to the smallest possible number
|
||||
|
Reference in New Issue
Block a user