1 | <?php |
||
31 | class Environment { |
||
32 | |||
33 | /** |
||
34 | * @var string |
||
35 | */ |
||
36 | private $appName; |
||
37 | /** |
||
38 | * The userId of the logged-in user or the person sharing a folder publicly |
||
39 | * |
||
40 | * @var string |
||
41 | */ |
||
42 | private $userId; |
||
43 | /** |
||
44 | * The userFolder of the logged-in user or the ORIGINAL owner of the files which are shared |
||
45 | * publicly |
||
46 | * |
||
47 | * A share needs to be tracked back to its original owner in order to be able to access the |
||
48 | * resource |
||
49 | * |
||
50 | * @var Folder|null |
||
51 | */ |
||
52 | private $userFolder; |
||
53 | /** |
||
54 | * @var IUserManager |
||
55 | */ |
||
56 | private $userManager; |
||
57 | /** |
||
58 | * @var int |
||
59 | */ |
||
60 | private $sharedNodeId; |
||
61 | /** |
||
62 | * @var File|Folder |
||
63 | */ |
||
64 | private $sharedNode; |
||
65 | /** |
||
66 | * @var IRootFolder |
||
67 | */ |
||
68 | private $rootFolder; |
||
69 | /** |
||
70 | * @var ILogger |
||
71 | */ |
||
72 | private $logger; |
||
73 | /** |
||
74 | * The path to the userFolder for users with accounts: /userId/files |
||
75 | * |
||
76 | * For public folders, it's the path from the shared folder to the root folder in the original |
||
77 | * owner's filesystem: /userId/files/parent_folder/shared_folder |
||
78 | * |
||
79 | * @var string |
||
80 | */ |
||
81 | private $fromRootToFolder; |
||
82 | /** |
||
83 | * The name of the shared folder |
||
84 | * |
||
85 | * @var string |
||
86 | */ |
||
87 | private $folderName; |
||
88 | /** |
||
89 | * @var string|null |
||
90 | */ |
||
91 | private $sharePassword; |
||
92 | |||
93 | /*** |
||
94 | * Constructor |
||
95 | * |
||
96 | * @param string $appName |
||
97 | * @param string|null $userId |
||
98 | * @param Folder|null $userFolder |
||
99 | * @param IUserManager $userManager |
||
100 | * @param IRootFolder $rootFolder |
||
101 | * @param ILogger $logger |
||
102 | */ |
||
103 | 59 | public function __construct( |
|
118 | |||
119 | /** |
||
120 | * Creates the environment based on the linkItem the token links to |
||
121 | * |
||
122 | * @param array $linkItem |
||
123 | */ |
||
124 | 21 | public function setTokenBasedEnv($linkItem) { |
|
140 | |||
141 | /** |
||
142 | * Creates the environment for a logged-in user |
||
143 | * |
||
144 | * userId and userFolder are already known, we define fromRootToFolder |
||
145 | * so that the services can use one method to have access to resources |
||
146 | * without having to know whether they're private or public |
||
147 | */ |
||
148 | 29 | public function setStandardEnv() { |
|
151 | |||
152 | /** |
||
153 | * Returns true if the environment has been setup using a token |
||
154 | * |
||
155 | * @return bool |
||
156 | */ |
||
157 | 43 | public function isTokenBasedEnv() { |
|
160 | |||
161 | /** |
||
162 | * Returns the Node based on a path starting from the virtual root |
||
163 | * |
||
164 | * @param string $subPath |
||
165 | * |
||
166 | * @return File|Folder |
||
167 | */ |
||
168 | 8 | public function getNodeFromVirtualRoot($subPath) { |
|
175 | |||
176 | /** |
||
177 | * Returns the Node based on a path starting from the files' owner user folder |
||
178 | * |
||
179 | * When logged in, this is the current user's user folder |
||
180 | * When visiting a link, this is the sharer's user folder |
||
181 | * |
||
182 | * @param string $path |
||
183 | * |
||
184 | * @return File|Folder |
||
185 | * |
||
186 | * @throws NotFoundEnvException |
||
187 | */ |
||
188 | 11 | public function getNodeFromUserFolder($path) { |
|
203 | |||
204 | /** |
||
205 | * Returns the resource identified by the given ID |
||
206 | * |
||
207 | * @param int $resourceId |
||
208 | * |
||
209 | * @return Node |
||
210 | * |
||
211 | * @throws NotFoundEnvException |
||
212 | */ |
||
213 | 37 | public function getResourceFromId($resourceId) { |
|
226 | |||
227 | /** |
||
228 | * Returns the shared node |
||
229 | * |
||
230 | * @return File|Folder |
||
231 | */ |
||
232 | 8 | public function getSharedNode() { |
|
235 | |||
236 | /** |
||
237 | * Returns the virtual root where the user lands after logging in or when following a link |
||
238 | * |
||
239 | * @return Folder |
||
240 | * @throws NotFoundEnvException |
||
241 | */ |
||
242 | 14 | public function getVirtualRootFolder() { |
|
256 | |||
257 | /** |
||
258 | * Returns the userId of the currently logged-in user or the sharer |
||
259 | * |
||
260 | * @return string |
||
261 | */ |
||
262 | 9 | public function getUserId() { |
|
265 | |||
266 | /** |
||
267 | * Returns the name of the user sharing files publicly |
||
268 | * |
||
269 | * @return string |
||
270 | * @throws NotFoundEnvException |
||
271 | */ |
||
272 | 2 | public function getDisplayName() { |
|
285 | |||
286 | /** |
||
287 | * Returns the name of shared folder |
||
288 | * |
||
289 | * @return string |
||
290 | */ |
||
291 | 1 | public function getSharedFolderName() { |
|
294 | |||
295 | /** |
||
296 | * Returns the password for the share, if there is one |
||
297 | * |
||
298 | * @return string|null |
||
299 | */ |
||
300 | 1 | public function getSharePassword() { |
|
303 | |||
304 | /** |
||
305 | * Returns the path which goes from the file, up to the user folder, based on a node: |
||
306 | * parent_folder/current_folder/my_file |
||
307 | * |
||
308 | * This is used for the preview system, which needs a full path |
||
309 | * |
||
310 | * getPath() on the file produces a path like: |
||
311 | * '/userId/files/my_folder/my_sub_folder/my_file' |
||
312 | * |
||
313 | * So we substract the path to the folder, giving us a relative path |
||
314 | * 'my_folder/my_sub_folder/my_file' |
||
315 | * |
||
316 | * @param Node $file |
||
317 | * |
||
318 | * @return string |
||
319 | */ |
||
320 | 9 | public function getPathFromUserFolder($file) { |
|
325 | |||
326 | /** |
||
327 | * Returns the path which goes from the file, up to the root folder of the Gallery: |
||
328 | * current_folder/my_file |
||
329 | * |
||
330 | * That root folder changes when folders are shared publicly |
||
331 | * |
||
332 | * @param File|Folder|N $node |
||
333 | * |
||
334 | * @return string |
||
335 | */ |
||
336 | 10 | public function getPathFromVirtualRoot($node) { |
|
350 | |||
351 | /** |
||
352 | * Returns the resource found in a specific folder and identified by the given ID |
||
353 | * |
||
354 | * @param Folder $folder |
||
355 | * @param int $resourceId |
||
356 | * |
||
357 | * @return Node |
||
358 | * @throws NotFoundEnvException |
||
359 | */ |
||
360 | 37 | private function getResourceFromFolderAndId($folder, $resourceId) { |
|
369 | |||
370 | /** |
||
371 | * Returns the path from the shared folder to the root folder in the original |
||
372 | * owner's filesystem: /userId/files/parent_folder/shared_folder |
||
373 | * |
||
374 | * This cannot be calculated with paths and IDs, the linkitem's file source is required |
||
375 | * |
||
376 | * @param string $fileSource |
||
377 | * |
||
378 | * @return string |
||
379 | */ |
||
380 | 21 | private function buildFromRootToFolder($fileSource) { |
|
386 | |||
387 | /** |
||
388 | * Returns the path which goes from the file, up to the user folder, based on a path: |
||
389 | * parent_folder/current_folder/my_file |
||
390 | * |
||
391 | * getPath() on the file produces a path like: |
||
392 | * '/userId/files/my_folder/my_sub_folder/my_file' |
||
393 | * |
||
394 | * So we substract the path to the user folder, giving us a relative path |
||
395 | * 'my_folder/my_sub_folder' |
||
396 | * |
||
397 | * @param string $fullPath |
||
398 | * |
||
399 | * @return string |
||
400 | */ |
||
401 | 17 | private function getRelativePath($fullPath) { |
|
407 | |||
408 | } |
||
409 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..