Mercurial > hg > isophonics-drupal-site
comparison vendor/zendframework/zend-diactoros/src/UploadedFile.php @ 12:7a779792577d
Update Drupal core to v8.4.5 (via Composer)
author | Chris Cannam |
---|---|
date | Fri, 23 Feb 2018 15:52:07 +0000 |
parents | 4c8ae668cc8c |
children | c2387f117808 |
comparison
equal
deleted
inserted
replaced
11:bfffd8d7479a | 12:7a779792577d |
---|---|
1 <?php | 1 <?php |
2 /** | 2 /** |
3 * Zend Framework (http://framework.zend.com/) | 3 * @see https://github.com/zendframework/zend-diactoros for the canonical source repository |
4 * | 4 * @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com) |
5 * @see http://github.com/zendframework/zend-diactoros for the canonical source repository | |
6 * @copyright Copyright (c) 2015-2016 Zend Technologies USA Inc. (http://www.zend.com) | |
7 * @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License | 5 * @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License |
8 */ | 6 */ |
9 | 7 |
10 namespace Zend\Diactoros; | 8 namespace Zend\Diactoros; |
11 | 9 |
14 use Psr\Http\Message\UploadedFileInterface; | 12 use Psr\Http\Message\UploadedFileInterface; |
15 use RuntimeException; | 13 use RuntimeException; |
16 | 14 |
17 class UploadedFile implements UploadedFileInterface | 15 class UploadedFile implements UploadedFileInterface |
18 { | 16 { |
19 /** | 17 const ERROR_MESSAGES = [ |
20 * @var string | 18 UPLOAD_ERR_OK => 'There is no error, the file uploaded with success', |
19 UPLOAD_ERR_INI_SIZE => 'The uploaded file exceeds the upload_max_filesize directive in php.ini', | |
20 UPLOAD_ERR_FORM_SIZE => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was ' | |
21 . 'specified in the HTML form', | |
22 UPLOAD_ERR_PARTIAL => 'The uploaded file was only partially uploaded', | |
23 UPLOAD_ERR_NO_FILE => 'No file was uploaded', | |
24 UPLOAD_ERR_NO_TMP_DIR => 'Missing a temporary folder', | |
25 UPLOAD_ERR_CANT_WRITE => 'Failed to write file to disk', | |
26 UPLOAD_ERR_EXTENSION => 'A PHP extension stopped the file upload.', | |
27 ]; | |
28 | |
29 /** | |
30 * @var string|null | |
21 */ | 31 */ |
22 private $clientFilename; | 32 private $clientFilename; |
23 | 33 |
24 /** | 34 /** |
25 * @var string | 35 * @var string|null |
26 */ | 36 */ |
27 private $clientMediaType; | 37 private $clientMediaType; |
28 | 38 |
29 /** | 39 /** |
30 * @var int | 40 * @var int |
112 * @throws \RuntimeException if the upload was not successful. | 122 * @throws \RuntimeException if the upload was not successful. |
113 */ | 123 */ |
114 public function getStream() | 124 public function getStream() |
115 { | 125 { |
116 if ($this->error !== UPLOAD_ERR_OK) { | 126 if ($this->error !== UPLOAD_ERR_OK) { |
117 throw new RuntimeException('Cannot retrieve stream due to upload error'); | 127 throw new RuntimeException(sprintf( |
128 'Cannot retrieve stream due to upload error: %s', | |
129 self::ERROR_MESSAGES[$this->error] | |
130 )); | |
118 } | 131 } |
119 | 132 |
120 if ($this->moved) { | 133 if ($this->moved) { |
121 throw new RuntimeException('Cannot retrieve stream after it has already been moved'); | 134 throw new RuntimeException('Cannot retrieve stream after it has already been moved'); |
122 } | 135 } |
145 if ($this->moved) { | 158 if ($this->moved) { |
146 throw new RuntimeException('Cannot move file; already moved!'); | 159 throw new RuntimeException('Cannot move file; already moved!'); |
147 } | 160 } |
148 | 161 |
149 if ($this->error !== UPLOAD_ERR_OK) { | 162 if ($this->error !== UPLOAD_ERR_OK) { |
150 throw new RuntimeException('Cannot retrieve stream due to upload error'); | 163 throw new RuntimeException(sprintf( |
164 'Cannot retrieve stream due to upload error: %s', | |
165 self::ERROR_MESSAGES[$this->error] | |
166 )); | |
151 } | 167 } |
152 | 168 |
153 if (! is_string($targetPath) || empty($targetPath)) { | 169 if (! is_string($targetPath) || empty($targetPath)) { |
154 throw new InvalidArgumentException( | 170 throw new InvalidArgumentException( |
155 'Invalid path provided for move operation; must be a non-empty string' | 171 'Invalid path provided for move operation; must be a non-empty string' |