1 | <?php |
||
5 | trait UploadContent |
||
6 | { |
||
7 | /** |
||
8 | * The file should be uploaded in chunks if it size exceeds the 150 MB threshold |
||
9 | * or if the resource size could not be determined (eg. a popen() stream). |
||
10 | * |
||
11 | * @param string|resource $contents |
||
12 | * |
||
13 | * @return bool |
||
14 | */ |
||
15 | 1 | protected function shouldUploadChunk($contents) |
|
21 | |||
22 | /** |
||
23 | * Check if the contents is a pipe stream (not seekable, no size defined). |
||
24 | * |
||
25 | * @param string|resource $contents |
||
26 | * |
||
27 | * @return bool |
||
28 | */ |
||
29 | 1 | protected function isPipe($contents) |
|
33 | |||
34 | /** |
||
35 | * Upload file split in chunks. This allows uploading large files, since |
||
36 | * Dropbox API v2 limits the content size to 150MB. |
||
37 | * |
||
38 | * The chunk size will affect directly the memory usage, so be careful. |
||
39 | * Large chunks tends to speed up the upload, while smaller optimizes memory usage. |
||
40 | * |
||
41 | * @param string $path |
||
42 | * @param string|resource $contents |
||
43 | * @param string $mode |
||
44 | * @param int $chunkSize |
||
45 | * |
||
46 | * @throws \Exception |
||
47 | * |
||
48 | * @return array |
||
49 | */ |
||
50 | 3 | public function uploadChunk($path, $contents, $mode = 'add', $chunkSize = null) |
|
79 | |||
80 | /** |
||
81 | * Upload sessions allow you to upload a single file in one or more requests, |
||
82 | * for example where the size of the file is greater than 150 MB. |
||
83 | * This call starts a new upload session with the given data. |
||
84 | * |
||
85 | * @link https://www.dropbox.com/developers/documentation/http/documentation#files-upload_session-start |
||
86 | * |
||
87 | * @param string $contents |
||
88 | * @param bool $close |
||
89 | * |
||
90 | * @return \Srmklive\Dropbox\DropboxUploadCounter |
||
91 | */ |
||
92 | 1 | public function startUploadSession($contents, $close = false) |
|
109 | |||
110 | /** |
||
111 | * Append more data to an upload session. |
||
112 | * When the parameter close is set, this call will close the session. |
||
113 | * A single request should not upload more than 150 MB. |
||
114 | * |
||
115 | * @link https://www.dropbox.com/developers/documentation/http/documentation#files-upload_session-append_v2 |
||
116 | * |
||
117 | * @param string $contents |
||
118 | * @param DropboxUploadCounter $cursor |
||
119 | * @param bool $close |
||
120 | * |
||
121 | * @return \Srmklive\Dropbox\DropboxUploadCounter |
||
122 | */ |
||
123 | 1 | public function appendContentToUploadSession($contents, DropboxUploadCounter $cursor, $close = false) |
|
137 | |||
138 | /** |
||
139 | * Finish an upload session and save the uploaded data to the given file path. |
||
140 | * A single request should not upload more than 150 MB. |
||
141 | * |
||
142 | * @link https://www.dropbox.com/developers/documentation/http/documentation#files-upload_session-finish |
||
143 | * |
||
144 | * @param string $contents |
||
145 | * @param \Srmklive\Dropbox\DropboxUploadCounter $cursor |
||
146 | * @param string $path |
||
147 | * @param string|array $mode |
||
148 | * @param bool $autorename |
||
149 | * @param bool $mute |
||
150 | * |
||
151 | * @return array |
||
152 | */ |
||
153 | 1 | public function finishUploadSession($contents, DropboxUploadCounter $cursor, $path, $mode = 'add', $autorename = false, $mute = false) |
|
172 | |||
173 | /** |
||
174 | * Sometimes fread() returns less than the request number of bytes (for example, when reading |
||
175 | * from network streams). This function repeatedly calls fread until the requested number of |
||
176 | * bytes have been read or we've reached EOF. |
||
177 | * |
||
178 | * @param resource $stream |
||
179 | * @param int $chunkSize |
||
180 | * |
||
181 | * @throws \Exception |
||
182 | * |
||
183 | * @return string |
||
184 | */ |
||
185 | 3 | protected static function readChunk($stream, $chunkSize) |
|
201 | } |
||
202 |
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.