1 | <?php |
||
32 | class Environment { |
||
33 | |||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | private $appName; |
||
38 | /** |
||
39 | * The userId of the logged-in user or the person sharing a folder publicly |
||
40 | * |
||
41 | * @var string |
||
42 | */ |
||
43 | private $userId; |
||
44 | /** |
||
45 | * The userFolder of the logged-in user or the ORIGINAL owner of the files which are shared |
||
46 | * publicly |
||
47 | * |
||
48 | * A share needs to be tracked back to its original owner in order to be able to access the |
||
49 | * resource |
||
50 | * |
||
51 | * @var Folder|null |
||
52 | */ |
||
53 | private $userFolder; |
||
54 | /** |
||
55 | * @var IUserManager |
||
56 | */ |
||
57 | private $userManager; |
||
58 | /** |
||
59 | * @var int |
||
60 | */ |
||
61 | private $sharedNodeId; |
||
62 | /** |
||
63 | * @var File|Folder |
||
64 | */ |
||
65 | private $sharedNode; |
||
66 | /** |
||
67 | * @var IRootFolder |
||
68 | */ |
||
69 | private $rootFolder; |
||
70 | /** |
||
71 | * @var ILogger |
||
72 | */ |
||
73 | private $logger; |
||
74 | /** |
||
75 | * The path to the userFolder for users with accounts: /userId/files |
||
76 | * |
||
77 | * For public folders, it's the path from the shared folder to the root folder in the original |
||
78 | * owner's filesystem: /userId/files/parent_folder/shared_folder |
||
79 | * |
||
80 | * @var string |
||
81 | */ |
||
82 | private $fromRootToFolder; |
||
83 | /** |
||
84 | * The name of the shared folder |
||
85 | * |
||
86 | * @var string |
||
87 | */ |
||
88 | private $folderName; |
||
89 | /** |
||
90 | * @var string|null |
||
91 | */ |
||
92 | private $sharePassword; |
||
93 | |||
94 | /*** |
||
95 | * Constructor |
||
96 | * |
||
97 | * @param string $appName |
||
98 | * @param string|null $userId |
||
99 | * @param Folder|null $userFolder |
||
100 | * @param IUserManager $userManager |
||
101 | * @param IRootFolder $rootFolder |
||
102 | * @param ILogger $logger |
||
103 | */ |
||
104 | 59 | public function __construct( |
|
119 | |||
120 | /** |
||
121 | * Creates the environment based on the share the token links to |
||
122 | * |
||
123 | * @param IShare $share |
||
124 | */ |
||
125 | 21 | public function setTokenBasedEnv($share) { |
|
137 | |||
138 | /** |
||
139 | * Creates the environment for a logged-in user |
||
140 | * |
||
141 | * userId and userFolder are already known, we define fromRootToFolder |
||
142 | * so that the services can use one method to have access to resources |
||
143 | * without having to know whether they're private or public |
||
144 | */ |
||
145 | 29 | public function setStandardEnv() { |
|
148 | |||
149 | /** |
||
150 | * Returns true if the environment has been setup using a token |
||
151 | * |
||
152 | * @return bool |
||
153 | */ |
||
154 | 43 | public function isTokenBasedEnv() { |
|
157 | |||
158 | /** |
||
159 | * Returns the Node based on a path starting from the virtual root |
||
160 | * |
||
161 | * @param string $subPath |
||
162 | * |
||
163 | * @return File|Folder |
||
|
|||
164 | */ |
||
165 | 8 | public function getNodeFromVirtualRoot($subPath) { |
|
172 | |||
173 | /** |
||
174 | * Returns the Node based on a path starting from the files' owner user folder |
||
175 | * |
||
176 | * When logged in, this is the current user's user folder |
||
177 | * When visiting a link, this is the sharer's user folder |
||
178 | * |
||
179 | * @param string $path |
||
180 | * |
||
181 | * @return File|Folder |
||
182 | * |
||
183 | * @throws NotFoundEnvException |
||
184 | */ |
||
185 | 11 | public function getNodeFromUserFolder($path) { |
|
200 | |||
201 | /** |
||
202 | * Returns the resource identified by the given ID |
||
203 | * |
||
204 | * @param int $resourceId |
||
205 | * |
||
206 | * @return Node |
||
207 | * |
||
208 | * @throws NotFoundEnvException |
||
209 | */ |
||
210 | 37 | public function getResourceFromId($resourceId) { |
|
223 | |||
224 | /** |
||
225 | * Returns the shared node |
||
226 | * |
||
227 | * @return File|Folder |
||
228 | */ |
||
229 | 8 | public function getSharedNode() { |
|
232 | |||
233 | /** |
||
234 | * Returns the virtual root where the user lands after logging in or when following a link |
||
235 | * |
||
236 | * @return Folder |
||
237 | * @throws NotFoundEnvException |
||
238 | */ |
||
239 | 14 | public function getVirtualRootFolder() { |
|
253 | |||
254 | /** |
||
255 | * Returns the userId of the currently logged-in user or the sharer |
||
256 | * |
||
257 | * @return string |
||
258 | */ |
||
259 | 9 | public function getUserId() { |
|
262 | |||
263 | /** |
||
264 | * Returns the name of the user sharing files publicly |
||
265 | * |
||
266 | * @return string |
||
267 | * @throws NotFoundEnvException |
||
268 | */ |
||
269 | 2 | public function getDisplayName() { |
|
282 | |||
283 | /** |
||
284 | * Returns the name of shared folder |
||
285 | * |
||
286 | * @return string |
||
287 | */ |
||
288 | 1 | public function getSharedFolderName() { |
|
291 | |||
292 | /** |
||
293 | * Returns the password for the share, if there is one |
||
294 | * |
||
295 | * @return string|null |
||
296 | */ |
||
297 | 1 | public function getSharePassword() { |
|
300 | |||
301 | /** |
||
302 | * Returns the path which goes from the file, up to the user folder, based on a node: |
||
303 | * parent_folder/current_folder/my_file |
||
304 | * |
||
305 | * This is used for the preview system, which needs a full path |
||
306 | * |
||
307 | * getPath() on the file produces a path like: |
||
308 | * '/userId/files/my_folder/my_sub_folder/my_file' |
||
309 | * |
||
310 | * So we substract the path to the folder, giving us a relative path |
||
311 | * 'my_folder/my_sub_folder/my_file' |
||
312 | * |
||
313 | * @param Node $file |
||
314 | * |
||
315 | * @return string |
||
316 | */ |
||
317 | 9 | public function getPathFromUserFolder($file) { |
|
322 | |||
323 | /** |
||
324 | * Returns the path which goes from the file, up to the root folder of the Gallery: |
||
325 | * current_folder/my_file |
||
326 | * |
||
327 | * That root folder changes when folders are shared publicly |
||
328 | * |
||
329 | * @param File|Folder|Node $node |
||
330 | * |
||
331 | * @return string |
||
332 | */ |
||
333 | 10 | public function getPathFromVirtualRoot($node) { |
|
347 | |||
348 | /** |
||
349 | * Returns the resource found in a specific folder and identified by the given ID |
||
350 | * |
||
351 | * @param Folder $folder |
||
352 | * @param int $resourceId |
||
353 | * |
||
354 | * @return Node |
||
355 | * @throws NotFoundEnvException |
||
356 | */ |
||
357 | 33 | private function getResourceFromFolderAndId($folder, $resourceId) { |
|
366 | |||
367 | /** |
||
368 | * Returns the path from the shared folder to the root folder in the original |
||
369 | * owner's filesystem: /userId/files/parent_folder/shared_folder |
||
370 | * |
||
371 | * This cannot be calculated with paths and IDs, the share's file source is required |
||
372 | * |
||
373 | * @param string $fileSource |
||
374 | * |
||
375 | * @return string |
||
376 | */ |
||
377 | 21 | private function buildFromRootToFolder($fileSource) { |
|
383 | |||
384 | /** |
||
385 | * Returns the path which goes from the file, up to the user folder, based on a path: |
||
386 | * parent_folder/current_folder/my_file |
||
387 | * |
||
388 | * getPath() on the file produces a path like: |
||
389 | * '/userId/files/my_folder/my_sub_folder/my_file' |
||
390 | * |
||
391 | * So we substract the path to the user folder, giving us a relative path |
||
392 | * 'my_folder/my_sub_folder' |
||
393 | * |
||
394 | * @param string $fullPath |
||
395 | * |
||
396 | * @return string |
||
397 | */ |
||
398 | 17 | private function getRelativePath($fullPath) { |
|
404 | |||
405 | } |
||
406 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.