function File::normalizeBinaryFormat
2 calls to File::normalizeBinaryFormat()
- File::__construct in vendor/
symfony/ validator/ Constraints/ File.php - File::__set in vendor/
symfony/ validator/ Constraints/ File.php - Sets the value of a lazily initialized option.
File
-
vendor/
symfony/ validator/ Constraints/ File.php, line 176
Class
- File
- Validates that a value is a valid "file".
Namespace
Symfony\Component\Validator\ConstraintsCode
private function normalizeBinaryFormat(int|string $maxSize) : void {
$factors = [
'k' => 1000,
'ki' => 1 << 10,
'm' => 1000 * 1000,
'mi' => 1 << 20,
'g' => 1000 * 1000 * 1000,
'gi' => 1 << 30,
];
if (ctype_digit((string) $maxSize)) {
$this->maxSize = (int) $maxSize;
$this->binaryFormat ??= false;
}
elseif (preg_match('/^(\\d++)(' . implode('|', array_keys($factors)) . ')$/i', $maxSize, $matches)) {
$this->maxSize = $matches[1] * $factors[$unit = strtolower($matches[2])];
$this->binaryFormat ??= 2 === \strlen($unit);
}
else {
throw new ConstraintDefinitionException(\sprintf('"%s" is not a valid maximum size.', $maxSize));
}
}