X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fsymfony%2Fvalidator%2FConstraints%2FFile.php;fp=vendor%2Fsymfony%2Fvalidator%2FConstraints%2FFile.php;h=5cc3a7313f7a5c3d94ac76d0303357388d6e391e;hp=341fbaf4407757920e9af04f33e32c3845d19fae;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/symfony/validator/Constraints/File.php b/vendor/symfony/validator/Constraints/File.php index 341fbaf44..5cc3a7313 100644 --- a/vendor/symfony/validator/Constraints/File.php +++ b/vendor/symfony/validator/Constraints/File.php @@ -18,6 +18,8 @@ use Symfony\Component\Validator\Exception\ConstraintDefinitionException; * @Annotation * @Target({"PROPERTY", "METHOD", "ANNOTATION"}) * + * @property int $maxSize + * * @author Bernhard Schussek */ class File extends Constraint @@ -86,25 +88,29 @@ class File extends Constraint return parent::__get($option); } - private function normalizeBinaryFormat($maxSize) + public function __isset($option) { - $sizeInt = (int) $maxSize; + if ('maxSize' === $option) { + return true; + } + + return parent::__isset($option); + } + private function normalizeBinaryFormat($maxSize) + { + $factors = array( + 'k' => 1000, + 'ki' => 1 << 10, + 'm' => 1000000, + 'mi' => 1 << 20, + ); if (ctype_digit((string) $maxSize)) { - $this->maxSize = $sizeInt; - $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->maxSize = (int) $maxSize; $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)); }