Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. File.php

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\Constraints

Code

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));
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal