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 IRootFolder |
||
63 | */ |
||
64 | private $rootFolder; |
||
65 | /** |
||
66 | * @var ILogger |
||
67 | */ |
||
68 | private $logger; |
||
69 | /** |
||
70 | * The path to the userFolder for users with accounts: /userId/files |
||
71 | * |
||
72 | * For public folders, it's the path from the shared folder to the root folder in the original |
||
73 | * owner's filesystem: /userId/files/parent_folder/shared_folder |
||
74 | * |
||
75 | * @var string |
||
76 | */ |
||
77 | private $fromRootToFolder; |
||
78 | /** |
||
79 | * The name of the shared folder |
||
80 | * |
||
81 | * @var string |
||
82 | */ |
||
83 | private $folderName; |
||
84 | /** |
||
85 | * @var string|null |
||
86 | */ |
||
87 | private $sharePassword; |
||
88 | |||
89 | /*** |
||
90 | * Constructor |
||
91 | * |
||
92 | * @param string $appName |
||
93 | * @param string|null $userId |
||
94 | * @param Folder|null $userFolder |
||
95 | * @param IUserManager $userManager |
||
96 | * @param IRootFolder $rootFolder |
||
97 | * @param ILogger $logger |
||
98 | */ |
||
99 | 58 | public function __construct( |
|
114 | |||
115 | /** |
||
116 | * Creates the environment based on the linkItem the token links to |
||
117 | * |
||
118 | * @param array $linkItem |
||
119 | */ |
||
120 | 20 | public function setTokenBasedEnv($linkItem) { |
|
134 | |||
135 | /** |
||
136 | * Creates the environment for a logged-in user |
||
137 | * |
||
138 | * userId and userFolder are already known, we define fromRootToFolder |
||
139 | * so that the services can use one method to have access to resources |
||
140 | * without having to know whether they're private or public |
||
141 | */ |
||
142 | 29 | public function setStandardEnv() { |
|
145 | |||
146 | /** |
||
147 | * Returns the Node based on a path starting from the virtual root |
||
148 | * |
||
149 | * @param string $subPath |
||
150 | * |
||
151 | * @return File|Folder |
||
|
|||
152 | */ |
||
153 | 8 | public function getNodeFromVirtualRoot($subPath) { |
|
160 | |||
161 | /** |
||
162 | * Returns the Node based on a path starting from the files' owner user folder |
||
163 | * |
||
164 | * When logged in, this is the current user's user folder |
||
165 | * When visiting a link, this is the sharer's user folder |
||
166 | * |
||
167 | * @param string $path |
||
168 | * |
||
169 | * @return File|Folder |
||
170 | * |
||
171 | * @throws NotFoundEnvException |
||
172 | */ |
||
173 | 11 | public function getNodeFromUserFolder($path) { |
|
188 | |||
189 | /** |
||
190 | * Returns the resource identified by the given ID |
||
191 | * |
||
192 | * @param int $resourceId |
||
193 | * |
||
194 | * @return Node |
||
195 | * |
||
196 | * @throws NotFoundEnvException |
||
197 | */ |
||
198 | 36 | public function getResourceFromId($resourceId) { |
|
206 | |||
207 | /** |
||
208 | * Returns the shared node |
||
209 | * |
||
210 | * @return File|Folder |
||
211 | */ |
||
212 | 8 | public function getSharedNode() { |
|
215 | |||
216 | /** |
||
217 | * Returns the virtual root where the user lands after logging in or when following a link |
||
218 | * |
||
219 | * @return Folder |
||
220 | * @throws NotFoundEnvException |
||
221 | */ |
||
222 | 14 | public function getVirtualRootFolder() { |
|
236 | |||
237 | /** |
||
238 | * Returns the userId of the currently logged-in user or the sharer |
||
239 | * |
||
240 | * @return string |
||
241 | */ |
||
242 | 9 | public function getUserId() { |
|
245 | |||
246 | /** |
||
247 | * Returns the name of the user sharing files publicly |
||
248 | * |
||
249 | * @return string |
||
250 | * @throws NotFoundEnvException |
||
251 | */ |
||
252 | 2 | public function getDisplayName() { |
|
265 | |||
266 | /** |
||
267 | * Returns the name of shared folder |
||
268 | * |
||
269 | * @return string |
||
270 | */ |
||
271 | 1 | public function getSharedFolderName() { |
|
274 | |||
275 | /** |
||
276 | * Returns the password for the share, if there is one |
||
277 | * |
||
278 | * @return string|null |
||
279 | */ |
||
280 | 1 | public function getSharePassword() { |
|
283 | |||
284 | /** |
||
285 | * Returns the path which goes from the file, up to the user folder, based on a node: |
||
286 | * parent_folder/current_folder/my_file |
||
287 | * |
||
288 | * This is used for the preview system, which needs a full path |
||
289 | * |
||
290 | * getPath() on the file produces a path like: |
||
291 | * '/userId/files/my_folder/my_sub_folder/my_file' |
||
292 | * |
||
293 | * So we substract the path to the folder, giving us a relative path |
||
294 | * 'my_folder/my_sub_folder/my_file' |
||
295 | * |
||
296 | * @param Node $file |
||
297 | * |
||
298 | * @return string |
||
299 | */ |
||
300 | 9 | public function getPathFromUserFolder($file) { |
|
305 | |||
306 | /** |
||
307 | * Returns the path which goes from the file, up to the root folder of the Gallery: |
||
308 | * current_folder/my_file |
||
309 | * |
||
310 | * That root folder changes when folders are shared publicly |
||
311 | * |
||
312 | * @param File|Folder|N $node |
||
313 | * |
||
314 | * @return string |
||
315 | */ |
||
316 | 10 | public function getPathFromVirtualRoot($node) { |
|
330 | |||
331 | /** |
||
332 | * Returns the path from the shared folder to the root folder in the original |
||
333 | * owner's filesystem: /userId/files/parent_folder/shared_folder |
||
334 | * |
||
335 | * This cannot be calculated with paths and IDs, the linkitem's file source is required |
||
336 | * |
||
337 | * @param string $fileSource |
||
338 | * |
||
339 | * @return string |
||
340 | */ |
||
341 | 20 | private function buildFromRootToFolder($fileSource) { |
|
347 | |||
348 | /** |
||
349 | * Returns the path which goes from the file, up to the user folder, based on a path: |
||
350 | * parent_folder/current_folder/my_file |
||
351 | * |
||
352 | * getPath() on the file produces a path like: |
||
353 | * '/userId/files/my_folder/my_sub_folder/my_file' |
||
354 | * |
||
355 | * So we substract the path to the user folder, giving us a relative path |
||
356 | * 'my_folder/my_sub_folder' |
||
357 | * |
||
358 | * @param string $fullPath |
||
359 | * |
||
360 | * @return string |
||
361 | */ |
||
362 | 17 | private function getRelativePath($fullPath) { |
|
368 | |||
369 | } |
||
370 |
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.