1 | <?php |
||
6 | trait UploadContent |
||
7 | { |
||
8 | /** |
||
9 | * The file should be uploaded in chunks if it size exceeds the 150 MB threshold |
||
10 | * or if the resource size could not be determined (eg. a popen() stream). |
||
11 | * |
||
12 | * @param string|resource $contents |
||
13 | * |
||
14 | * @return bool |
||
15 | */ |
||
16 | protected function shouldUploadChunk($contents) |
||
30 | |||
31 | /** |
||
32 | * Check if the contents is a pipe stream (not seekable, no size defined). |
||
33 | * |
||
34 | * @param string|resource $contents |
||
35 | * |
||
36 | * @return bool |
||
37 | */ |
||
38 | protected function isPipe($contents) |
||
42 | |||
43 | /** |
||
44 | * Upload file split in chunks. This allows uploading large files, since |
||
45 | * Dropbox API v2 limits the content size to 150MB. |
||
46 | * |
||
47 | * The chunk size will affect directly the memory usage, so be careful. |
||
48 | * Large chunks tends to speed up the upload, while smaller optimizes memory usage. |
||
49 | * |
||
50 | * @param string $path |
||
51 | * @param string|resource $contents |
||
52 | * @param string $mode |
||
53 | * @param int $chunkSize |
||
54 | * |
||
55 | * @return array |
||
56 | */ |
||
57 | public function uploadChunk($path, $contents, $mode = 'add', $chunkSize = null) |
||
86 | |||
87 | /** |
||
88 | * Upload sessions allow you to upload a single file in one or more requests, |
||
89 | * for example where the size of the file is greater than 150 MB. |
||
90 | * This call starts a new upload session with the given data. |
||
91 | * |
||
92 | * @link https://www.dropbox.com/developers/documentation/http/documentation#files-upload_session-start |
||
93 | * |
||
94 | * @param string $contents |
||
95 | * @param bool $close |
||
96 | * |
||
97 | * @return \Srmklive\Dropbox\DropboxUploadCounter |
||
98 | */ |
||
99 | public function startUploadSession($contents, $close = false) |
||
116 | |||
117 | /** |
||
118 | * Append more data to an upload session. |
||
119 | * When the parameter close is set, this call will close the session. |
||
120 | * A single request should not upload more than 150 MB. |
||
121 | * |
||
122 | * @link https://www.dropbox.com/developers/documentation/http/documentation#files-upload_session-append_v2 |
||
123 | * |
||
124 | * @param string $contents |
||
125 | * @param DropboxUploadCounter $cursor |
||
126 | * @param bool $close |
||
127 | * |
||
128 | * @return \Srmklive\Dropbox\DropboxUploadCounter |
||
129 | */ |
||
130 | public function appendContentToUploadSession($contents, DropboxUploadCounter $cursor, $close = false) |
||
144 | |||
145 | /** |
||
146 | * Finish an upload session and save the uploaded data to the given file path. |
||
147 | * A single request should not upload more than 150 MB. |
||
148 | * |
||
149 | * @link https://www.dropbox.com/developers/documentation/http/documentation#files-upload_session-finish |
||
150 | * |
||
151 | * @param string $contents |
||
152 | * @param \Srmklive\Dropbox\DropboxUploadCounter $cursor |
||
153 | * @param string $path |
||
154 | * @param string|array $mode |
||
155 | * @param bool $autorename |
||
156 | * @param bool $mute |
||
157 | * |
||
158 | * @return array |
||
159 | */ |
||
160 | public function finishUploadSession($contents, DropboxUploadCounter $cursor, $path, $mode = 'add', $autorename = false, $mute = false) |
||
179 | |||
180 | /** |
||
181 | * Sometimes fread() returns less than the request number of bytes (for example, when reading |
||
182 | * from network streams). This function repeatedly calls fread until the requested number of |
||
183 | * bytes have been read or we've reached EOF. |
||
184 | * |
||
185 | * @param resource $stream |
||
186 | * @param int $chunkSize |
||
187 | * |
||
188 | * @throws \Exception |
||
189 | * |
||
190 | * @return string |
||
191 | */ |
||
192 | protected static function readChunk($stream, $chunkSize) |
||
208 | } |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.