Mercurial > hg > isophonics-drupal-site
diff vendor/symfony/validator/Constraints/File.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 4c8ae668cc8c |
children | 129ea1e6d783 |
line wrap: on
line diff
--- a/vendor/symfony/validator/Constraints/File.php Mon Apr 23 09:33:26 2018 +0100 +++ b/vendor/symfony/validator/Constraints/File.php Mon Apr 23 09:46:53 2018 +0100 @@ -18,6 +18,8 @@ * @Annotation * @Target({"PROPERTY", "METHOD", "ANNOTATION"}) * + * @property int $maxSize + * * @author Bernhard Schussek <bschussek@gmail.com> */ class File extends Constraint @@ -86,25 +88,29 @@ return parent::__get($option); } + public function __isset($option) + { + if ('maxSize' === $option) { + return true; + } + + return parent::__isset($option); + } + private function normalizeBinaryFormat($maxSize) { - $sizeInt = (int) $maxSize; - + $factors = array( + 'k' => 1000, + 'ki' => 1 << 10, + 'm' => 1000000, + 'mi' => 1 << 20, + ); if (ctype_digit((string) $maxSize)) { - $this->maxSize = $sizeInt; + $this->maxSize = (int) $maxSize; $this->binaryFormat = null === $this->binaryFormat ? false : $this->binaryFormat; - } elseif (preg_match('/^\d++k$/i', $maxSize)) { - $this->maxSize = $sizeInt * 1000; - $this->binaryFormat = null === $this->binaryFormat ? false : $this->binaryFormat; - } elseif (preg_match('/^\d++M$/i', $maxSize)) { - $this->maxSize = $sizeInt * 1000000; - $this->binaryFormat = null === $this->binaryFormat ? false : $this->binaryFormat; - } elseif (preg_match('/^\d++Ki$/i', $maxSize)) { - $this->maxSize = $sizeInt << 10; - $this->binaryFormat = null === $this->binaryFormat ? true : $this->binaryFormat; - } elseif (preg_match('/^\d++Mi$/i', $maxSize)) { - $this->maxSize = $sizeInt << 20; - $this->binaryFormat = null === $this->binaryFormat ? true : $this->binaryFormat; + } elseif (preg_match('/^(\d++)('.implode('|', array_keys($factors)).')$/i', $maxSize, $matches)) { + $this->maxSize = $matches[1] * $factors[$unit = strtolower($matches[2])]; + $this->binaryFormat = null === $this->binaryFormat ? 2 === strlen($unit) : $this->binaryFormat; } else { throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum size', $this->maxSize)); }