comparison vendor/symfony/validator/Constraints/File.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
30 const NOT_READABLE_ERROR = 'c20c92a4-5bfa-4202-9477-28e800e0f6ff'; 30 const NOT_READABLE_ERROR = 'c20c92a4-5bfa-4202-9477-28e800e0f6ff';
31 const EMPTY_ERROR = '5d743385-9775-4aa5-8ff5-495fb1e60137'; 31 const EMPTY_ERROR = '5d743385-9775-4aa5-8ff5-495fb1e60137';
32 const TOO_LARGE_ERROR = 'df8637af-d466-48c6-a59d-e7126250a654'; 32 const TOO_LARGE_ERROR = 'df8637af-d466-48c6-a59d-e7126250a654';
33 const INVALID_MIME_TYPE_ERROR = '744f00bc-4389-4c74-92de-9a43cde55534'; 33 const INVALID_MIME_TYPE_ERROR = '744f00bc-4389-4c74-92de-9a43cde55534';
34 34
35 protected static $errorNames = array( 35 protected static $errorNames = [
36 self::NOT_FOUND_ERROR => 'NOT_FOUND_ERROR', 36 self::NOT_FOUND_ERROR => 'NOT_FOUND_ERROR',
37 self::NOT_READABLE_ERROR => 'NOT_READABLE_ERROR', 37 self::NOT_READABLE_ERROR => 'NOT_READABLE_ERROR',
38 self::EMPTY_ERROR => 'EMPTY_ERROR', 38 self::EMPTY_ERROR => 'EMPTY_ERROR',
39 self::TOO_LARGE_ERROR => 'TOO_LARGE_ERROR', 39 self::TOO_LARGE_ERROR => 'TOO_LARGE_ERROR',
40 self::INVALID_MIME_TYPE_ERROR => 'INVALID_MIME_TYPE_ERROR', 40 self::INVALID_MIME_TYPE_ERROR => 'INVALID_MIME_TYPE_ERROR',
41 ); 41 ];
42 42
43 public $binaryFormat; 43 public $binaryFormat;
44 public $mimeTypes = array(); 44 public $mimeTypes = [];
45 public $notFoundMessage = 'The file could not be found.'; 45 public $notFoundMessage = 'The file could not be found.';
46 public $notReadableMessage = 'The file is not readable.'; 46 public $notReadableMessage = 'The file is not readable.';
47 public $maxSizeMessage = 'The file is too large ({{ size }} {{ suffix }}). Allowed maximum size is {{ limit }} {{ suffix }}.'; 47 public $maxSizeMessage = 'The file is too large ({{ size }} {{ suffix }}). Allowed maximum size is {{ limit }} {{ suffix }}.';
48 public $mimeTypesMessage = 'The mime type of the file is invalid ({{ type }}). Allowed mime types are {{ types }}.'; 48 public $mimeTypesMessage = 'The mime type of the file is invalid ({{ type }}). Allowed mime types are {{ types }}.';
49 public $disallowEmptyMessage = 'An empty file is not allowed.'; 49 public $disallowEmptyMessage = 'An empty file is not allowed.';
97 return parent::__isset($option); 97 return parent::__isset($option);
98 } 98 }
99 99
100 private function normalizeBinaryFormat($maxSize) 100 private function normalizeBinaryFormat($maxSize)
101 { 101 {
102 $factors = array( 102 $factors = [
103 'k' => 1000, 103 'k' => 1000,
104 'ki' => 1 << 10, 104 'ki' => 1 << 10,
105 'm' => 1000000, 105 'm' => 1000000,
106 'mi' => 1 << 20, 106 'mi' => 1 << 20,
107 ); 107 ];
108 if (ctype_digit((string) $maxSize)) { 108 if (ctype_digit((string) $maxSize)) {
109 $this->maxSize = (int) $maxSize; 109 $this->maxSize = (int) $maxSize;
110 $this->binaryFormat = null === $this->binaryFormat ? false : $this->binaryFormat; 110 $this->binaryFormat = null === $this->binaryFormat ? false : $this->binaryFormat;
111 } elseif (preg_match('/^(\d++)('.implode('|', array_keys($factors)).')$/i', $maxSize, $matches)) { 111 } elseif (preg_match('/^(\d++)('.implode('|', array_keys($factors)).')$/i', $maxSize, $matches)) {
112 $this->maxSize = $matches[1] * $factors[$unit = strtolower($matches[2])]; 112 $this->maxSize = $matches[1] * $factors[$unit = strtolower($matches[2])];
113 $this->binaryFormat = null === $this->binaryFormat ? 2 === strlen($unit) : $this->binaryFormat; 113 $this->binaryFormat = null === $this->binaryFormat ? 2 === \strlen($unit) : $this->binaryFormat;
114 } else { 114 } else {
115 throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum size', $this->maxSize)); 115 throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum size', $this->maxSize));
116 } 116 }
117 } 117 }
118 } 118 }