'NOT_FOUND_ERROR', self::NOT_READABLE_ERROR => 'NOT_READABLE_ERROR', self::EMPTY_ERROR => 'EMPTY_ERROR', self::TOO_LARGE_ERROR => 'TOO_LARGE_ERROR', self::INVALID_MIME_TYPE_ERROR => 'INVALID_MIME_TYPE_ERROR']; public $binaryFormat; public $mimeTypes = []; public $notFoundMessage = 'The file could not be found.'; public $notReadableMessage = 'The file is not readable.'; public $maxSizeMessage = 'The file is too large ({{ size }} {{ suffix }}). Allowed maximum size is {{ limit }} {{ suffix }}.'; public $mimeTypesMessage = 'The mime type of the file is invalid ({{ type }}). Allowed mime types are {{ types }}.'; public $disallowEmptyMessage = 'An empty file is not allowed.'; public $uploadIniSizeErrorMessage = 'The file is too large. Allowed maximum size is {{ limit }} {{ suffix }}.'; public $uploadFormSizeErrorMessage = 'The file is too large.'; public $uploadPartialErrorMessage = 'The file was only partially uploaded.'; public $uploadNoFileErrorMessage = 'No file was uploaded.'; public $uploadNoTmpDirErrorMessage = 'No temporary folder was configured in php.ini.'; public $uploadCantWriteErrorMessage = 'Cannot write temporary file to disk.'; public $uploadExtensionErrorMessage = 'A PHP extension caused the upload to fail.'; public $uploadErrorMessage = 'The file could not be uploaded.'; protected $maxSize; public function __construct(?array $options = null, $maxSize = null, ?bool $binaryFormat = null, $mimeTypes = null, ?string $notFoundMessage = null, ?string $notReadableMessage = null, ?string $maxSizeMessage = null, ?string $mimeTypesMessage = null, ?string $disallowEmptyMessage = null, ?string $uploadIniSizeErrorMessage = null, ?string $uploadFormSizeErrorMessage = null, ?string $uploadPartialErrorMessage = null, ?string $uploadNoFileErrorMessage = null, ?string $uploadNoTmpDirErrorMessage = null, ?string $uploadCantWriteErrorMessage = null, ?string $uploadExtensionErrorMessage = null, ?string $uploadErrorMessage = null, ?array $groups = null, $payload = null) { if (null !== $maxSize && !\is_int($maxSize) && !\is_string($maxSize)) { throw new \TypeError(\sprintf('"%s": Expected argument $maxSize to be either null, an integer or a string, got "%s".', __METHOD__, \get_debug_type($maxSize))); } if (null !== $mimeTypes && !\is_array($mimeTypes) && !\is_string($mimeTypes)) { throw new \TypeError(\sprintf('"%s": Expected argument $mimeTypes to be either null, an array or a string, got "%s".', __METHOD__, \get_debug_type($mimeTypes))); } parent::__construct($options, $groups, $payload); $this->maxSize = $maxSize ?? $this->maxSize; $this->binaryFormat = $binaryFormat ?? $this->binaryFormat; $this->mimeTypes = $mimeTypes ?? $this->mimeTypes; $this->notFoundMessage = $notFoundMessage ?? $this->notFoundMessage; $this->notReadableMessage = $notReadableMessage ?? $this->notReadableMessage; $this->maxSizeMessage = $maxSizeMessage ?? $this->maxSizeMessage; $this->mimeTypesMessage = $mimeTypesMessage ?? $this->mimeTypesMessage; $this->disallowEmptyMessage = $disallowEmptyMessage ?? $this->disallowEmptyMessage; $this->uploadIniSizeErrorMessage = $uploadIniSizeErrorMessage ?? $this->uploadIniSizeErrorMessage; $this->uploadFormSizeErrorMessage = $uploadFormSizeErrorMessage ?? $this->uploadFormSizeErrorMessage; $this->uploadPartialErrorMessage = $uploadPartialErrorMessage ?? $this->uploadPartialErrorMessage; $this->uploadNoFileErrorMessage = $uploadNoFileErrorMessage ?? $this->uploadNoFileErrorMessage; $this->uploadNoTmpDirErrorMessage = $uploadNoTmpDirErrorMessage ?? $this->uploadNoTmpDirErrorMessage; $this->uploadCantWriteErrorMessage = $uploadCantWriteErrorMessage ?? $this->uploadCantWriteErrorMessage; $this->uploadExtensionErrorMessage = $uploadExtensionErrorMessage ?? $this->uploadExtensionErrorMessage; $this->uploadErrorMessage = $uploadErrorMessage ?? $this->uploadErrorMessage; if (null !== $this->maxSize) { $this->normalizeBinaryFormat($this->maxSize); } } public function __set(string $option, $value) { if ('maxSize' === $option) { $this->normalizeBinaryFormat($value); return; } parent::__set($option, $value); } public function __get(string $option) { if ('maxSize' === $option) { return $this->maxSize; } return parent::__get($option); } public function __isset(string $option) { if ('maxSize' === $option) { return \true; } return parent::__isset($option); } private function normalizeBinaryFormat($maxSize) { $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 = $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 = $this->binaryFormat ?? 2 === \strlen($unit); } else { throw new ConstraintDefinitionException(\sprintf('"%s" is not a valid maximum size.', $maxSize)); } } }