| File: UploadedFile.php Lines 30 to 49 | 
 | 
30 |     private $stream; | 
 | 
31 |  | 
 | 
32 |     /** | 
 | 
33 |      * @param string|resource|\Psr\Http\Message\StreamInterface $streamOrFile | 
 | 
34 |      * @param int $size UPLOAD_ERR_* constant | 
 | 
35 |      * @param int $errorCode | 
 | 
36 |      * @param string $clientFilename | 
 | 
37 |      * @param string $clientMediaType | 
 | 
38 |      */ | 
 |  |     public function __construct($streamOrFile, $size, $errorCode, $clientFilename=null, $clientMediaType=null) { | 
 | 
40 |         if($errorCode === UPLOAD_ERR_OK) { | 
 | 
41 |             if(is_string($streamOrFile)) { | 
 | 
42 |                 $this->file = $streamOrFile; | 
 | 
43 |             } elseif(is_resource($streamOrFile)) { | 
 | 
44 |                 $this->stream = new Stream($streamOrFile); | 
 | 
45 |             } elseif($streamOrFile instanceof \Psr\Http\Message\StreamInterface) { | 
 | 
46 |                 $this->stream = $streamOrFile; | 
 | 
47 |             } else { | 
 | 
48 |                 throw new \InvalidArgumentException('Invalid stream or file provided for UploadedFile'); | 
 | 
49 |             } | 
|   | 
| File: UploadedFile.php Lines 69 to 88 | 
 | 
69 |         } | 
 | 
70 |         $this->clientMediaType = $clientMediaType; | 
 | 
71 |     } | 
 | 
72 |  | 
 | 
73 |     /** | 
 | 
74 |      * $_FILES の1件分から作成する | 
 | 
75 |      * @param array $file | 
 | 
76 |      * @return \Puyo\Psr7\UploadedFile | 
 | 
77 |      */ | 
 |  |     public static function createBy_FILE(array $file) { | 
 | 
79 |         return new UploadedFile($file['tmp_name'], $file['size'], $file['error'], $file['name'], $file['type']); | 
 | 
80 |     } | 
 | 
81 |  | 
 | 
82 |     /** | 
 | 
83 |      * {@inheritdoc} | 
 | 
84 |      * @return \Psr\Http\Message\StreamInterface | 
 | 
85 |      * @throws \RuntimeException if the upload was not successful. | 
 | 
86 |      */ | 
 | 
87 |     public function getStream() { | 
 | 
88 |         if(!$this->isUploadOk()) { | 
|   | 
| File: UploadedFile.php Lines 151 to 170 | 
 | 
151 |     /** | 
 | 
152 |      * {@inheritdoc} | 
 | 
153 |      * @return string | 
 | 
154 |      */ | 
 | 
155 |     public function getClientMediaType() { | 
 | 
156 |         return $this->clientMediaType; | 
 | 
157 |     } | 
 | 
158 |  | 
 | 
159 |     private function writeFile($path) { | 
 |  |         $fp = fopen($path, 'wb+'); | 
 | 
161 |         if(!is_resource($fp)) { | 
 | 
162 |             throw new \RuntimeException('Unable to write to designated path'); | 
 | 
163 |         } | 
 | 
164 |  | 
 | 
165 |         $stream = $this->getStream(); | 
 | 
166 |         while(!$stream->eof()) { | 
 | 
167 |             fwrite($fp, $stream->read(4096)); | 
 | 
168 |         } | 
 | 
169 |  | 
 | 
170 |         fclose($fp); | 
|   |