Mercurial > hg > cmmr2012-drupal-site
comparison vendor/symfony/validator/Constraints/FileValidator.php @ 4:a9cd425dd02b
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:11:55 +0000 |
parents | c75dbcec494b |
children |
comparison
equal
deleted
inserted
replaced
3:307d7a7fd348 | 4:a9cd425dd02b |
---|---|
25 const KB_BYTES = 1000; | 25 const KB_BYTES = 1000; |
26 const MB_BYTES = 1000000; | 26 const MB_BYTES = 1000000; |
27 const KIB_BYTES = 1024; | 27 const KIB_BYTES = 1024; |
28 const MIB_BYTES = 1048576; | 28 const MIB_BYTES = 1048576; |
29 | 29 |
30 private static $suffices = array( | 30 private static $suffices = [ |
31 1 => 'bytes', | 31 1 => 'bytes', |
32 self::KB_BYTES => 'kB', | 32 self::KB_BYTES => 'kB', |
33 self::MB_BYTES => 'MB', | 33 self::MB_BYTES => 'MB', |
34 self::KIB_BYTES => 'KiB', | 34 self::KIB_BYTES => 'KiB', |
35 self::MIB_BYTES => 'MiB', | 35 self::MIB_BYTES => 'MiB', |
36 ); | 36 ]; |
37 | 37 |
38 /** | 38 /** |
39 * {@inheritdoc} | 39 * {@inheritdoc} |
40 */ | 40 */ |
41 public function validate($value, Constraint $constraint) | 41 public function validate($value, Constraint $constraint) |
55 if ($constraint->maxSize && $constraint->maxSize < $iniLimitSize) { | 55 if ($constraint->maxSize && $constraint->maxSize < $iniLimitSize) { |
56 $limitInBytes = $constraint->maxSize; | 56 $limitInBytes = $constraint->maxSize; |
57 $binaryFormat = $constraint->binaryFormat; | 57 $binaryFormat = $constraint->binaryFormat; |
58 } else { | 58 } else { |
59 $limitInBytes = $iniLimitSize; | 59 $limitInBytes = $iniLimitSize; |
60 $binaryFormat = true; | 60 $binaryFormat = null === $constraint->binaryFormat ? true : $constraint->binaryFormat; |
61 } | 61 } |
62 | 62 |
63 list($sizeAsString, $limitAsString, $suffix) = $this->factorizeSizes(0, $limitInBytes, $binaryFormat); | 63 list($sizeAsString, $limitAsString, $suffix) = $this->factorizeSizes(0, $limitInBytes, $binaryFormat); |
64 $this->context->buildViolation($constraint->uploadIniSizeErrorMessage) | 64 $this->context->buildViolation($constraint->uploadIniSizeErrorMessage) |
65 ->setParameter('{{ limit }}', $limitAsString) | 65 ->setParameter('{{ limit }}', $limitAsString) |
111 | 111 |
112 return; | 112 return; |
113 } | 113 } |
114 } | 114 } |
115 | 115 |
116 if (!is_scalar($value) && !$value instanceof FileObject && !(is_object($value) && method_exists($value, '__toString'))) { | 116 if (!is_scalar($value) && !$value instanceof FileObject && !(\is_object($value) && method_exists($value, '__toString'))) { |
117 throw new UnexpectedTypeException($value, 'string'); | 117 throw new UnexpectedTypeException($value, 'string'); |
118 } | 118 } |
119 | 119 |
120 $path = $value instanceof FileObject ? $value->getPathname() : (string) $value; | 120 $path = $value instanceof FileObject ? $value->getPathname() : (string) $value; |
121 | 121 |
194 } | 194 } |
195 } | 195 } |
196 | 196 |
197 private static function moreDecimalsThan($double, $numberOfDecimals) | 197 private static function moreDecimalsThan($double, $numberOfDecimals) |
198 { | 198 { |
199 return strlen((string) $double) > strlen(round($double, $numberOfDecimals)); | 199 return \strlen((string) $double) > \strlen(round($double, $numberOfDecimals)); |
200 } | 200 } |
201 | 201 |
202 /** | 202 /** |
203 * Convert the limit to the smallest possible number | 203 * Convert the limit to the smallest possible number |
204 * (i.e. try "MB", then "kB", then "bytes"). | 204 * (i.e. try "MB", then "kB", then "bytes"). |
231 $coef /= $coefFactor; | 231 $coef /= $coefFactor; |
232 $limitAsString = (string) ($limit / $coef); | 232 $limitAsString = (string) ($limit / $coef); |
233 $sizeAsString = (string) round($size / $coef, 2); | 233 $sizeAsString = (string) round($size / $coef, 2); |
234 } | 234 } |
235 | 235 |
236 return array($sizeAsString, $limitAsString, self::$suffices[$coef]); | 236 return [$sizeAsString, $limitAsString, self::$suffices[$coef]]; |
237 } | 237 } |
238 } | 238 } |