1 | <?php |
||
10 | class DropboxFile |
||
11 | { |
||
12 | const MODE_READ = 'r'; |
||
13 | |||
14 | const MODE_WRITE = 'w'; |
||
15 | |||
16 | /** |
||
17 | * Path of the file to upload |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $path; |
||
22 | |||
23 | /** |
||
24 | * The maximum bytes to read. Defaults to -1 (read all the remaining buffer). |
||
25 | * |
||
26 | * @var int |
||
27 | */ |
||
28 | protected $maxLength = -1; |
||
29 | |||
30 | /** |
||
31 | * Seek to the specified offset before reading. |
||
32 | * If this number is negative, no seeking will |
||
33 | * occur and reading will start from the current. |
||
34 | * |
||
35 | * @var int |
||
36 | */ |
||
37 | protected $offset = -1; |
||
38 | |||
39 | /** |
||
40 | * File Stream |
||
41 | * |
||
42 | * @var \GuzzleHttp\Psr7\Stream |
||
43 | */ |
||
44 | protected $stream; |
||
45 | |||
46 | /** |
||
47 | * The type of access |
||
48 | * |
||
49 | * @var string |
||
50 | */ |
||
51 | protected $mode; |
||
52 | |||
53 | /** |
||
54 | * Flag to see if we created an instance using a stream |
||
55 | * |
||
56 | * @var bool |
||
57 | */ |
||
58 | private $isStream = false; |
||
59 | |||
60 | /** |
||
61 | * Create a new DropboxFile instance |
||
62 | * |
||
63 | * @param string $filePath Path of the file to upload |
||
64 | * @param string $mode The type of access |
||
65 | */ |
||
66 | public function __construct($filePath, $mode = self::MODE_READ) |
||
71 | |||
72 | /** |
||
73 | * Create a new DropboxFile instance using a file stream |
||
74 | * |
||
75 | * @param $fileName |
||
76 | * @param $resource |
||
77 | * @param string $mode |
||
78 | * |
||
79 | * @return DropboxFile |
||
80 | * @throws DropboxClientException |
||
81 | */ |
||
82 | public static function createByStream($fileName, $resource, $mode = self::MODE_READ) |
||
101 | |||
102 | /** |
||
103 | * Create a new DropboxFile instance using a file path |
||
104 | * |
||
105 | * This behaves the same as the constructor but was added in order to |
||
106 | * match the syntax of the static createByStream function |
||
107 | * |
||
108 | * @see DropboxFile::createByStream() |
||
109 | * |
||
110 | * @param $filePath |
||
111 | * @param $mode |
||
112 | * |
||
113 | * @return DropboxFile |
||
114 | */ |
||
115 | public static function createByPath($filePath, $mode) |
||
119 | |||
120 | /** |
||
121 | * Closes the stream when destructed. |
||
122 | */ |
||
123 | public function __destruct() |
||
127 | |||
128 | /** |
||
129 | * Close the file stream |
||
130 | */ |
||
131 | public function close() |
||
137 | |||
138 | /** |
||
139 | * Set the offset to start reading |
||
140 | * the data from the stream |
||
141 | * |
||
142 | * @param int $offset |
||
143 | */ |
||
144 | public function setOffset($offset) |
||
148 | |||
149 | /** |
||
150 | * Set the Max Length till where to read |
||
151 | * the data from the stream. |
||
152 | * |
||
153 | * @param int $maxLength |
||
154 | */ |
||
155 | public function setMaxLength($maxLength) |
||
159 | |||
160 | /** |
||
161 | * Return the contents of the file |
||
162 | * |
||
163 | * @return string |
||
164 | */ |
||
165 | public function getContents() |
||
182 | |||
183 | /** |
||
184 | * Get the Open File Stream |
||
185 | * |
||
186 | * @return \GuzzleHttp\Psr7\Stream |
||
187 | */ |
||
188 | public function getStream() |
||
195 | |||
196 | /** |
||
197 | * Manually set the stream for this DropboxFile instance |
||
198 | * |
||
199 | * @param $stream |
||
200 | */ |
||
201 | public function setStream($stream) |
||
206 | |||
207 | /** |
||
208 | * Opens the File Stream |
||
209 | * |
||
210 | * @throws DropboxClientException |
||
211 | * |
||
212 | * @return void |
||
213 | */ |
||
214 | public function open() |
||
242 | |||
243 | /** |
||
244 | * @return bool |
||
245 | */ |
||
246 | protected function isCreatedFromStream() |
||
250 | |||
251 | /** |
||
252 | * Returns true if the path to the file is remote |
||
253 | * |
||
254 | * @param string $pathToFile |
||
255 | * |
||
256 | * @return boolean |
||
257 | */ |
||
258 | protected function isRemoteFile($pathToFile) |
||
262 | |||
263 | /** |
||
264 | * @return bool |
||
265 | */ |
||
266 | protected function isNotReadable() |
||
270 | |||
271 | /** |
||
272 | * @return bool |
||
273 | */ |
||
274 | protected function isNotWritable() |
||
278 | |||
279 | /** |
||
280 | * Get the name of the file |
||
281 | * |
||
282 | * @return string |
||
283 | */ |
||
284 | public function getFileName() |
||
288 | |||
289 | /** |
||
290 | * Get the path of the file |
||
291 | * |
||
292 | * @return string |
||
293 | */ |
||
294 | public function getFilePath() |
||
298 | |||
299 | /** |
||
300 | * Get the mode of the file stream |
||
301 | * |
||
302 | * @return string |
||
303 | */ |
||
304 | public function getMode() |
||
308 | |||
309 | /** |
||
310 | * Get the size of the file |
||
311 | * |
||
312 | * @return int |
||
313 | */ |
||
314 | public function getSize() |
||
318 | |||
319 | /** |
||
320 | * Get mimetype of the file |
||
321 | * |
||
322 | * @return string |
||
323 | */ |
||
324 | public function getMimetype() |
||
328 | } |
||
329 |