@@ -30,34 +30,34 @@ |
||
30 | 30 | */ |
31 | 31 | class CreateUserEvent extends Event { |
32 | 32 | |
33 | - /** @var string */ |
|
34 | - private $uid; |
|
35 | - |
|
36 | - /** @var string */ |
|
37 | - private $password; |
|
38 | - |
|
39 | - /** |
|
40 | - * @since 18.0.0 |
|
41 | - */ |
|
42 | - public function __construct(string $uid, |
|
43 | - string $password) { |
|
44 | - parent::__construct(); |
|
45 | - $this->uid = $uid; |
|
46 | - $this->password = $password; |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * @since 18.0.0 |
|
51 | - */ |
|
52 | - public function getUid(): string { |
|
53 | - return $this->uid; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * @since 18.0.0 |
|
58 | - */ |
|
59 | - public function getPassword(): string { |
|
60 | - return $this->password; |
|
61 | - } |
|
33 | + /** @var string */ |
|
34 | + private $uid; |
|
35 | + |
|
36 | + /** @var string */ |
|
37 | + private $password; |
|
38 | + |
|
39 | + /** |
|
40 | + * @since 18.0.0 |
|
41 | + */ |
|
42 | + public function __construct(string $uid, |
|
43 | + string $password) { |
|
44 | + parent::__construct(); |
|
45 | + $this->uid = $uid; |
|
46 | + $this->password = $password; |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * @since 18.0.0 |
|
51 | + */ |
|
52 | + public function getUid(): string { |
|
53 | + return $this->uid; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * @since 18.0.0 |
|
58 | + */ |
|
59 | + public function getPassword(): string { |
|
60 | + return $this->password; |
|
61 | + } |
|
62 | 62 | |
63 | 63 | } |
@@ -31,41 +31,41 @@ |
||
31 | 31 | */ |
32 | 32 | class UserCreatedEvent extends Event { |
33 | 33 | |
34 | - /** @var IUser */ |
|
35 | - private $user; |
|
34 | + /** @var IUser */ |
|
35 | + private $user; |
|
36 | 36 | |
37 | - /** @var string */ |
|
38 | - private $password; |
|
37 | + /** @var string */ |
|
38 | + private $password; |
|
39 | 39 | |
40 | - /** |
|
41 | - * @since 18.0.0 |
|
42 | - */ |
|
43 | - public function __construct(IUser $user, |
|
44 | - string $password) { |
|
45 | - parent::__construct(); |
|
46 | - $this->user = $user; |
|
47 | - $this->password = $password; |
|
48 | - } |
|
40 | + /** |
|
41 | + * @since 18.0.0 |
|
42 | + */ |
|
43 | + public function __construct(IUser $user, |
|
44 | + string $password) { |
|
45 | + parent::__construct(); |
|
46 | + $this->user = $user; |
|
47 | + $this->password = $password; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @since 18.0.0 |
|
52 | - */ |
|
53 | - public function getUser(): IUser { |
|
54 | - return $this->user; |
|
55 | - } |
|
50 | + /** |
|
51 | + * @since 18.0.0 |
|
52 | + */ |
|
53 | + public function getUser(): IUser { |
|
54 | + return $this->user; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @since 18.0.0 |
|
59 | - */ |
|
60 | - public function getUid(): string { |
|
61 | - return $this->user->getUID(); |
|
62 | - } |
|
57 | + /** |
|
58 | + * @since 18.0.0 |
|
59 | + */ |
|
60 | + public function getUid(): string { |
|
61 | + return $this->user->getUID(); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @since 18.0.0 |
|
66 | - */ |
|
67 | - public function getPassword(): string { |
|
68 | - return $this->password; |
|
69 | - } |
|
64 | + /** |
|
65 | + * @since 18.0.0 |
|
66 | + */ |
|
67 | + public function getPassword(): string { |
|
68 | + return $this->password; |
|
69 | + } |
|
70 | 70 | |
71 | 71 | } |
@@ -63,570 +63,570 @@ |
||
63 | 63 | * @package OC\User |
64 | 64 | */ |
65 | 65 | class Manager extends PublicEmitter implements IUserManager { |
66 | - /** |
|
67 | - * @var \OCP\UserInterface[] $backends |
|
68 | - */ |
|
69 | - private $backends = array(); |
|
70 | - |
|
71 | - /** |
|
72 | - * @var \OC\User\User[] $cachedUsers |
|
73 | - */ |
|
74 | - private $cachedUsers = array(); |
|
75 | - |
|
76 | - /** @var IConfig */ |
|
77 | - private $config; |
|
78 | - |
|
79 | - /** @var EventDispatcherInterface */ |
|
80 | - private $dispatcher; |
|
81 | - |
|
82 | - /** @var IEventDispatcher */ |
|
83 | - private $eventDispatcher; |
|
84 | - |
|
85 | - public function __construct(IConfig $config, |
|
86 | - EventDispatcherInterface $oldDispatcher, |
|
87 | - IEventDispatcher $eventDispatcher) { |
|
88 | - $this->config = $config; |
|
89 | - $this->dispatcher = $oldDispatcher; |
|
90 | - $cachedUsers = &$this->cachedUsers; |
|
91 | - $this->listen('\OC\User', 'postDelete', function ($user) use (&$cachedUsers) { |
|
92 | - /** @var \OC\User\User $user */ |
|
93 | - unset($cachedUsers[$user->getUID()]); |
|
94 | - }); |
|
95 | - $this->eventDispatcher = $eventDispatcher; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Get the active backends |
|
100 | - * @return \OCP\UserInterface[] |
|
101 | - */ |
|
102 | - public function getBackends() { |
|
103 | - return $this->backends; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * register a user backend |
|
108 | - * |
|
109 | - * @param \OCP\UserInterface $backend |
|
110 | - */ |
|
111 | - public function registerBackend($backend) { |
|
112 | - $this->backends[] = $backend; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * remove a user backend |
|
117 | - * |
|
118 | - * @param \OCP\UserInterface $backend |
|
119 | - */ |
|
120 | - public function removeBackend($backend) { |
|
121 | - $this->cachedUsers = array(); |
|
122 | - if (($i = array_search($backend, $this->backends)) !== false) { |
|
123 | - unset($this->backends[$i]); |
|
124 | - } |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * remove all user backends |
|
129 | - */ |
|
130 | - public function clearBackends() { |
|
131 | - $this->cachedUsers = array(); |
|
132 | - $this->backends = array(); |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * get a user by user id |
|
137 | - * |
|
138 | - * @param string $uid |
|
139 | - * @return \OC\User\User|null Either the user or null if the specified user does not exist |
|
140 | - */ |
|
141 | - public function get($uid) { |
|
142 | - if (is_null($uid) || $uid === '' || $uid === false) { |
|
143 | - return null; |
|
144 | - } |
|
145 | - if (isset($this->cachedUsers[$uid])) { //check the cache first to prevent having to loop over the backends |
|
146 | - return $this->cachedUsers[$uid]; |
|
147 | - } |
|
148 | - foreach ($this->backends as $backend) { |
|
149 | - if ($backend->userExists($uid)) { |
|
150 | - return $this->getUserObject($uid, $backend); |
|
151 | - } |
|
152 | - } |
|
153 | - return null; |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * get or construct the user object |
|
158 | - * |
|
159 | - * @param string $uid |
|
160 | - * @param \OCP\UserInterface $backend |
|
161 | - * @param bool $cacheUser If false the newly created user object will not be cached |
|
162 | - * @return \OC\User\User |
|
163 | - */ |
|
164 | - protected function getUserObject($uid, $backend, $cacheUser = true) { |
|
165 | - if ($backend instanceof IGetRealUIDBackend) { |
|
166 | - $uid = $backend->getRealUID($uid); |
|
167 | - } |
|
168 | - |
|
169 | - if (isset($this->cachedUsers[$uid])) { |
|
170 | - return $this->cachedUsers[$uid]; |
|
171 | - } |
|
172 | - |
|
173 | - $user = new User($uid, $backend, $this->dispatcher, $this, $this->config); |
|
174 | - if ($cacheUser) { |
|
175 | - $this->cachedUsers[$uid] = $user; |
|
176 | - } |
|
177 | - return $user; |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * check if a user exists |
|
182 | - * |
|
183 | - * @param string $uid |
|
184 | - * @return bool |
|
185 | - */ |
|
186 | - public function userExists($uid) { |
|
187 | - $user = $this->get($uid); |
|
188 | - return ($user !== null); |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Check if the password is valid for the user |
|
193 | - * |
|
194 | - * @param string $loginName |
|
195 | - * @param string $password |
|
196 | - * @return mixed the User object on success, false otherwise |
|
197 | - */ |
|
198 | - public function checkPassword($loginName, $password) { |
|
199 | - $result = $this->checkPasswordNoLogging($loginName, $password); |
|
200 | - |
|
201 | - if ($result === false) { |
|
202 | - \OC::$server->getLogger()->warning('Login failed: \''. $loginName .'\' (Remote IP: \''. \OC::$server->getRequest()->getRemoteAddress(). '\')', ['app' => 'core']); |
|
203 | - } |
|
204 | - |
|
205 | - return $result; |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * Check if the password is valid for the user |
|
210 | - * |
|
211 | - * @internal |
|
212 | - * @param string $loginName |
|
213 | - * @param string $password |
|
214 | - * @return IUser|false the User object on success, false otherwise |
|
215 | - */ |
|
216 | - public function checkPasswordNoLogging($loginName, $password) { |
|
217 | - $loginName = str_replace("\0", '', $loginName); |
|
218 | - $password = str_replace("\0", '', $password); |
|
219 | - |
|
220 | - foreach ($this->backends as $backend) { |
|
221 | - if ($backend->implementsActions(Backend::CHECK_PASSWORD)) { |
|
222 | - $uid = $backend->checkPassword($loginName, $password); |
|
223 | - if ($uid !== false) { |
|
224 | - return $this->getUserObject($uid, $backend); |
|
225 | - } |
|
226 | - } |
|
227 | - } |
|
228 | - |
|
229 | - return false; |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * search by user id |
|
234 | - * |
|
235 | - * @param string $pattern |
|
236 | - * @param int $limit |
|
237 | - * @param int $offset |
|
238 | - * @return \OC\User\User[] |
|
239 | - */ |
|
240 | - public function search($pattern, $limit = null, $offset = null) { |
|
241 | - $users = array(); |
|
242 | - foreach ($this->backends as $backend) { |
|
243 | - $backendUsers = $backend->getUsers($pattern, $limit, $offset); |
|
244 | - if (is_array($backendUsers)) { |
|
245 | - foreach ($backendUsers as $uid) { |
|
246 | - $users[$uid] = $this->getUserObject($uid, $backend); |
|
247 | - } |
|
248 | - } |
|
249 | - } |
|
250 | - |
|
251 | - uasort($users, function ($a, $b) { |
|
252 | - /** |
|
253 | - * @var \OC\User\User $a |
|
254 | - * @var \OC\User\User $b |
|
255 | - */ |
|
256 | - return strcasecmp($a->getUID(), $b->getUID()); |
|
257 | - }); |
|
258 | - return $users; |
|
259 | - } |
|
260 | - |
|
261 | - /** |
|
262 | - * search by displayName |
|
263 | - * |
|
264 | - * @param string $pattern |
|
265 | - * @param int $limit |
|
266 | - * @param int $offset |
|
267 | - * @return \OC\User\User[] |
|
268 | - */ |
|
269 | - public function searchDisplayName($pattern, $limit = null, $offset = null) { |
|
270 | - $users = array(); |
|
271 | - foreach ($this->backends as $backend) { |
|
272 | - $backendUsers = $backend->getDisplayNames($pattern, $limit, $offset); |
|
273 | - if (is_array($backendUsers)) { |
|
274 | - foreach ($backendUsers as $uid => $displayName) { |
|
275 | - $users[] = $this->getUserObject($uid, $backend); |
|
276 | - } |
|
277 | - } |
|
278 | - } |
|
279 | - |
|
280 | - usort($users, function ($a, $b) { |
|
281 | - /** |
|
282 | - * @var \OC\User\User $a |
|
283 | - * @var \OC\User\User $b |
|
284 | - */ |
|
285 | - return strcasecmp($a->getDisplayName(), $b->getDisplayName()); |
|
286 | - }); |
|
287 | - return $users; |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * @param string $uid |
|
292 | - * @param string $password |
|
293 | - * @throws \InvalidArgumentException |
|
294 | - * @return bool|IUser the created user or false |
|
295 | - */ |
|
296 | - public function createUser($uid, $password) { |
|
297 | - if (!$this->verifyUid($uid)) { |
|
298 | - return false; |
|
299 | - } |
|
300 | - |
|
301 | - $localBackends = []; |
|
302 | - foreach ($this->backends as $backend) { |
|
303 | - if ($backend instanceof Database) { |
|
304 | - // First check if there is another user backend |
|
305 | - $localBackends[] = $backend; |
|
306 | - continue; |
|
307 | - } |
|
308 | - |
|
309 | - if ($backend->implementsActions(Backend::CREATE_USER)) { |
|
310 | - return $this->createUserFromBackend($uid, $password, $backend); |
|
311 | - } |
|
312 | - } |
|
313 | - |
|
314 | - foreach ($localBackends as $backend) { |
|
315 | - if ($backend->implementsActions(Backend::CREATE_USER)) { |
|
316 | - return $this->createUserFromBackend($uid, $password, $backend); |
|
317 | - } |
|
318 | - } |
|
319 | - |
|
320 | - return false; |
|
321 | - } |
|
322 | - |
|
323 | - /** |
|
324 | - * @param string $uid |
|
325 | - * @param string $password |
|
326 | - * @param UserInterface $backend |
|
327 | - * @return IUser|null |
|
328 | - * @throws \InvalidArgumentException |
|
329 | - */ |
|
330 | - public function createUserFromBackend($uid, $password, UserInterface $backend) { |
|
331 | - $l = \OC::$server->getL10N('lib'); |
|
332 | - |
|
333 | - // Check the name for bad characters |
|
334 | - // Allowed are: "a-z", "A-Z", "0-9" and "_.@-'" |
|
335 | - if (preg_match('/[^a-zA-Z0-9 _\.@\-\']/', $uid)) { |
|
336 | - throw new \InvalidArgumentException($l->t('Only the following characters are allowed in a username:' |
|
337 | - . ' "a-z", "A-Z", "0-9", and "_.@-\'"')); |
|
338 | - } |
|
339 | - // No empty username |
|
340 | - if (trim($uid) === '') { |
|
341 | - throw new \InvalidArgumentException($l->t('A valid username must be provided')); |
|
342 | - } |
|
343 | - // No whitespace at the beginning or at the end |
|
344 | - if (trim($uid) !== $uid) { |
|
345 | - throw new \InvalidArgumentException($l->t('Username contains whitespace at the beginning or at the end')); |
|
346 | - } |
|
347 | - // Username only consists of 1 or 2 dots (directory traversal) |
|
348 | - if ($uid === '.' || $uid === '..') { |
|
349 | - throw new \InvalidArgumentException($l->t('Username must not consist of dots only')); |
|
350 | - } |
|
351 | - // No empty password |
|
352 | - if (trim($password) === '') { |
|
353 | - throw new \InvalidArgumentException($l->t('A valid password must be provided')); |
|
354 | - } |
|
355 | - |
|
356 | - // Check if user already exists |
|
357 | - if ($this->userExists($uid)) { |
|
358 | - throw new \InvalidArgumentException($l->t('The username is already being used')); |
|
359 | - } |
|
360 | - |
|
361 | - $this->emit('\OC\User', 'preCreateUser', [$uid, $password]); |
|
362 | - $this->eventDispatcher->dispatchTyped(new CreateUserEvent($uid, $password)); |
|
363 | - $state = $backend->createUser($uid, $password); |
|
364 | - if($state === false) { |
|
365 | - throw new \InvalidArgumentException($l->t('Could not create user')); |
|
366 | - } |
|
367 | - $user = $this->getUserObject($uid, $backend); |
|
368 | - if ($user instanceof IUser) { |
|
369 | - $this->emit('\OC\User', 'postCreateUser', [$user, $password]); |
|
370 | - $this->eventDispatcher->dispatchTyped(new UserCreatedEvent($user, $password)); |
|
371 | - } |
|
372 | - return $user; |
|
373 | - } |
|
374 | - |
|
375 | - /** |
|
376 | - * returns how many users per backend exist (if supported by backend) |
|
377 | - * |
|
378 | - * @param boolean $hasLoggedIn when true only users that have a lastLogin |
|
379 | - * entry in the preferences table will be affected |
|
380 | - * @return array|int an array of backend class as key and count number as value |
|
381 | - * if $hasLoggedIn is true only an int is returned |
|
382 | - */ |
|
383 | - public function countUsers($hasLoggedIn = false) { |
|
384 | - if ($hasLoggedIn) { |
|
385 | - return $this->countSeenUsers(); |
|
386 | - } |
|
387 | - $userCountStatistics = []; |
|
388 | - foreach ($this->backends as $backend) { |
|
389 | - if ($backend->implementsActions(Backend::COUNT_USERS)) { |
|
390 | - $backendUsers = $backend->countUsers(); |
|
391 | - if($backendUsers !== false) { |
|
392 | - if($backend instanceof IUserBackend) { |
|
393 | - $name = $backend->getBackendName(); |
|
394 | - } else { |
|
395 | - $name = get_class($backend); |
|
396 | - } |
|
397 | - if(isset($userCountStatistics[$name])) { |
|
398 | - $userCountStatistics[$name] += $backendUsers; |
|
399 | - } else { |
|
400 | - $userCountStatistics[$name] = $backendUsers; |
|
401 | - } |
|
402 | - } |
|
403 | - } |
|
404 | - } |
|
405 | - return $userCountStatistics; |
|
406 | - } |
|
407 | - |
|
408 | - /** |
|
409 | - * returns how many users per backend exist in the requested groups (if supported by backend) |
|
410 | - * |
|
411 | - * @param IGroup[] $groups an array of gid to search in |
|
412 | - * @return array|int an array of backend class as key and count number as value |
|
413 | - * if $hasLoggedIn is true only an int is returned |
|
414 | - */ |
|
415 | - public function countUsersOfGroups(array $groups) { |
|
416 | - $users = []; |
|
417 | - foreach($groups as $group) { |
|
418 | - $usersIds = array_map(function($user) { |
|
419 | - return $user->getUID(); |
|
420 | - }, $group->getUsers()); |
|
421 | - $users = array_merge($users, $usersIds); |
|
422 | - } |
|
423 | - return count(array_unique($users)); |
|
424 | - } |
|
425 | - |
|
426 | - /** |
|
427 | - * The callback is executed for each user on each backend. |
|
428 | - * If the callback returns false no further users will be retrieved. |
|
429 | - * |
|
430 | - * @param \Closure $callback |
|
431 | - * @param string $search |
|
432 | - * @param boolean $onlySeen when true only users that have a lastLogin entry |
|
433 | - * in the preferences table will be affected |
|
434 | - * @since 9.0.0 |
|
435 | - */ |
|
436 | - public function callForAllUsers(\Closure $callback, $search = '', $onlySeen = false) { |
|
437 | - if ($onlySeen) { |
|
438 | - $this->callForSeenUsers($callback); |
|
439 | - } else { |
|
440 | - foreach ($this->getBackends() as $backend) { |
|
441 | - $limit = 500; |
|
442 | - $offset = 0; |
|
443 | - do { |
|
444 | - $users = $backend->getUsers($search, $limit, $offset); |
|
445 | - foreach ($users as $uid) { |
|
446 | - if (!$backend->userExists($uid)) { |
|
447 | - continue; |
|
448 | - } |
|
449 | - $user = $this->getUserObject($uid, $backend, false); |
|
450 | - $return = $callback($user); |
|
451 | - if ($return === false) { |
|
452 | - break; |
|
453 | - } |
|
454 | - } |
|
455 | - $offset += $limit; |
|
456 | - } while (count($users) >= $limit); |
|
457 | - } |
|
458 | - } |
|
459 | - } |
|
460 | - |
|
461 | - /** |
|
462 | - * returns how many users are disabled |
|
463 | - * |
|
464 | - * @return int |
|
465 | - * @since 12.0.0 |
|
466 | - */ |
|
467 | - public function countDisabledUsers(): int { |
|
468 | - $queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
469 | - $queryBuilder->select($queryBuilder->func()->count('*')) |
|
470 | - ->from('preferences') |
|
471 | - ->where($queryBuilder->expr()->eq('appid', $queryBuilder->createNamedParameter('core'))) |
|
472 | - ->andWhere($queryBuilder->expr()->eq('configkey', $queryBuilder->createNamedParameter('enabled'))) |
|
473 | - ->andWhere($queryBuilder->expr()->eq('configvalue', $queryBuilder->createNamedParameter('false'), IQueryBuilder::PARAM_STR)); |
|
474 | - |
|
475 | - |
|
476 | - $result = $queryBuilder->execute(); |
|
477 | - $count = $result->fetchColumn(); |
|
478 | - $result->closeCursor(); |
|
479 | - |
|
480 | - if ($count !== false) { |
|
481 | - $count = (int)$count; |
|
482 | - } else { |
|
483 | - $count = 0; |
|
484 | - } |
|
485 | - |
|
486 | - return $count; |
|
487 | - } |
|
488 | - |
|
489 | - /** |
|
490 | - * returns how many users are disabled in the requested groups |
|
491 | - * |
|
492 | - * @param array $groups groupids to search |
|
493 | - * @return int |
|
494 | - * @since 14.0.0 |
|
495 | - */ |
|
496 | - public function countDisabledUsersOfGroups(array $groups): int { |
|
497 | - $queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
498 | - $queryBuilder->select($queryBuilder->createFunction('COUNT(DISTINCT ' . $queryBuilder->getColumnName('uid') . ')')) |
|
499 | - ->from('preferences', 'p') |
|
500 | - ->innerJoin('p', 'group_user', 'g', $queryBuilder->expr()->eq('p.userid', 'g.uid')) |
|
501 | - ->where($queryBuilder->expr()->eq('appid', $queryBuilder->createNamedParameter('core'))) |
|
502 | - ->andWhere($queryBuilder->expr()->eq('configkey', $queryBuilder->createNamedParameter('enabled'))) |
|
503 | - ->andWhere($queryBuilder->expr()->eq('configvalue', $queryBuilder->createNamedParameter('false'), IQueryBuilder::PARAM_STR)) |
|
504 | - ->andWhere($queryBuilder->expr()->in('gid', $queryBuilder->createNamedParameter($groups, IQueryBuilder::PARAM_STR_ARRAY))); |
|
505 | - |
|
506 | - $result = $queryBuilder->execute(); |
|
507 | - $count = $result->fetchColumn(); |
|
508 | - $result->closeCursor(); |
|
509 | - |
|
510 | - if ($count !== false) { |
|
511 | - $count = (int)$count; |
|
512 | - } else { |
|
513 | - $count = 0; |
|
514 | - } |
|
515 | - |
|
516 | - return $count; |
|
517 | - } |
|
518 | - |
|
519 | - /** |
|
520 | - * returns how many users have logged in once |
|
521 | - * |
|
522 | - * @return int |
|
523 | - * @since 11.0.0 |
|
524 | - */ |
|
525 | - public function countSeenUsers() { |
|
526 | - $queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
527 | - $queryBuilder->select($queryBuilder->func()->count('*')) |
|
528 | - ->from('preferences') |
|
529 | - ->where($queryBuilder->expr()->eq('appid', $queryBuilder->createNamedParameter('login'))) |
|
530 | - ->andWhere($queryBuilder->expr()->eq('configkey', $queryBuilder->createNamedParameter('lastLogin'))) |
|
531 | - ->andWhere($queryBuilder->expr()->isNotNull('configvalue')); |
|
532 | - |
|
533 | - $query = $queryBuilder->execute(); |
|
534 | - |
|
535 | - $result = (int)$query->fetchColumn(); |
|
536 | - $query->closeCursor(); |
|
537 | - |
|
538 | - return $result; |
|
539 | - } |
|
540 | - |
|
541 | - /** |
|
542 | - * @param \Closure $callback |
|
543 | - * @since 11.0.0 |
|
544 | - */ |
|
545 | - public function callForSeenUsers(\Closure $callback) { |
|
546 | - $limit = 1000; |
|
547 | - $offset = 0; |
|
548 | - do { |
|
549 | - $userIds = $this->getSeenUserIds($limit, $offset); |
|
550 | - $offset += $limit; |
|
551 | - foreach ($userIds as $userId) { |
|
552 | - foreach ($this->backends as $backend) { |
|
553 | - if ($backend->userExists($userId)) { |
|
554 | - $user = $this->getUserObject($userId, $backend, false); |
|
555 | - $return = $callback($user); |
|
556 | - if ($return === false) { |
|
557 | - return; |
|
558 | - } |
|
559 | - break; |
|
560 | - } |
|
561 | - } |
|
562 | - } |
|
563 | - } while (count($userIds) >= $limit); |
|
564 | - } |
|
565 | - |
|
566 | - /** |
|
567 | - * Getting all userIds that have a listLogin value requires checking the |
|
568 | - * value in php because on oracle you cannot use a clob in a where clause, |
|
569 | - * preventing us from doing a not null or length(value) > 0 check. |
|
570 | - * |
|
571 | - * @param int $limit |
|
572 | - * @param int $offset |
|
573 | - * @return string[] with user ids |
|
574 | - */ |
|
575 | - private function getSeenUserIds($limit = null, $offset = null) { |
|
576 | - $queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
577 | - $queryBuilder->select(['userid']) |
|
578 | - ->from('preferences') |
|
579 | - ->where($queryBuilder->expr()->eq( |
|
580 | - 'appid', $queryBuilder->createNamedParameter('login')) |
|
581 | - ) |
|
582 | - ->andWhere($queryBuilder->expr()->eq( |
|
583 | - 'configkey', $queryBuilder->createNamedParameter('lastLogin')) |
|
584 | - ) |
|
585 | - ->andWhere($queryBuilder->expr()->isNotNull('configvalue') |
|
586 | - ); |
|
587 | - |
|
588 | - if ($limit !== null) { |
|
589 | - $queryBuilder->setMaxResults($limit); |
|
590 | - } |
|
591 | - if ($offset !== null) { |
|
592 | - $queryBuilder->setFirstResult($offset); |
|
593 | - } |
|
594 | - $query = $queryBuilder->execute(); |
|
595 | - $result = []; |
|
596 | - |
|
597 | - while ($row = $query->fetch()) { |
|
598 | - $result[] = $row['userid']; |
|
599 | - } |
|
600 | - |
|
601 | - $query->closeCursor(); |
|
602 | - |
|
603 | - return $result; |
|
604 | - } |
|
605 | - |
|
606 | - /** |
|
607 | - * @param string $email |
|
608 | - * @return IUser[] |
|
609 | - * @since 9.1.0 |
|
610 | - */ |
|
611 | - public function getByEmail($email) { |
|
612 | - $userIds = $this->config->getUsersForUserValueCaseInsensitive('settings', 'email', $email); |
|
613 | - |
|
614 | - $users = array_map(function($uid) { |
|
615 | - return $this->get($uid); |
|
616 | - }, $userIds); |
|
617 | - |
|
618 | - return array_values(array_filter($users, function($u) { |
|
619 | - return ($u instanceof IUser); |
|
620 | - })); |
|
621 | - } |
|
622 | - |
|
623 | - private function verifyUid(string $uid): bool { |
|
624 | - $appdata = 'appdata_' . $this->config->getSystemValueString('instanceid'); |
|
625 | - |
|
626 | - if ($uid === '.htaccess' || $uid === 'files_external' || $uid === '.ocdata' || $uid === 'owncloud.log' || $uid === 'nextcloud.log' || $uid === $appdata) { |
|
627 | - return false; |
|
628 | - } |
|
629 | - |
|
630 | - return true; |
|
631 | - } |
|
66 | + /** |
|
67 | + * @var \OCP\UserInterface[] $backends |
|
68 | + */ |
|
69 | + private $backends = array(); |
|
70 | + |
|
71 | + /** |
|
72 | + * @var \OC\User\User[] $cachedUsers |
|
73 | + */ |
|
74 | + private $cachedUsers = array(); |
|
75 | + |
|
76 | + /** @var IConfig */ |
|
77 | + private $config; |
|
78 | + |
|
79 | + /** @var EventDispatcherInterface */ |
|
80 | + private $dispatcher; |
|
81 | + |
|
82 | + /** @var IEventDispatcher */ |
|
83 | + private $eventDispatcher; |
|
84 | + |
|
85 | + public function __construct(IConfig $config, |
|
86 | + EventDispatcherInterface $oldDispatcher, |
|
87 | + IEventDispatcher $eventDispatcher) { |
|
88 | + $this->config = $config; |
|
89 | + $this->dispatcher = $oldDispatcher; |
|
90 | + $cachedUsers = &$this->cachedUsers; |
|
91 | + $this->listen('\OC\User', 'postDelete', function ($user) use (&$cachedUsers) { |
|
92 | + /** @var \OC\User\User $user */ |
|
93 | + unset($cachedUsers[$user->getUID()]); |
|
94 | + }); |
|
95 | + $this->eventDispatcher = $eventDispatcher; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Get the active backends |
|
100 | + * @return \OCP\UserInterface[] |
|
101 | + */ |
|
102 | + public function getBackends() { |
|
103 | + return $this->backends; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * register a user backend |
|
108 | + * |
|
109 | + * @param \OCP\UserInterface $backend |
|
110 | + */ |
|
111 | + public function registerBackend($backend) { |
|
112 | + $this->backends[] = $backend; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * remove a user backend |
|
117 | + * |
|
118 | + * @param \OCP\UserInterface $backend |
|
119 | + */ |
|
120 | + public function removeBackend($backend) { |
|
121 | + $this->cachedUsers = array(); |
|
122 | + if (($i = array_search($backend, $this->backends)) !== false) { |
|
123 | + unset($this->backends[$i]); |
|
124 | + } |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * remove all user backends |
|
129 | + */ |
|
130 | + public function clearBackends() { |
|
131 | + $this->cachedUsers = array(); |
|
132 | + $this->backends = array(); |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * get a user by user id |
|
137 | + * |
|
138 | + * @param string $uid |
|
139 | + * @return \OC\User\User|null Either the user or null if the specified user does not exist |
|
140 | + */ |
|
141 | + public function get($uid) { |
|
142 | + if (is_null($uid) || $uid === '' || $uid === false) { |
|
143 | + return null; |
|
144 | + } |
|
145 | + if (isset($this->cachedUsers[$uid])) { //check the cache first to prevent having to loop over the backends |
|
146 | + return $this->cachedUsers[$uid]; |
|
147 | + } |
|
148 | + foreach ($this->backends as $backend) { |
|
149 | + if ($backend->userExists($uid)) { |
|
150 | + return $this->getUserObject($uid, $backend); |
|
151 | + } |
|
152 | + } |
|
153 | + return null; |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * get or construct the user object |
|
158 | + * |
|
159 | + * @param string $uid |
|
160 | + * @param \OCP\UserInterface $backend |
|
161 | + * @param bool $cacheUser If false the newly created user object will not be cached |
|
162 | + * @return \OC\User\User |
|
163 | + */ |
|
164 | + protected function getUserObject($uid, $backend, $cacheUser = true) { |
|
165 | + if ($backend instanceof IGetRealUIDBackend) { |
|
166 | + $uid = $backend->getRealUID($uid); |
|
167 | + } |
|
168 | + |
|
169 | + if (isset($this->cachedUsers[$uid])) { |
|
170 | + return $this->cachedUsers[$uid]; |
|
171 | + } |
|
172 | + |
|
173 | + $user = new User($uid, $backend, $this->dispatcher, $this, $this->config); |
|
174 | + if ($cacheUser) { |
|
175 | + $this->cachedUsers[$uid] = $user; |
|
176 | + } |
|
177 | + return $user; |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * check if a user exists |
|
182 | + * |
|
183 | + * @param string $uid |
|
184 | + * @return bool |
|
185 | + */ |
|
186 | + public function userExists($uid) { |
|
187 | + $user = $this->get($uid); |
|
188 | + return ($user !== null); |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Check if the password is valid for the user |
|
193 | + * |
|
194 | + * @param string $loginName |
|
195 | + * @param string $password |
|
196 | + * @return mixed the User object on success, false otherwise |
|
197 | + */ |
|
198 | + public function checkPassword($loginName, $password) { |
|
199 | + $result = $this->checkPasswordNoLogging($loginName, $password); |
|
200 | + |
|
201 | + if ($result === false) { |
|
202 | + \OC::$server->getLogger()->warning('Login failed: \''. $loginName .'\' (Remote IP: \''. \OC::$server->getRequest()->getRemoteAddress(). '\')', ['app' => 'core']); |
|
203 | + } |
|
204 | + |
|
205 | + return $result; |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * Check if the password is valid for the user |
|
210 | + * |
|
211 | + * @internal |
|
212 | + * @param string $loginName |
|
213 | + * @param string $password |
|
214 | + * @return IUser|false the User object on success, false otherwise |
|
215 | + */ |
|
216 | + public function checkPasswordNoLogging($loginName, $password) { |
|
217 | + $loginName = str_replace("\0", '', $loginName); |
|
218 | + $password = str_replace("\0", '', $password); |
|
219 | + |
|
220 | + foreach ($this->backends as $backend) { |
|
221 | + if ($backend->implementsActions(Backend::CHECK_PASSWORD)) { |
|
222 | + $uid = $backend->checkPassword($loginName, $password); |
|
223 | + if ($uid !== false) { |
|
224 | + return $this->getUserObject($uid, $backend); |
|
225 | + } |
|
226 | + } |
|
227 | + } |
|
228 | + |
|
229 | + return false; |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * search by user id |
|
234 | + * |
|
235 | + * @param string $pattern |
|
236 | + * @param int $limit |
|
237 | + * @param int $offset |
|
238 | + * @return \OC\User\User[] |
|
239 | + */ |
|
240 | + public function search($pattern, $limit = null, $offset = null) { |
|
241 | + $users = array(); |
|
242 | + foreach ($this->backends as $backend) { |
|
243 | + $backendUsers = $backend->getUsers($pattern, $limit, $offset); |
|
244 | + if (is_array($backendUsers)) { |
|
245 | + foreach ($backendUsers as $uid) { |
|
246 | + $users[$uid] = $this->getUserObject($uid, $backend); |
|
247 | + } |
|
248 | + } |
|
249 | + } |
|
250 | + |
|
251 | + uasort($users, function ($a, $b) { |
|
252 | + /** |
|
253 | + * @var \OC\User\User $a |
|
254 | + * @var \OC\User\User $b |
|
255 | + */ |
|
256 | + return strcasecmp($a->getUID(), $b->getUID()); |
|
257 | + }); |
|
258 | + return $users; |
|
259 | + } |
|
260 | + |
|
261 | + /** |
|
262 | + * search by displayName |
|
263 | + * |
|
264 | + * @param string $pattern |
|
265 | + * @param int $limit |
|
266 | + * @param int $offset |
|
267 | + * @return \OC\User\User[] |
|
268 | + */ |
|
269 | + public function searchDisplayName($pattern, $limit = null, $offset = null) { |
|
270 | + $users = array(); |
|
271 | + foreach ($this->backends as $backend) { |
|
272 | + $backendUsers = $backend->getDisplayNames($pattern, $limit, $offset); |
|
273 | + if (is_array($backendUsers)) { |
|
274 | + foreach ($backendUsers as $uid => $displayName) { |
|
275 | + $users[] = $this->getUserObject($uid, $backend); |
|
276 | + } |
|
277 | + } |
|
278 | + } |
|
279 | + |
|
280 | + usort($users, function ($a, $b) { |
|
281 | + /** |
|
282 | + * @var \OC\User\User $a |
|
283 | + * @var \OC\User\User $b |
|
284 | + */ |
|
285 | + return strcasecmp($a->getDisplayName(), $b->getDisplayName()); |
|
286 | + }); |
|
287 | + return $users; |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * @param string $uid |
|
292 | + * @param string $password |
|
293 | + * @throws \InvalidArgumentException |
|
294 | + * @return bool|IUser the created user or false |
|
295 | + */ |
|
296 | + public function createUser($uid, $password) { |
|
297 | + if (!$this->verifyUid($uid)) { |
|
298 | + return false; |
|
299 | + } |
|
300 | + |
|
301 | + $localBackends = []; |
|
302 | + foreach ($this->backends as $backend) { |
|
303 | + if ($backend instanceof Database) { |
|
304 | + // First check if there is another user backend |
|
305 | + $localBackends[] = $backend; |
|
306 | + continue; |
|
307 | + } |
|
308 | + |
|
309 | + if ($backend->implementsActions(Backend::CREATE_USER)) { |
|
310 | + return $this->createUserFromBackend($uid, $password, $backend); |
|
311 | + } |
|
312 | + } |
|
313 | + |
|
314 | + foreach ($localBackends as $backend) { |
|
315 | + if ($backend->implementsActions(Backend::CREATE_USER)) { |
|
316 | + return $this->createUserFromBackend($uid, $password, $backend); |
|
317 | + } |
|
318 | + } |
|
319 | + |
|
320 | + return false; |
|
321 | + } |
|
322 | + |
|
323 | + /** |
|
324 | + * @param string $uid |
|
325 | + * @param string $password |
|
326 | + * @param UserInterface $backend |
|
327 | + * @return IUser|null |
|
328 | + * @throws \InvalidArgumentException |
|
329 | + */ |
|
330 | + public function createUserFromBackend($uid, $password, UserInterface $backend) { |
|
331 | + $l = \OC::$server->getL10N('lib'); |
|
332 | + |
|
333 | + // Check the name for bad characters |
|
334 | + // Allowed are: "a-z", "A-Z", "0-9" and "_.@-'" |
|
335 | + if (preg_match('/[^a-zA-Z0-9 _\.@\-\']/', $uid)) { |
|
336 | + throw new \InvalidArgumentException($l->t('Only the following characters are allowed in a username:' |
|
337 | + . ' "a-z", "A-Z", "0-9", and "_.@-\'"')); |
|
338 | + } |
|
339 | + // No empty username |
|
340 | + if (trim($uid) === '') { |
|
341 | + throw new \InvalidArgumentException($l->t('A valid username must be provided')); |
|
342 | + } |
|
343 | + // No whitespace at the beginning or at the end |
|
344 | + if (trim($uid) !== $uid) { |
|
345 | + throw new \InvalidArgumentException($l->t('Username contains whitespace at the beginning or at the end')); |
|
346 | + } |
|
347 | + // Username only consists of 1 or 2 dots (directory traversal) |
|
348 | + if ($uid === '.' || $uid === '..') { |
|
349 | + throw new \InvalidArgumentException($l->t('Username must not consist of dots only')); |
|
350 | + } |
|
351 | + // No empty password |
|
352 | + if (trim($password) === '') { |
|
353 | + throw new \InvalidArgumentException($l->t('A valid password must be provided')); |
|
354 | + } |
|
355 | + |
|
356 | + // Check if user already exists |
|
357 | + if ($this->userExists($uid)) { |
|
358 | + throw new \InvalidArgumentException($l->t('The username is already being used')); |
|
359 | + } |
|
360 | + |
|
361 | + $this->emit('\OC\User', 'preCreateUser', [$uid, $password]); |
|
362 | + $this->eventDispatcher->dispatchTyped(new CreateUserEvent($uid, $password)); |
|
363 | + $state = $backend->createUser($uid, $password); |
|
364 | + if($state === false) { |
|
365 | + throw new \InvalidArgumentException($l->t('Could not create user')); |
|
366 | + } |
|
367 | + $user = $this->getUserObject($uid, $backend); |
|
368 | + if ($user instanceof IUser) { |
|
369 | + $this->emit('\OC\User', 'postCreateUser', [$user, $password]); |
|
370 | + $this->eventDispatcher->dispatchTyped(new UserCreatedEvent($user, $password)); |
|
371 | + } |
|
372 | + return $user; |
|
373 | + } |
|
374 | + |
|
375 | + /** |
|
376 | + * returns how many users per backend exist (if supported by backend) |
|
377 | + * |
|
378 | + * @param boolean $hasLoggedIn when true only users that have a lastLogin |
|
379 | + * entry in the preferences table will be affected |
|
380 | + * @return array|int an array of backend class as key and count number as value |
|
381 | + * if $hasLoggedIn is true only an int is returned |
|
382 | + */ |
|
383 | + public function countUsers($hasLoggedIn = false) { |
|
384 | + if ($hasLoggedIn) { |
|
385 | + return $this->countSeenUsers(); |
|
386 | + } |
|
387 | + $userCountStatistics = []; |
|
388 | + foreach ($this->backends as $backend) { |
|
389 | + if ($backend->implementsActions(Backend::COUNT_USERS)) { |
|
390 | + $backendUsers = $backend->countUsers(); |
|
391 | + if($backendUsers !== false) { |
|
392 | + if($backend instanceof IUserBackend) { |
|
393 | + $name = $backend->getBackendName(); |
|
394 | + } else { |
|
395 | + $name = get_class($backend); |
|
396 | + } |
|
397 | + if(isset($userCountStatistics[$name])) { |
|
398 | + $userCountStatistics[$name] += $backendUsers; |
|
399 | + } else { |
|
400 | + $userCountStatistics[$name] = $backendUsers; |
|
401 | + } |
|
402 | + } |
|
403 | + } |
|
404 | + } |
|
405 | + return $userCountStatistics; |
|
406 | + } |
|
407 | + |
|
408 | + /** |
|
409 | + * returns how many users per backend exist in the requested groups (if supported by backend) |
|
410 | + * |
|
411 | + * @param IGroup[] $groups an array of gid to search in |
|
412 | + * @return array|int an array of backend class as key and count number as value |
|
413 | + * if $hasLoggedIn is true only an int is returned |
|
414 | + */ |
|
415 | + public function countUsersOfGroups(array $groups) { |
|
416 | + $users = []; |
|
417 | + foreach($groups as $group) { |
|
418 | + $usersIds = array_map(function($user) { |
|
419 | + return $user->getUID(); |
|
420 | + }, $group->getUsers()); |
|
421 | + $users = array_merge($users, $usersIds); |
|
422 | + } |
|
423 | + return count(array_unique($users)); |
|
424 | + } |
|
425 | + |
|
426 | + /** |
|
427 | + * The callback is executed for each user on each backend. |
|
428 | + * If the callback returns false no further users will be retrieved. |
|
429 | + * |
|
430 | + * @param \Closure $callback |
|
431 | + * @param string $search |
|
432 | + * @param boolean $onlySeen when true only users that have a lastLogin entry |
|
433 | + * in the preferences table will be affected |
|
434 | + * @since 9.0.0 |
|
435 | + */ |
|
436 | + public function callForAllUsers(\Closure $callback, $search = '', $onlySeen = false) { |
|
437 | + if ($onlySeen) { |
|
438 | + $this->callForSeenUsers($callback); |
|
439 | + } else { |
|
440 | + foreach ($this->getBackends() as $backend) { |
|
441 | + $limit = 500; |
|
442 | + $offset = 0; |
|
443 | + do { |
|
444 | + $users = $backend->getUsers($search, $limit, $offset); |
|
445 | + foreach ($users as $uid) { |
|
446 | + if (!$backend->userExists($uid)) { |
|
447 | + continue; |
|
448 | + } |
|
449 | + $user = $this->getUserObject($uid, $backend, false); |
|
450 | + $return = $callback($user); |
|
451 | + if ($return === false) { |
|
452 | + break; |
|
453 | + } |
|
454 | + } |
|
455 | + $offset += $limit; |
|
456 | + } while (count($users) >= $limit); |
|
457 | + } |
|
458 | + } |
|
459 | + } |
|
460 | + |
|
461 | + /** |
|
462 | + * returns how many users are disabled |
|
463 | + * |
|
464 | + * @return int |
|
465 | + * @since 12.0.0 |
|
466 | + */ |
|
467 | + public function countDisabledUsers(): int { |
|
468 | + $queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
469 | + $queryBuilder->select($queryBuilder->func()->count('*')) |
|
470 | + ->from('preferences') |
|
471 | + ->where($queryBuilder->expr()->eq('appid', $queryBuilder->createNamedParameter('core'))) |
|
472 | + ->andWhere($queryBuilder->expr()->eq('configkey', $queryBuilder->createNamedParameter('enabled'))) |
|
473 | + ->andWhere($queryBuilder->expr()->eq('configvalue', $queryBuilder->createNamedParameter('false'), IQueryBuilder::PARAM_STR)); |
|
474 | + |
|
475 | + |
|
476 | + $result = $queryBuilder->execute(); |
|
477 | + $count = $result->fetchColumn(); |
|
478 | + $result->closeCursor(); |
|
479 | + |
|
480 | + if ($count !== false) { |
|
481 | + $count = (int)$count; |
|
482 | + } else { |
|
483 | + $count = 0; |
|
484 | + } |
|
485 | + |
|
486 | + return $count; |
|
487 | + } |
|
488 | + |
|
489 | + /** |
|
490 | + * returns how many users are disabled in the requested groups |
|
491 | + * |
|
492 | + * @param array $groups groupids to search |
|
493 | + * @return int |
|
494 | + * @since 14.0.0 |
|
495 | + */ |
|
496 | + public function countDisabledUsersOfGroups(array $groups): int { |
|
497 | + $queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
498 | + $queryBuilder->select($queryBuilder->createFunction('COUNT(DISTINCT ' . $queryBuilder->getColumnName('uid') . ')')) |
|
499 | + ->from('preferences', 'p') |
|
500 | + ->innerJoin('p', 'group_user', 'g', $queryBuilder->expr()->eq('p.userid', 'g.uid')) |
|
501 | + ->where($queryBuilder->expr()->eq('appid', $queryBuilder->createNamedParameter('core'))) |
|
502 | + ->andWhere($queryBuilder->expr()->eq('configkey', $queryBuilder->createNamedParameter('enabled'))) |
|
503 | + ->andWhere($queryBuilder->expr()->eq('configvalue', $queryBuilder->createNamedParameter('false'), IQueryBuilder::PARAM_STR)) |
|
504 | + ->andWhere($queryBuilder->expr()->in('gid', $queryBuilder->createNamedParameter($groups, IQueryBuilder::PARAM_STR_ARRAY))); |
|
505 | + |
|
506 | + $result = $queryBuilder->execute(); |
|
507 | + $count = $result->fetchColumn(); |
|
508 | + $result->closeCursor(); |
|
509 | + |
|
510 | + if ($count !== false) { |
|
511 | + $count = (int)$count; |
|
512 | + } else { |
|
513 | + $count = 0; |
|
514 | + } |
|
515 | + |
|
516 | + return $count; |
|
517 | + } |
|
518 | + |
|
519 | + /** |
|
520 | + * returns how many users have logged in once |
|
521 | + * |
|
522 | + * @return int |
|
523 | + * @since 11.0.0 |
|
524 | + */ |
|
525 | + public function countSeenUsers() { |
|
526 | + $queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
527 | + $queryBuilder->select($queryBuilder->func()->count('*')) |
|
528 | + ->from('preferences') |
|
529 | + ->where($queryBuilder->expr()->eq('appid', $queryBuilder->createNamedParameter('login'))) |
|
530 | + ->andWhere($queryBuilder->expr()->eq('configkey', $queryBuilder->createNamedParameter('lastLogin'))) |
|
531 | + ->andWhere($queryBuilder->expr()->isNotNull('configvalue')); |
|
532 | + |
|
533 | + $query = $queryBuilder->execute(); |
|
534 | + |
|
535 | + $result = (int)$query->fetchColumn(); |
|
536 | + $query->closeCursor(); |
|
537 | + |
|
538 | + return $result; |
|
539 | + } |
|
540 | + |
|
541 | + /** |
|
542 | + * @param \Closure $callback |
|
543 | + * @since 11.0.0 |
|
544 | + */ |
|
545 | + public function callForSeenUsers(\Closure $callback) { |
|
546 | + $limit = 1000; |
|
547 | + $offset = 0; |
|
548 | + do { |
|
549 | + $userIds = $this->getSeenUserIds($limit, $offset); |
|
550 | + $offset += $limit; |
|
551 | + foreach ($userIds as $userId) { |
|
552 | + foreach ($this->backends as $backend) { |
|
553 | + if ($backend->userExists($userId)) { |
|
554 | + $user = $this->getUserObject($userId, $backend, false); |
|
555 | + $return = $callback($user); |
|
556 | + if ($return === false) { |
|
557 | + return; |
|
558 | + } |
|
559 | + break; |
|
560 | + } |
|
561 | + } |
|
562 | + } |
|
563 | + } while (count($userIds) >= $limit); |
|
564 | + } |
|
565 | + |
|
566 | + /** |
|
567 | + * Getting all userIds that have a listLogin value requires checking the |
|
568 | + * value in php because on oracle you cannot use a clob in a where clause, |
|
569 | + * preventing us from doing a not null or length(value) > 0 check. |
|
570 | + * |
|
571 | + * @param int $limit |
|
572 | + * @param int $offset |
|
573 | + * @return string[] with user ids |
|
574 | + */ |
|
575 | + private function getSeenUserIds($limit = null, $offset = null) { |
|
576 | + $queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
577 | + $queryBuilder->select(['userid']) |
|
578 | + ->from('preferences') |
|
579 | + ->where($queryBuilder->expr()->eq( |
|
580 | + 'appid', $queryBuilder->createNamedParameter('login')) |
|
581 | + ) |
|
582 | + ->andWhere($queryBuilder->expr()->eq( |
|
583 | + 'configkey', $queryBuilder->createNamedParameter('lastLogin')) |
|
584 | + ) |
|
585 | + ->andWhere($queryBuilder->expr()->isNotNull('configvalue') |
|
586 | + ); |
|
587 | + |
|
588 | + if ($limit !== null) { |
|
589 | + $queryBuilder->setMaxResults($limit); |
|
590 | + } |
|
591 | + if ($offset !== null) { |
|
592 | + $queryBuilder->setFirstResult($offset); |
|
593 | + } |
|
594 | + $query = $queryBuilder->execute(); |
|
595 | + $result = []; |
|
596 | + |
|
597 | + while ($row = $query->fetch()) { |
|
598 | + $result[] = $row['userid']; |
|
599 | + } |
|
600 | + |
|
601 | + $query->closeCursor(); |
|
602 | + |
|
603 | + return $result; |
|
604 | + } |
|
605 | + |
|
606 | + /** |
|
607 | + * @param string $email |
|
608 | + * @return IUser[] |
|
609 | + * @since 9.1.0 |
|
610 | + */ |
|
611 | + public function getByEmail($email) { |
|
612 | + $userIds = $this->config->getUsersForUserValueCaseInsensitive('settings', 'email', $email); |
|
613 | + |
|
614 | + $users = array_map(function($uid) { |
|
615 | + return $this->get($uid); |
|
616 | + }, $userIds); |
|
617 | + |
|
618 | + return array_values(array_filter($users, function($u) { |
|
619 | + return ($u instanceof IUser); |
|
620 | + })); |
|
621 | + } |
|
622 | + |
|
623 | + private function verifyUid(string $uid): bool { |
|
624 | + $appdata = 'appdata_' . $this->config->getSystemValueString('instanceid'); |
|
625 | + |
|
626 | + if ($uid === '.htaccess' || $uid === 'files_external' || $uid === '.ocdata' || $uid === 'owncloud.log' || $uid === 'nextcloud.log' || $uid === $appdata) { |
|
627 | + return false; |
|
628 | + } |
|
629 | + |
|
630 | + return true; |
|
631 | + } |
|
632 | 632 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | $this->config = $config; |
89 | 89 | $this->dispatcher = $oldDispatcher; |
90 | 90 | $cachedUsers = &$this->cachedUsers; |
91 | - $this->listen('\OC\User', 'postDelete', function ($user) use (&$cachedUsers) { |
|
91 | + $this->listen('\OC\User', 'postDelete', function($user) use (&$cachedUsers) { |
|
92 | 92 | /** @var \OC\User\User $user */ |
93 | 93 | unset($cachedUsers[$user->getUID()]); |
94 | 94 | }); |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | $result = $this->checkPasswordNoLogging($loginName, $password); |
200 | 200 | |
201 | 201 | if ($result === false) { |
202 | - \OC::$server->getLogger()->warning('Login failed: \''. $loginName .'\' (Remote IP: \''. \OC::$server->getRequest()->getRemoteAddress(). '\')', ['app' => 'core']); |
|
202 | + \OC::$server->getLogger()->warning('Login failed: \''.$loginName.'\' (Remote IP: \''.\OC::$server->getRequest()->getRemoteAddress().'\')', ['app' => 'core']); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | return $result; |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | } |
249 | 249 | } |
250 | 250 | |
251 | - uasort($users, function ($a, $b) { |
|
251 | + uasort($users, function($a, $b) { |
|
252 | 252 | /** |
253 | 253 | * @var \OC\User\User $a |
254 | 254 | * @var \OC\User\User $b |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | } |
278 | 278 | } |
279 | 279 | |
280 | - usort($users, function ($a, $b) { |
|
280 | + usort($users, function($a, $b) { |
|
281 | 281 | /** |
282 | 282 | * @var \OC\User\User $a |
283 | 283 | * @var \OC\User\User $b |
@@ -361,7 +361,7 @@ discard block |
||
361 | 361 | $this->emit('\OC\User', 'preCreateUser', [$uid, $password]); |
362 | 362 | $this->eventDispatcher->dispatchTyped(new CreateUserEvent($uid, $password)); |
363 | 363 | $state = $backend->createUser($uid, $password); |
364 | - if($state === false) { |
|
364 | + if ($state === false) { |
|
365 | 365 | throw new \InvalidArgumentException($l->t('Could not create user')); |
366 | 366 | } |
367 | 367 | $user = $this->getUserObject($uid, $backend); |
@@ -388,13 +388,13 @@ discard block |
||
388 | 388 | foreach ($this->backends as $backend) { |
389 | 389 | if ($backend->implementsActions(Backend::COUNT_USERS)) { |
390 | 390 | $backendUsers = $backend->countUsers(); |
391 | - if($backendUsers !== false) { |
|
392 | - if($backend instanceof IUserBackend) { |
|
391 | + if ($backendUsers !== false) { |
|
392 | + if ($backend instanceof IUserBackend) { |
|
393 | 393 | $name = $backend->getBackendName(); |
394 | 394 | } else { |
395 | 395 | $name = get_class($backend); |
396 | 396 | } |
397 | - if(isset($userCountStatistics[$name])) { |
|
397 | + if (isset($userCountStatistics[$name])) { |
|
398 | 398 | $userCountStatistics[$name] += $backendUsers; |
399 | 399 | } else { |
400 | 400 | $userCountStatistics[$name] = $backendUsers; |
@@ -414,7 +414,7 @@ discard block |
||
414 | 414 | */ |
415 | 415 | public function countUsersOfGroups(array $groups) { |
416 | 416 | $users = []; |
417 | - foreach($groups as $group) { |
|
417 | + foreach ($groups as $group) { |
|
418 | 418 | $usersIds = array_map(function($user) { |
419 | 419 | return $user->getUID(); |
420 | 420 | }, $group->getUsers()); |
@@ -478,7 +478,7 @@ discard block |
||
478 | 478 | $result->closeCursor(); |
479 | 479 | |
480 | 480 | if ($count !== false) { |
481 | - $count = (int)$count; |
|
481 | + $count = (int) $count; |
|
482 | 482 | } else { |
483 | 483 | $count = 0; |
484 | 484 | } |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | */ |
496 | 496 | public function countDisabledUsersOfGroups(array $groups): int { |
497 | 497 | $queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
498 | - $queryBuilder->select($queryBuilder->createFunction('COUNT(DISTINCT ' . $queryBuilder->getColumnName('uid') . ')')) |
|
498 | + $queryBuilder->select($queryBuilder->createFunction('COUNT(DISTINCT '.$queryBuilder->getColumnName('uid').')')) |
|
499 | 499 | ->from('preferences', 'p') |
500 | 500 | ->innerJoin('p', 'group_user', 'g', $queryBuilder->expr()->eq('p.userid', 'g.uid')) |
501 | 501 | ->where($queryBuilder->expr()->eq('appid', $queryBuilder->createNamedParameter('core'))) |
@@ -508,7 +508,7 @@ discard block |
||
508 | 508 | $result->closeCursor(); |
509 | 509 | |
510 | 510 | if ($count !== false) { |
511 | - $count = (int)$count; |
|
511 | + $count = (int) $count; |
|
512 | 512 | } else { |
513 | 513 | $count = 0; |
514 | 514 | } |
@@ -532,7 +532,7 @@ discard block |
||
532 | 532 | |
533 | 533 | $query = $queryBuilder->execute(); |
534 | 534 | |
535 | - $result = (int)$query->fetchColumn(); |
|
535 | + $result = (int) $query->fetchColumn(); |
|
536 | 536 | $query->closeCursor(); |
537 | 537 | |
538 | 538 | return $result; |
@@ -621,7 +621,7 @@ discard block |
||
621 | 621 | } |
622 | 622 | |
623 | 623 | private function verifyUid(string $uid): bool { |
624 | - $appdata = 'appdata_' . $this->config->getSystemValueString('instanceid'); |
|
624 | + $appdata = 'appdata_'.$this->config->getSystemValueString('instanceid'); |
|
625 | 625 | |
626 | 626 | if ($uid === '.htaccess' || $uid === 'files_external' || $uid === '.ocdata' || $uid === 'owncloud.log' || $uid === 'nextcloud.log' || $uid === $appdata) { |
627 | 627 | return false; |
@@ -169,1894 +169,1894 @@ |
||
169 | 169 | * TODO: hookup all manager classes |
170 | 170 | */ |
171 | 171 | class Server extends ServerContainer implements IServerContainer { |
172 | - /** @var string */ |
|
173 | - private $webRoot; |
|
174 | - |
|
175 | - /** |
|
176 | - * @param string $webRoot |
|
177 | - * @param \OC\Config $config |
|
178 | - */ |
|
179 | - public function __construct($webRoot, \OC\Config $config) { |
|
180 | - parent::__construct(); |
|
181 | - $this->webRoot = $webRoot; |
|
182 | - |
|
183 | - // To find out if we are running from CLI or not |
|
184 | - $this->registerParameter('isCLI', \OC::$CLI); |
|
185 | - |
|
186 | - $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
187 | - return $c; |
|
188 | - }); |
|
189 | - |
|
190 | - $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
191 | - $this->registerAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
192 | - |
|
193 | - $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
194 | - $this->registerAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class); |
|
195 | - |
|
196 | - $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
197 | - $this->registerAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class); |
|
198 | - |
|
199 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
200 | - $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
201 | - |
|
202 | - $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class); |
|
203 | - |
|
204 | - $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
205 | - |
|
206 | - |
|
207 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
208 | - return new PreviewManager( |
|
209 | - $c->getConfig(), |
|
210 | - $c->getRootFolder(), |
|
211 | - $c->getAppDataDir('preview'), |
|
212 | - $c->getEventDispatcher(), |
|
213 | - $c->getGeneratorHelper(), |
|
214 | - $c->getSession()->get('user_id') |
|
215 | - ); |
|
216 | - }); |
|
217 | - $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
218 | - |
|
219 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
220 | - return new \OC\Preview\Watcher( |
|
221 | - $c->getAppDataDir('preview') |
|
222 | - ); |
|
223 | - }); |
|
224 | - |
|
225 | - $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) { |
|
226 | - $view = new View(); |
|
227 | - $util = new Encryption\Util( |
|
228 | - $view, |
|
229 | - $c->getUserManager(), |
|
230 | - $c->getGroupManager(), |
|
231 | - $c->getConfig() |
|
232 | - ); |
|
233 | - return new Encryption\Manager( |
|
234 | - $c->getConfig(), |
|
235 | - $c->getLogger(), |
|
236 | - $c->getL10N('core'), |
|
237 | - new View(), |
|
238 | - $util, |
|
239 | - new ArrayCache() |
|
240 | - ); |
|
241 | - }); |
|
242 | - $this->registerAlias('EncryptionManager', \OCP\Encryption\IManager::class); |
|
243 | - |
|
244 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
245 | - $util = new Encryption\Util( |
|
246 | - new View(), |
|
247 | - $c->getUserManager(), |
|
248 | - $c->getGroupManager(), |
|
249 | - $c->getConfig() |
|
250 | - ); |
|
251 | - return new Encryption\File( |
|
252 | - $util, |
|
253 | - $c->getRootFolder(), |
|
254 | - $c->getShareManager() |
|
255 | - ); |
|
256 | - }); |
|
257 | - |
|
258 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
259 | - $view = new View(); |
|
260 | - $util = new Encryption\Util( |
|
261 | - $view, |
|
262 | - $c->getUserManager(), |
|
263 | - $c->getGroupManager(), |
|
264 | - $c->getConfig() |
|
265 | - ); |
|
266 | - |
|
267 | - return new Encryption\Keys\Storage($view, $util); |
|
268 | - }); |
|
269 | - $this->registerService('TagMapper', function (Server $c) { |
|
270 | - return new TagMapper($c->getDatabaseConnection()); |
|
271 | - }); |
|
272 | - |
|
273 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
274 | - $tagMapper = $c->query('TagMapper'); |
|
275 | - return new TagManager($tagMapper, $c->getUserSession()); |
|
276 | - }); |
|
277 | - $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
278 | - |
|
279 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
280 | - $config = $c->getConfig(); |
|
281 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
282 | - return new $factoryClass($this); |
|
283 | - }); |
|
284 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
285 | - return $c->query('SystemTagManagerFactory')->getManager(); |
|
286 | - }); |
|
287 | - $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
288 | - |
|
289 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
290 | - return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
291 | - }); |
|
292 | - $this->registerService('RootFolder', function (Server $c) { |
|
293 | - $manager = \OC\Files\Filesystem::getMountManager(null); |
|
294 | - $view = new View(); |
|
295 | - $root = new Root( |
|
296 | - $manager, |
|
297 | - $view, |
|
298 | - null, |
|
299 | - $c->getUserMountCache(), |
|
300 | - $this->getLogger(), |
|
301 | - $this->getUserManager() |
|
302 | - ); |
|
303 | - $connector = new HookConnector($root, $view, $c->getEventDispatcher()); |
|
304 | - $connector->viewToNode(); |
|
305 | - |
|
306 | - $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
307 | - $previewConnector->connectWatcher(); |
|
308 | - |
|
309 | - return $root; |
|
310 | - }); |
|
311 | - $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
312 | - |
|
313 | - $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
314 | - return new LazyRoot(function () use ($c) { |
|
315 | - return $c->query('RootFolder'); |
|
316 | - }); |
|
317 | - }); |
|
318 | - $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
319 | - |
|
320 | - $this->registerAlias('UserManager', \OC\User\Manager::class); |
|
321 | - $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
322 | - |
|
323 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
324 | - $groupManager = new \OC\Group\Manager($this->getUserManager(), $c->getEventDispatcher(), $this->getLogger()); |
|
325 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
326 | - \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
327 | - }); |
|
328 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
329 | - \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
330 | - }); |
|
331 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
332 | - \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
333 | - }); |
|
334 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
335 | - \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
336 | - }); |
|
337 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
338 | - \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
339 | - }); |
|
340 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
341 | - \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
342 | - //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
343 | - \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
344 | - }); |
|
345 | - return $groupManager; |
|
346 | - }); |
|
347 | - $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
348 | - |
|
349 | - $this->registerService(Store::class, function (Server $c) { |
|
350 | - $session = $c->getSession(); |
|
351 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
352 | - $tokenProvider = $c->query(IProvider::class); |
|
353 | - } else { |
|
354 | - $tokenProvider = null; |
|
355 | - } |
|
356 | - $logger = $c->getLogger(); |
|
357 | - return new Store($session, $logger, $tokenProvider); |
|
358 | - }); |
|
359 | - $this->registerAlias(IStore::class, Store::class); |
|
360 | - $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) { |
|
361 | - $dbConnection = $c->getDatabaseConnection(); |
|
362 | - return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
363 | - }); |
|
364 | - $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
365 | - |
|
366 | - $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
367 | - $manager = $c->getUserManager(); |
|
368 | - $session = new \OC\Session\Memory(''); |
|
369 | - $timeFactory = new TimeFactory(); |
|
370 | - // Token providers might require a working database. This code |
|
371 | - // might however be called when ownCloud is not yet setup. |
|
372 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
373 | - $defaultTokenProvider = $c->query(IProvider::class); |
|
374 | - } else { |
|
375 | - $defaultTokenProvider = null; |
|
376 | - } |
|
377 | - |
|
378 | - $dispatcher = $c->getEventDispatcher(); |
|
379 | - |
|
380 | - $userSession = new \OC\User\Session( |
|
381 | - $manager, |
|
382 | - $session, |
|
383 | - $timeFactory, |
|
384 | - $defaultTokenProvider, |
|
385 | - $c->getConfig(), |
|
386 | - $c->getSecureRandom(), |
|
387 | - $c->getLockdownManager(), |
|
388 | - $c->getLogger(), |
|
389 | - $c->query(IEventDispatcher::class) |
|
390 | - ); |
|
391 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
392 | - \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
393 | - }); |
|
394 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
395 | - /** @var $user \OC\User\User */ |
|
396 | - \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
397 | - }); |
|
398 | - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
|
399 | - /** @var $user \OC\User\User */ |
|
400 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
401 | - $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
402 | - }); |
|
403 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
404 | - /** @var $user \OC\User\User */ |
|
405 | - \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
406 | - }); |
|
407 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
408 | - /** @var $user \OC\User\User */ |
|
409 | - \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
410 | - }); |
|
411 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
412 | - /** @var $user \OC\User\User */ |
|
413 | - \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
414 | - }); |
|
415 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
416 | - \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
417 | - }); |
|
418 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password, $isTokenLogin) { |
|
419 | - /** @var $user \OC\User\User */ |
|
420 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'isTokenLogin' => $isTokenLogin)); |
|
421 | - }); |
|
422 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
423 | - /** @var $user \OC\User\User */ |
|
424 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
425 | - }); |
|
426 | - $userSession->listen('\OC\User', 'logout', function () { |
|
427 | - \OC_Hook::emit('OC_User', 'logout', array()); |
|
428 | - }); |
|
429 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
430 | - /** @var $user \OC\User\User */ |
|
431 | - \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
432 | - }); |
|
433 | - return $userSession; |
|
434 | - }); |
|
435 | - $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
436 | - $this->registerAlias('UserSession', \OC\User\Session::class); |
|
437 | - |
|
438 | - $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
439 | - |
|
440 | - $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
441 | - $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
442 | - |
|
443 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
444 | - return new \OC\AllConfig( |
|
445 | - $c->getSystemConfig() |
|
446 | - ); |
|
447 | - }); |
|
448 | - $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
449 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
450 | - |
|
451 | - $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
452 | - return new \OC\SystemConfig($config); |
|
453 | - }); |
|
454 | - $this->registerAlias('SystemConfig', \OC\SystemConfig::class); |
|
455 | - |
|
456 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
457 | - return new \OC\AppConfig($c->getDatabaseConnection()); |
|
458 | - }); |
|
459 | - $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
460 | - $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
461 | - |
|
462 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
463 | - return new \OC\L10N\Factory( |
|
464 | - $c->getConfig(), |
|
465 | - $c->getRequest(), |
|
466 | - $c->getUserSession(), |
|
467 | - \OC::$SERVERROOT |
|
468 | - ); |
|
469 | - }); |
|
470 | - $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
471 | - |
|
472 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
473 | - $config = $c->getConfig(); |
|
474 | - $cacheFactory = $c->getMemCacheFactory(); |
|
475 | - $request = $c->getRequest(); |
|
476 | - return new \OC\URLGenerator( |
|
477 | - $config, |
|
478 | - $cacheFactory, |
|
479 | - $request |
|
480 | - ); |
|
481 | - }); |
|
482 | - $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
483 | - |
|
484 | - $this->registerAlias('AppFetcher', AppFetcher::class); |
|
485 | - $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
|
486 | - |
|
487 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
488 | - return new Cache\File(); |
|
489 | - }); |
|
490 | - $this->registerAlias('UserCache', \OCP\ICache::class); |
|
491 | - |
|
492 | - $this->registerService(Factory::class, function (Server $c) { |
|
493 | - |
|
494 | - $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
495 | - ArrayCache::class, |
|
496 | - ArrayCache::class, |
|
497 | - ArrayCache::class |
|
498 | - ); |
|
499 | - $config = $c->getConfig(); |
|
500 | - |
|
501 | - if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
502 | - $v = \OC_App::getAppVersions(); |
|
503 | - $v['core'] = implode(',', \OC_Util::getVersion()); |
|
504 | - $version = implode(',', $v); |
|
505 | - $instanceId = \OC_Util::getInstanceId(); |
|
506 | - $path = \OC::$SERVERROOT; |
|
507 | - $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
508 | - return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
509 | - $config->getSystemValue('memcache.local', null), |
|
510 | - $config->getSystemValue('memcache.distributed', null), |
|
511 | - $config->getSystemValue('memcache.locking', null) |
|
512 | - ); |
|
513 | - } |
|
514 | - return $arrayCacheFactory; |
|
515 | - |
|
516 | - }); |
|
517 | - $this->registerAlias('MemCacheFactory', Factory::class); |
|
518 | - $this->registerAlias(ICacheFactory::class, Factory::class); |
|
519 | - |
|
520 | - $this->registerService('RedisFactory', function (Server $c) { |
|
521 | - $systemConfig = $c->getSystemConfig(); |
|
522 | - return new RedisFactory($systemConfig); |
|
523 | - }); |
|
524 | - |
|
525 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
526 | - return new \OC\Activity\Manager( |
|
527 | - $c->getRequest(), |
|
528 | - $c->getUserSession(), |
|
529 | - $c->getConfig(), |
|
530 | - $c->query(IValidator::class) |
|
531 | - ); |
|
532 | - }); |
|
533 | - $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
534 | - |
|
535 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
536 | - return new \OC\Activity\EventMerger( |
|
537 | - $c->getL10N('lib') |
|
538 | - ); |
|
539 | - }); |
|
540 | - $this->registerAlias(IValidator::class, Validator::class); |
|
541 | - |
|
542 | - $this->registerService(AvatarManager::class, function(Server $c) { |
|
543 | - return new AvatarManager( |
|
544 | - $c->query(\OC\User\Manager::class), |
|
545 | - $c->getAppDataDir('avatar'), |
|
546 | - $c->getL10N('lib'), |
|
547 | - $c->getLogger(), |
|
548 | - $c->getConfig() |
|
549 | - ); |
|
550 | - }); |
|
551 | - $this->registerAlias(\OCP\IAvatarManager::class, AvatarManager::class); |
|
552 | - $this->registerAlias('AvatarManager', AvatarManager::class); |
|
553 | - |
|
554 | - $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
555 | - $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
|
556 | - |
|
557 | - $this->registerService(\OC\Log::class, function (Server $c) { |
|
558 | - $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
559 | - $factory = new LogFactory($c, $this->getSystemConfig()); |
|
560 | - $logger = $factory->get($logType); |
|
561 | - $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class); |
|
562 | - |
|
563 | - return new Log($logger, $this->getSystemConfig(), null, $registry); |
|
564 | - }); |
|
565 | - $this->registerAlias(\OCP\ILogger::class, \OC\Log::class); |
|
566 | - $this->registerAlias('Logger', \OC\Log::class); |
|
567 | - |
|
568 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
569 | - return new LogFactory($c, $this->getSystemConfig()); |
|
570 | - }); |
|
571 | - |
|
572 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
573 | - $config = $c->getConfig(); |
|
574 | - return new \OC\BackgroundJob\JobList( |
|
575 | - $c->getDatabaseConnection(), |
|
576 | - $config, |
|
577 | - new TimeFactory() |
|
578 | - ); |
|
579 | - }); |
|
580 | - $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
581 | - |
|
582 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
583 | - $cacheFactory = $c->getMemCacheFactory(); |
|
584 | - $logger = $c->getLogger(); |
|
585 | - if ($cacheFactory->isLocalCacheAvailable()) { |
|
586 | - $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
587 | - } else { |
|
588 | - $router = new \OC\Route\Router($logger); |
|
589 | - } |
|
590 | - return $router; |
|
591 | - }); |
|
592 | - $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
593 | - |
|
594 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
595 | - return new Search(); |
|
596 | - }); |
|
597 | - $this->registerAlias('Search', \OCP\ISearch::class); |
|
598 | - |
|
599 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
600 | - return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
601 | - $this->getMemCacheFactory(), |
|
602 | - new \OC\AppFramework\Utility\TimeFactory() |
|
603 | - ); |
|
604 | - }); |
|
605 | - |
|
606 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
607 | - return new SecureRandom(); |
|
608 | - }); |
|
609 | - $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
610 | - |
|
611 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
612 | - return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
613 | - }); |
|
614 | - $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
615 | - |
|
616 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
617 | - return new Hasher($c->getConfig()); |
|
618 | - }); |
|
619 | - $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
620 | - |
|
621 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
622 | - return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
623 | - }); |
|
624 | - $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
625 | - |
|
626 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
627 | - $systemConfig = $c->getSystemConfig(); |
|
628 | - $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
629 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
630 | - if (!$factory->isValidType($type)) { |
|
631 | - throw new \OC\DatabaseException('Invalid database type'); |
|
632 | - } |
|
633 | - $connectionParams = $factory->createConnectionParams(); |
|
634 | - $connection = $factory->getConnection($type, $connectionParams); |
|
635 | - $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
636 | - return $connection; |
|
637 | - }); |
|
638 | - $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
639 | - |
|
640 | - |
|
641 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
642 | - $user = \OC_User::getUser(); |
|
643 | - $uid = $user ? $user : null; |
|
644 | - return new ClientService( |
|
645 | - $c->getConfig(), |
|
646 | - new \OC\Security\CertificateManager( |
|
647 | - $uid, |
|
648 | - new View(), |
|
649 | - $c->getConfig(), |
|
650 | - $c->getLogger(), |
|
651 | - $c->getSecureRandom() |
|
652 | - ) |
|
653 | - ); |
|
654 | - }); |
|
655 | - $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
656 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
657 | - $eventLogger = new EventLogger(); |
|
658 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
659 | - // In debug mode, module is being activated by default |
|
660 | - $eventLogger->activate(); |
|
661 | - } |
|
662 | - return $eventLogger; |
|
663 | - }); |
|
664 | - $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
665 | - |
|
666 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
667 | - $queryLogger = new QueryLogger(); |
|
668 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
669 | - // In debug mode, module is being activated by default |
|
670 | - $queryLogger->activate(); |
|
671 | - } |
|
672 | - return $queryLogger; |
|
673 | - }); |
|
674 | - $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
675 | - |
|
676 | - $this->registerService(TempManager::class, function (Server $c) { |
|
677 | - return new TempManager( |
|
678 | - $c->getLogger(), |
|
679 | - $c->getConfig() |
|
680 | - ); |
|
681 | - }); |
|
682 | - $this->registerAlias('TempManager', TempManager::class); |
|
683 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
684 | - |
|
685 | - $this->registerService(AppManager::class, function (Server $c) { |
|
686 | - return new \OC\App\AppManager( |
|
687 | - $c->getUserSession(), |
|
688 | - $c->query(\OC\AppConfig::class), |
|
689 | - $c->getGroupManager(), |
|
690 | - $c->getMemCacheFactory(), |
|
691 | - $c->getEventDispatcher(), |
|
692 | - $c->getLogger() |
|
693 | - ); |
|
694 | - }); |
|
695 | - $this->registerAlias('AppManager', AppManager::class); |
|
696 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
697 | - |
|
698 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
699 | - return new DateTimeZone( |
|
700 | - $c->getConfig(), |
|
701 | - $c->getSession() |
|
702 | - ); |
|
703 | - }); |
|
704 | - $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
705 | - |
|
706 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
707 | - $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
708 | - |
|
709 | - return new DateTimeFormatter( |
|
710 | - $c->getDateTimeZone()->getTimeZone(), |
|
711 | - $c->getL10N('lib', $language) |
|
712 | - ); |
|
713 | - }); |
|
714 | - $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
715 | - |
|
716 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
717 | - $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
718 | - $listener = new UserMountCacheListener($mountCache); |
|
719 | - $listener->listen($c->getUserManager()); |
|
720 | - return $mountCache; |
|
721 | - }); |
|
722 | - $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
723 | - |
|
724 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
725 | - $loader = \OC\Files\Filesystem::getLoader(); |
|
726 | - $mountCache = $c->query('UserMountCache'); |
|
727 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
728 | - |
|
729 | - // builtin providers |
|
730 | - |
|
731 | - $config = $c->getConfig(); |
|
732 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
733 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
734 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
735 | - |
|
736 | - return $manager; |
|
737 | - }); |
|
738 | - $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
739 | - |
|
740 | - $this->registerService('IniWrapper', function ($c) { |
|
741 | - return new IniGetWrapper(); |
|
742 | - }); |
|
743 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
744 | - $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
745 | - if ($busClass) { |
|
746 | - list($app, $class) = explode('::', $busClass, 2); |
|
747 | - if ($c->getAppManager()->isInstalled($app)) { |
|
748 | - \OC_App::loadApp($app); |
|
749 | - return $c->query($class); |
|
750 | - } else { |
|
751 | - throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
752 | - } |
|
753 | - } else { |
|
754 | - $jobList = $c->getJobList(); |
|
755 | - return new CronBus($jobList); |
|
756 | - } |
|
757 | - }); |
|
758 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
759 | - return new TrustedDomainHelper($this->getConfig()); |
|
760 | - }); |
|
761 | - $this->registerService(Throttler::class, function (Server $c) { |
|
762 | - return new Throttler( |
|
763 | - $c->getDatabaseConnection(), |
|
764 | - new TimeFactory(), |
|
765 | - $c->getLogger(), |
|
766 | - $c->getConfig() |
|
767 | - ); |
|
768 | - }); |
|
769 | - $this->registerAlias('Throttler', Throttler::class); |
|
770 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
771 | - // IConfig and IAppManager requires a working database. This code |
|
772 | - // might however be called when ownCloud is not yet setup. |
|
773 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
774 | - $config = $c->getConfig(); |
|
775 | - $appManager = $c->getAppManager(); |
|
776 | - } else { |
|
777 | - $config = null; |
|
778 | - $appManager = null; |
|
779 | - } |
|
780 | - |
|
781 | - return new Checker( |
|
782 | - new EnvironmentHelper(), |
|
783 | - new FileAccessHelper(), |
|
784 | - new AppLocator(), |
|
785 | - $config, |
|
786 | - $c->getMemCacheFactory(), |
|
787 | - $appManager, |
|
788 | - $c->getTempManager(), |
|
789 | - $c->getMimeTypeDetector() |
|
790 | - ); |
|
791 | - }); |
|
792 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
793 | - if (isset($this['urlParams'])) { |
|
794 | - $urlParams = $this['urlParams']; |
|
795 | - } else { |
|
796 | - $urlParams = []; |
|
797 | - } |
|
798 | - |
|
799 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
800 | - && in_array('fakeinput', stream_get_wrappers()) |
|
801 | - ) { |
|
802 | - $stream = 'fakeinput://data'; |
|
803 | - } else { |
|
804 | - $stream = 'php://input'; |
|
805 | - } |
|
806 | - |
|
807 | - return new Request( |
|
808 | - [ |
|
809 | - 'get' => $_GET, |
|
810 | - 'post' => $_POST, |
|
811 | - 'files' => $_FILES, |
|
812 | - 'server' => $_SERVER, |
|
813 | - 'env' => $_ENV, |
|
814 | - 'cookies' => $_COOKIE, |
|
815 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
816 | - ? $_SERVER['REQUEST_METHOD'] |
|
817 | - : '', |
|
818 | - 'urlParams' => $urlParams, |
|
819 | - ], |
|
820 | - $this->getSecureRandom(), |
|
821 | - $this->getConfig(), |
|
822 | - $this->getCsrfTokenManager(), |
|
823 | - $stream |
|
824 | - ); |
|
825 | - }); |
|
826 | - $this->registerAlias('Request', \OCP\IRequest::class); |
|
827 | - |
|
828 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
829 | - return new Mailer( |
|
830 | - $c->getConfig(), |
|
831 | - $c->getLogger(), |
|
832 | - $c->query(Defaults::class), |
|
833 | - $c->getURLGenerator(), |
|
834 | - $c->getL10N('lib') |
|
835 | - ); |
|
836 | - }); |
|
837 | - $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
838 | - |
|
839 | - $this->registerService('LDAPProvider', function (Server $c) { |
|
840 | - $config = $c->getConfig(); |
|
841 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
842 | - if (is_null($factoryClass)) { |
|
843 | - throw new \Exception('ldapProviderFactory not set'); |
|
844 | - } |
|
845 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
846 | - $factory = new $factoryClass($this); |
|
847 | - return $factory->getLDAPProvider(); |
|
848 | - }); |
|
849 | - $this->registerService(ILockingProvider::class, function (Server $c) { |
|
850 | - $ini = $c->getIniWrapper(); |
|
851 | - $config = $c->getConfig(); |
|
852 | - $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
853 | - if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
854 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
855 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
856 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
857 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
858 | - return new MemcacheLockingProvider($memcache, $ttl); |
|
859 | - } |
|
860 | - return new DBLockingProvider( |
|
861 | - $c->getDatabaseConnection(), |
|
862 | - $c->getLogger(), |
|
863 | - new TimeFactory(), |
|
864 | - $ttl, |
|
865 | - !\OC::$CLI |
|
866 | - ); |
|
867 | - } |
|
868 | - return new NoopLockingProvider(); |
|
869 | - }); |
|
870 | - $this->registerAlias('LockingProvider', ILockingProvider::class); |
|
871 | - |
|
872 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
873 | - return new \OC\Files\Mount\Manager(); |
|
874 | - }); |
|
875 | - $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
876 | - |
|
877 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
878 | - return new \OC\Files\Type\Detection( |
|
879 | - $c->getURLGenerator(), |
|
880 | - \OC::$configDir, |
|
881 | - \OC::$SERVERROOT . '/resources/config/' |
|
882 | - ); |
|
883 | - }); |
|
884 | - $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
885 | - |
|
886 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
887 | - return new \OC\Files\Type\Loader( |
|
888 | - $c->getDatabaseConnection() |
|
889 | - ); |
|
890 | - }); |
|
891 | - $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
892 | - $this->registerService(BundleFetcher::class, function () { |
|
893 | - return new BundleFetcher($this->getL10N('lib')); |
|
894 | - }); |
|
895 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
896 | - return new Manager( |
|
897 | - $c->query(IValidator::class), |
|
898 | - $c->getLogger() |
|
899 | - ); |
|
900 | - }); |
|
901 | - $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
902 | - |
|
903 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
904 | - $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
905 | - $manager->registerCapability(function () use ($c) { |
|
906 | - return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
907 | - }); |
|
908 | - $manager->registerCapability(function () use ($c) { |
|
909 | - return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
910 | - }); |
|
911 | - return $manager; |
|
912 | - }); |
|
913 | - $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
914 | - |
|
915 | - $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
916 | - $config = $c->getConfig(); |
|
917 | - $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
918 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
919 | - $factory = new $factoryClass($this); |
|
920 | - $manager = $factory->getManager(); |
|
921 | - |
|
922 | - $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
|
923 | - $manager = $c->getUserManager(); |
|
924 | - $user = $manager->get($id); |
|
925 | - if(is_null($user)) { |
|
926 | - $l = $c->getL10N('core'); |
|
927 | - $displayName = $l->t('Unknown user'); |
|
928 | - } else { |
|
929 | - $displayName = $user->getDisplayName(); |
|
930 | - } |
|
931 | - return $displayName; |
|
932 | - }); |
|
933 | - |
|
934 | - return $manager; |
|
935 | - }); |
|
936 | - $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
937 | - |
|
938 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
939 | - /* |
|
172 | + /** @var string */ |
|
173 | + private $webRoot; |
|
174 | + |
|
175 | + /** |
|
176 | + * @param string $webRoot |
|
177 | + * @param \OC\Config $config |
|
178 | + */ |
|
179 | + public function __construct($webRoot, \OC\Config $config) { |
|
180 | + parent::__construct(); |
|
181 | + $this->webRoot = $webRoot; |
|
182 | + |
|
183 | + // To find out if we are running from CLI or not |
|
184 | + $this->registerParameter('isCLI', \OC::$CLI); |
|
185 | + |
|
186 | + $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
187 | + return $c; |
|
188 | + }); |
|
189 | + |
|
190 | + $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
191 | + $this->registerAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
192 | + |
|
193 | + $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
194 | + $this->registerAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class); |
|
195 | + |
|
196 | + $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
197 | + $this->registerAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class); |
|
198 | + |
|
199 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
200 | + $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
201 | + |
|
202 | + $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class); |
|
203 | + |
|
204 | + $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
205 | + |
|
206 | + |
|
207 | + $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
208 | + return new PreviewManager( |
|
209 | + $c->getConfig(), |
|
210 | + $c->getRootFolder(), |
|
211 | + $c->getAppDataDir('preview'), |
|
212 | + $c->getEventDispatcher(), |
|
213 | + $c->getGeneratorHelper(), |
|
214 | + $c->getSession()->get('user_id') |
|
215 | + ); |
|
216 | + }); |
|
217 | + $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
218 | + |
|
219 | + $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
220 | + return new \OC\Preview\Watcher( |
|
221 | + $c->getAppDataDir('preview') |
|
222 | + ); |
|
223 | + }); |
|
224 | + |
|
225 | + $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) { |
|
226 | + $view = new View(); |
|
227 | + $util = new Encryption\Util( |
|
228 | + $view, |
|
229 | + $c->getUserManager(), |
|
230 | + $c->getGroupManager(), |
|
231 | + $c->getConfig() |
|
232 | + ); |
|
233 | + return new Encryption\Manager( |
|
234 | + $c->getConfig(), |
|
235 | + $c->getLogger(), |
|
236 | + $c->getL10N('core'), |
|
237 | + new View(), |
|
238 | + $util, |
|
239 | + new ArrayCache() |
|
240 | + ); |
|
241 | + }); |
|
242 | + $this->registerAlias('EncryptionManager', \OCP\Encryption\IManager::class); |
|
243 | + |
|
244 | + $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
245 | + $util = new Encryption\Util( |
|
246 | + new View(), |
|
247 | + $c->getUserManager(), |
|
248 | + $c->getGroupManager(), |
|
249 | + $c->getConfig() |
|
250 | + ); |
|
251 | + return new Encryption\File( |
|
252 | + $util, |
|
253 | + $c->getRootFolder(), |
|
254 | + $c->getShareManager() |
|
255 | + ); |
|
256 | + }); |
|
257 | + |
|
258 | + $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
259 | + $view = new View(); |
|
260 | + $util = new Encryption\Util( |
|
261 | + $view, |
|
262 | + $c->getUserManager(), |
|
263 | + $c->getGroupManager(), |
|
264 | + $c->getConfig() |
|
265 | + ); |
|
266 | + |
|
267 | + return new Encryption\Keys\Storage($view, $util); |
|
268 | + }); |
|
269 | + $this->registerService('TagMapper', function (Server $c) { |
|
270 | + return new TagMapper($c->getDatabaseConnection()); |
|
271 | + }); |
|
272 | + |
|
273 | + $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
274 | + $tagMapper = $c->query('TagMapper'); |
|
275 | + return new TagManager($tagMapper, $c->getUserSession()); |
|
276 | + }); |
|
277 | + $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
278 | + |
|
279 | + $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
280 | + $config = $c->getConfig(); |
|
281 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
282 | + return new $factoryClass($this); |
|
283 | + }); |
|
284 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
285 | + return $c->query('SystemTagManagerFactory')->getManager(); |
|
286 | + }); |
|
287 | + $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
288 | + |
|
289 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
290 | + return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
291 | + }); |
|
292 | + $this->registerService('RootFolder', function (Server $c) { |
|
293 | + $manager = \OC\Files\Filesystem::getMountManager(null); |
|
294 | + $view = new View(); |
|
295 | + $root = new Root( |
|
296 | + $manager, |
|
297 | + $view, |
|
298 | + null, |
|
299 | + $c->getUserMountCache(), |
|
300 | + $this->getLogger(), |
|
301 | + $this->getUserManager() |
|
302 | + ); |
|
303 | + $connector = new HookConnector($root, $view, $c->getEventDispatcher()); |
|
304 | + $connector->viewToNode(); |
|
305 | + |
|
306 | + $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
307 | + $previewConnector->connectWatcher(); |
|
308 | + |
|
309 | + return $root; |
|
310 | + }); |
|
311 | + $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
312 | + |
|
313 | + $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
314 | + return new LazyRoot(function () use ($c) { |
|
315 | + return $c->query('RootFolder'); |
|
316 | + }); |
|
317 | + }); |
|
318 | + $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
319 | + |
|
320 | + $this->registerAlias('UserManager', \OC\User\Manager::class); |
|
321 | + $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
322 | + |
|
323 | + $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
324 | + $groupManager = new \OC\Group\Manager($this->getUserManager(), $c->getEventDispatcher(), $this->getLogger()); |
|
325 | + $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
326 | + \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
327 | + }); |
|
328 | + $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
329 | + \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
330 | + }); |
|
331 | + $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
332 | + \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
333 | + }); |
|
334 | + $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
335 | + \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
336 | + }); |
|
337 | + $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
338 | + \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
339 | + }); |
|
340 | + $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
341 | + \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
342 | + //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
343 | + \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
344 | + }); |
|
345 | + return $groupManager; |
|
346 | + }); |
|
347 | + $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
348 | + |
|
349 | + $this->registerService(Store::class, function (Server $c) { |
|
350 | + $session = $c->getSession(); |
|
351 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
352 | + $tokenProvider = $c->query(IProvider::class); |
|
353 | + } else { |
|
354 | + $tokenProvider = null; |
|
355 | + } |
|
356 | + $logger = $c->getLogger(); |
|
357 | + return new Store($session, $logger, $tokenProvider); |
|
358 | + }); |
|
359 | + $this->registerAlias(IStore::class, Store::class); |
|
360 | + $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) { |
|
361 | + $dbConnection = $c->getDatabaseConnection(); |
|
362 | + return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
363 | + }); |
|
364 | + $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
365 | + |
|
366 | + $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
367 | + $manager = $c->getUserManager(); |
|
368 | + $session = new \OC\Session\Memory(''); |
|
369 | + $timeFactory = new TimeFactory(); |
|
370 | + // Token providers might require a working database. This code |
|
371 | + // might however be called when ownCloud is not yet setup. |
|
372 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
373 | + $defaultTokenProvider = $c->query(IProvider::class); |
|
374 | + } else { |
|
375 | + $defaultTokenProvider = null; |
|
376 | + } |
|
377 | + |
|
378 | + $dispatcher = $c->getEventDispatcher(); |
|
379 | + |
|
380 | + $userSession = new \OC\User\Session( |
|
381 | + $manager, |
|
382 | + $session, |
|
383 | + $timeFactory, |
|
384 | + $defaultTokenProvider, |
|
385 | + $c->getConfig(), |
|
386 | + $c->getSecureRandom(), |
|
387 | + $c->getLockdownManager(), |
|
388 | + $c->getLogger(), |
|
389 | + $c->query(IEventDispatcher::class) |
|
390 | + ); |
|
391 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
392 | + \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
393 | + }); |
|
394 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
395 | + /** @var $user \OC\User\User */ |
|
396 | + \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
397 | + }); |
|
398 | + $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
|
399 | + /** @var $user \OC\User\User */ |
|
400 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
401 | + $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
402 | + }); |
|
403 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
404 | + /** @var $user \OC\User\User */ |
|
405 | + \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
406 | + }); |
|
407 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
408 | + /** @var $user \OC\User\User */ |
|
409 | + \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
410 | + }); |
|
411 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
412 | + /** @var $user \OC\User\User */ |
|
413 | + \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
414 | + }); |
|
415 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
416 | + \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
417 | + }); |
|
418 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $password, $isTokenLogin) { |
|
419 | + /** @var $user \OC\User\User */ |
|
420 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'isTokenLogin' => $isTokenLogin)); |
|
421 | + }); |
|
422 | + $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
423 | + /** @var $user \OC\User\User */ |
|
424 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
425 | + }); |
|
426 | + $userSession->listen('\OC\User', 'logout', function () { |
|
427 | + \OC_Hook::emit('OC_User', 'logout', array()); |
|
428 | + }); |
|
429 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
430 | + /** @var $user \OC\User\User */ |
|
431 | + \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
432 | + }); |
|
433 | + return $userSession; |
|
434 | + }); |
|
435 | + $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
436 | + $this->registerAlias('UserSession', \OC\User\Session::class); |
|
437 | + |
|
438 | + $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
439 | + |
|
440 | + $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
441 | + $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
442 | + |
|
443 | + $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
444 | + return new \OC\AllConfig( |
|
445 | + $c->getSystemConfig() |
|
446 | + ); |
|
447 | + }); |
|
448 | + $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
449 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
450 | + |
|
451 | + $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
452 | + return new \OC\SystemConfig($config); |
|
453 | + }); |
|
454 | + $this->registerAlias('SystemConfig', \OC\SystemConfig::class); |
|
455 | + |
|
456 | + $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
457 | + return new \OC\AppConfig($c->getDatabaseConnection()); |
|
458 | + }); |
|
459 | + $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
460 | + $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
461 | + |
|
462 | + $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
463 | + return new \OC\L10N\Factory( |
|
464 | + $c->getConfig(), |
|
465 | + $c->getRequest(), |
|
466 | + $c->getUserSession(), |
|
467 | + \OC::$SERVERROOT |
|
468 | + ); |
|
469 | + }); |
|
470 | + $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
471 | + |
|
472 | + $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
473 | + $config = $c->getConfig(); |
|
474 | + $cacheFactory = $c->getMemCacheFactory(); |
|
475 | + $request = $c->getRequest(); |
|
476 | + return new \OC\URLGenerator( |
|
477 | + $config, |
|
478 | + $cacheFactory, |
|
479 | + $request |
|
480 | + ); |
|
481 | + }); |
|
482 | + $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
483 | + |
|
484 | + $this->registerAlias('AppFetcher', AppFetcher::class); |
|
485 | + $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
|
486 | + |
|
487 | + $this->registerService(\OCP\ICache::class, function ($c) { |
|
488 | + return new Cache\File(); |
|
489 | + }); |
|
490 | + $this->registerAlias('UserCache', \OCP\ICache::class); |
|
491 | + |
|
492 | + $this->registerService(Factory::class, function (Server $c) { |
|
493 | + |
|
494 | + $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
495 | + ArrayCache::class, |
|
496 | + ArrayCache::class, |
|
497 | + ArrayCache::class |
|
498 | + ); |
|
499 | + $config = $c->getConfig(); |
|
500 | + |
|
501 | + if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
502 | + $v = \OC_App::getAppVersions(); |
|
503 | + $v['core'] = implode(',', \OC_Util::getVersion()); |
|
504 | + $version = implode(',', $v); |
|
505 | + $instanceId = \OC_Util::getInstanceId(); |
|
506 | + $path = \OC::$SERVERROOT; |
|
507 | + $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
508 | + return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
509 | + $config->getSystemValue('memcache.local', null), |
|
510 | + $config->getSystemValue('memcache.distributed', null), |
|
511 | + $config->getSystemValue('memcache.locking', null) |
|
512 | + ); |
|
513 | + } |
|
514 | + return $arrayCacheFactory; |
|
515 | + |
|
516 | + }); |
|
517 | + $this->registerAlias('MemCacheFactory', Factory::class); |
|
518 | + $this->registerAlias(ICacheFactory::class, Factory::class); |
|
519 | + |
|
520 | + $this->registerService('RedisFactory', function (Server $c) { |
|
521 | + $systemConfig = $c->getSystemConfig(); |
|
522 | + return new RedisFactory($systemConfig); |
|
523 | + }); |
|
524 | + |
|
525 | + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
526 | + return new \OC\Activity\Manager( |
|
527 | + $c->getRequest(), |
|
528 | + $c->getUserSession(), |
|
529 | + $c->getConfig(), |
|
530 | + $c->query(IValidator::class) |
|
531 | + ); |
|
532 | + }); |
|
533 | + $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
534 | + |
|
535 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
536 | + return new \OC\Activity\EventMerger( |
|
537 | + $c->getL10N('lib') |
|
538 | + ); |
|
539 | + }); |
|
540 | + $this->registerAlias(IValidator::class, Validator::class); |
|
541 | + |
|
542 | + $this->registerService(AvatarManager::class, function(Server $c) { |
|
543 | + return new AvatarManager( |
|
544 | + $c->query(\OC\User\Manager::class), |
|
545 | + $c->getAppDataDir('avatar'), |
|
546 | + $c->getL10N('lib'), |
|
547 | + $c->getLogger(), |
|
548 | + $c->getConfig() |
|
549 | + ); |
|
550 | + }); |
|
551 | + $this->registerAlias(\OCP\IAvatarManager::class, AvatarManager::class); |
|
552 | + $this->registerAlias('AvatarManager', AvatarManager::class); |
|
553 | + |
|
554 | + $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
555 | + $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
|
556 | + |
|
557 | + $this->registerService(\OC\Log::class, function (Server $c) { |
|
558 | + $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
559 | + $factory = new LogFactory($c, $this->getSystemConfig()); |
|
560 | + $logger = $factory->get($logType); |
|
561 | + $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class); |
|
562 | + |
|
563 | + return new Log($logger, $this->getSystemConfig(), null, $registry); |
|
564 | + }); |
|
565 | + $this->registerAlias(\OCP\ILogger::class, \OC\Log::class); |
|
566 | + $this->registerAlias('Logger', \OC\Log::class); |
|
567 | + |
|
568 | + $this->registerService(ILogFactory::class, function (Server $c) { |
|
569 | + return new LogFactory($c, $this->getSystemConfig()); |
|
570 | + }); |
|
571 | + |
|
572 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
573 | + $config = $c->getConfig(); |
|
574 | + return new \OC\BackgroundJob\JobList( |
|
575 | + $c->getDatabaseConnection(), |
|
576 | + $config, |
|
577 | + new TimeFactory() |
|
578 | + ); |
|
579 | + }); |
|
580 | + $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
581 | + |
|
582 | + $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
583 | + $cacheFactory = $c->getMemCacheFactory(); |
|
584 | + $logger = $c->getLogger(); |
|
585 | + if ($cacheFactory->isLocalCacheAvailable()) { |
|
586 | + $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
587 | + } else { |
|
588 | + $router = new \OC\Route\Router($logger); |
|
589 | + } |
|
590 | + return $router; |
|
591 | + }); |
|
592 | + $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
593 | + |
|
594 | + $this->registerService(\OCP\ISearch::class, function ($c) { |
|
595 | + return new Search(); |
|
596 | + }); |
|
597 | + $this->registerAlias('Search', \OCP\ISearch::class); |
|
598 | + |
|
599 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
600 | + return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
601 | + $this->getMemCacheFactory(), |
|
602 | + new \OC\AppFramework\Utility\TimeFactory() |
|
603 | + ); |
|
604 | + }); |
|
605 | + |
|
606 | + $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
607 | + return new SecureRandom(); |
|
608 | + }); |
|
609 | + $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
610 | + |
|
611 | + $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
612 | + return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
613 | + }); |
|
614 | + $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
615 | + |
|
616 | + $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
617 | + return new Hasher($c->getConfig()); |
|
618 | + }); |
|
619 | + $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
620 | + |
|
621 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
622 | + return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
623 | + }); |
|
624 | + $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
625 | + |
|
626 | + $this->registerService(IDBConnection::class, function (Server $c) { |
|
627 | + $systemConfig = $c->getSystemConfig(); |
|
628 | + $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
629 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
630 | + if (!$factory->isValidType($type)) { |
|
631 | + throw new \OC\DatabaseException('Invalid database type'); |
|
632 | + } |
|
633 | + $connectionParams = $factory->createConnectionParams(); |
|
634 | + $connection = $factory->getConnection($type, $connectionParams); |
|
635 | + $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
636 | + return $connection; |
|
637 | + }); |
|
638 | + $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
639 | + |
|
640 | + |
|
641 | + $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
642 | + $user = \OC_User::getUser(); |
|
643 | + $uid = $user ? $user : null; |
|
644 | + return new ClientService( |
|
645 | + $c->getConfig(), |
|
646 | + new \OC\Security\CertificateManager( |
|
647 | + $uid, |
|
648 | + new View(), |
|
649 | + $c->getConfig(), |
|
650 | + $c->getLogger(), |
|
651 | + $c->getSecureRandom() |
|
652 | + ) |
|
653 | + ); |
|
654 | + }); |
|
655 | + $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
656 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
657 | + $eventLogger = new EventLogger(); |
|
658 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
659 | + // In debug mode, module is being activated by default |
|
660 | + $eventLogger->activate(); |
|
661 | + } |
|
662 | + return $eventLogger; |
|
663 | + }); |
|
664 | + $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
665 | + |
|
666 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
667 | + $queryLogger = new QueryLogger(); |
|
668 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
669 | + // In debug mode, module is being activated by default |
|
670 | + $queryLogger->activate(); |
|
671 | + } |
|
672 | + return $queryLogger; |
|
673 | + }); |
|
674 | + $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
675 | + |
|
676 | + $this->registerService(TempManager::class, function (Server $c) { |
|
677 | + return new TempManager( |
|
678 | + $c->getLogger(), |
|
679 | + $c->getConfig() |
|
680 | + ); |
|
681 | + }); |
|
682 | + $this->registerAlias('TempManager', TempManager::class); |
|
683 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
684 | + |
|
685 | + $this->registerService(AppManager::class, function (Server $c) { |
|
686 | + return new \OC\App\AppManager( |
|
687 | + $c->getUserSession(), |
|
688 | + $c->query(\OC\AppConfig::class), |
|
689 | + $c->getGroupManager(), |
|
690 | + $c->getMemCacheFactory(), |
|
691 | + $c->getEventDispatcher(), |
|
692 | + $c->getLogger() |
|
693 | + ); |
|
694 | + }); |
|
695 | + $this->registerAlias('AppManager', AppManager::class); |
|
696 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
697 | + |
|
698 | + $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
699 | + return new DateTimeZone( |
|
700 | + $c->getConfig(), |
|
701 | + $c->getSession() |
|
702 | + ); |
|
703 | + }); |
|
704 | + $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
705 | + |
|
706 | + $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
707 | + $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
708 | + |
|
709 | + return new DateTimeFormatter( |
|
710 | + $c->getDateTimeZone()->getTimeZone(), |
|
711 | + $c->getL10N('lib', $language) |
|
712 | + ); |
|
713 | + }); |
|
714 | + $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
715 | + |
|
716 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
717 | + $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
718 | + $listener = new UserMountCacheListener($mountCache); |
|
719 | + $listener->listen($c->getUserManager()); |
|
720 | + return $mountCache; |
|
721 | + }); |
|
722 | + $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
723 | + |
|
724 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
725 | + $loader = \OC\Files\Filesystem::getLoader(); |
|
726 | + $mountCache = $c->query('UserMountCache'); |
|
727 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
728 | + |
|
729 | + // builtin providers |
|
730 | + |
|
731 | + $config = $c->getConfig(); |
|
732 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
733 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
734 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
735 | + |
|
736 | + return $manager; |
|
737 | + }); |
|
738 | + $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
739 | + |
|
740 | + $this->registerService('IniWrapper', function ($c) { |
|
741 | + return new IniGetWrapper(); |
|
742 | + }); |
|
743 | + $this->registerService('AsyncCommandBus', function (Server $c) { |
|
744 | + $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
745 | + if ($busClass) { |
|
746 | + list($app, $class) = explode('::', $busClass, 2); |
|
747 | + if ($c->getAppManager()->isInstalled($app)) { |
|
748 | + \OC_App::loadApp($app); |
|
749 | + return $c->query($class); |
|
750 | + } else { |
|
751 | + throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
752 | + } |
|
753 | + } else { |
|
754 | + $jobList = $c->getJobList(); |
|
755 | + return new CronBus($jobList); |
|
756 | + } |
|
757 | + }); |
|
758 | + $this->registerService('TrustedDomainHelper', function ($c) { |
|
759 | + return new TrustedDomainHelper($this->getConfig()); |
|
760 | + }); |
|
761 | + $this->registerService(Throttler::class, function (Server $c) { |
|
762 | + return new Throttler( |
|
763 | + $c->getDatabaseConnection(), |
|
764 | + new TimeFactory(), |
|
765 | + $c->getLogger(), |
|
766 | + $c->getConfig() |
|
767 | + ); |
|
768 | + }); |
|
769 | + $this->registerAlias('Throttler', Throttler::class); |
|
770 | + $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
771 | + // IConfig and IAppManager requires a working database. This code |
|
772 | + // might however be called when ownCloud is not yet setup. |
|
773 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
774 | + $config = $c->getConfig(); |
|
775 | + $appManager = $c->getAppManager(); |
|
776 | + } else { |
|
777 | + $config = null; |
|
778 | + $appManager = null; |
|
779 | + } |
|
780 | + |
|
781 | + return new Checker( |
|
782 | + new EnvironmentHelper(), |
|
783 | + new FileAccessHelper(), |
|
784 | + new AppLocator(), |
|
785 | + $config, |
|
786 | + $c->getMemCacheFactory(), |
|
787 | + $appManager, |
|
788 | + $c->getTempManager(), |
|
789 | + $c->getMimeTypeDetector() |
|
790 | + ); |
|
791 | + }); |
|
792 | + $this->registerService(\OCP\IRequest::class, function ($c) { |
|
793 | + if (isset($this['urlParams'])) { |
|
794 | + $urlParams = $this['urlParams']; |
|
795 | + } else { |
|
796 | + $urlParams = []; |
|
797 | + } |
|
798 | + |
|
799 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
800 | + && in_array('fakeinput', stream_get_wrappers()) |
|
801 | + ) { |
|
802 | + $stream = 'fakeinput://data'; |
|
803 | + } else { |
|
804 | + $stream = 'php://input'; |
|
805 | + } |
|
806 | + |
|
807 | + return new Request( |
|
808 | + [ |
|
809 | + 'get' => $_GET, |
|
810 | + 'post' => $_POST, |
|
811 | + 'files' => $_FILES, |
|
812 | + 'server' => $_SERVER, |
|
813 | + 'env' => $_ENV, |
|
814 | + 'cookies' => $_COOKIE, |
|
815 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
816 | + ? $_SERVER['REQUEST_METHOD'] |
|
817 | + : '', |
|
818 | + 'urlParams' => $urlParams, |
|
819 | + ], |
|
820 | + $this->getSecureRandom(), |
|
821 | + $this->getConfig(), |
|
822 | + $this->getCsrfTokenManager(), |
|
823 | + $stream |
|
824 | + ); |
|
825 | + }); |
|
826 | + $this->registerAlias('Request', \OCP\IRequest::class); |
|
827 | + |
|
828 | + $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
829 | + return new Mailer( |
|
830 | + $c->getConfig(), |
|
831 | + $c->getLogger(), |
|
832 | + $c->query(Defaults::class), |
|
833 | + $c->getURLGenerator(), |
|
834 | + $c->getL10N('lib') |
|
835 | + ); |
|
836 | + }); |
|
837 | + $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
838 | + |
|
839 | + $this->registerService('LDAPProvider', function (Server $c) { |
|
840 | + $config = $c->getConfig(); |
|
841 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
842 | + if (is_null($factoryClass)) { |
|
843 | + throw new \Exception('ldapProviderFactory not set'); |
|
844 | + } |
|
845 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
846 | + $factory = new $factoryClass($this); |
|
847 | + return $factory->getLDAPProvider(); |
|
848 | + }); |
|
849 | + $this->registerService(ILockingProvider::class, function (Server $c) { |
|
850 | + $ini = $c->getIniWrapper(); |
|
851 | + $config = $c->getConfig(); |
|
852 | + $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
853 | + if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
854 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
855 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
856 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
857 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
858 | + return new MemcacheLockingProvider($memcache, $ttl); |
|
859 | + } |
|
860 | + return new DBLockingProvider( |
|
861 | + $c->getDatabaseConnection(), |
|
862 | + $c->getLogger(), |
|
863 | + new TimeFactory(), |
|
864 | + $ttl, |
|
865 | + !\OC::$CLI |
|
866 | + ); |
|
867 | + } |
|
868 | + return new NoopLockingProvider(); |
|
869 | + }); |
|
870 | + $this->registerAlias('LockingProvider', ILockingProvider::class); |
|
871 | + |
|
872 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
873 | + return new \OC\Files\Mount\Manager(); |
|
874 | + }); |
|
875 | + $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
876 | + |
|
877 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
878 | + return new \OC\Files\Type\Detection( |
|
879 | + $c->getURLGenerator(), |
|
880 | + \OC::$configDir, |
|
881 | + \OC::$SERVERROOT . '/resources/config/' |
|
882 | + ); |
|
883 | + }); |
|
884 | + $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
885 | + |
|
886 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
887 | + return new \OC\Files\Type\Loader( |
|
888 | + $c->getDatabaseConnection() |
|
889 | + ); |
|
890 | + }); |
|
891 | + $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
892 | + $this->registerService(BundleFetcher::class, function () { |
|
893 | + return new BundleFetcher($this->getL10N('lib')); |
|
894 | + }); |
|
895 | + $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
896 | + return new Manager( |
|
897 | + $c->query(IValidator::class), |
|
898 | + $c->getLogger() |
|
899 | + ); |
|
900 | + }); |
|
901 | + $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
902 | + |
|
903 | + $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
904 | + $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
905 | + $manager->registerCapability(function () use ($c) { |
|
906 | + return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
907 | + }); |
|
908 | + $manager->registerCapability(function () use ($c) { |
|
909 | + return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
910 | + }); |
|
911 | + return $manager; |
|
912 | + }); |
|
913 | + $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
914 | + |
|
915 | + $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
916 | + $config = $c->getConfig(); |
|
917 | + $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
918 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
919 | + $factory = new $factoryClass($this); |
|
920 | + $manager = $factory->getManager(); |
|
921 | + |
|
922 | + $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
|
923 | + $manager = $c->getUserManager(); |
|
924 | + $user = $manager->get($id); |
|
925 | + if(is_null($user)) { |
|
926 | + $l = $c->getL10N('core'); |
|
927 | + $displayName = $l->t('Unknown user'); |
|
928 | + } else { |
|
929 | + $displayName = $user->getDisplayName(); |
|
930 | + } |
|
931 | + return $displayName; |
|
932 | + }); |
|
933 | + |
|
934 | + return $manager; |
|
935 | + }); |
|
936 | + $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
937 | + |
|
938 | + $this->registerService('ThemingDefaults', function (Server $c) { |
|
939 | + /* |
|
940 | 940 | * Dark magic for autoloader. |
941 | 941 | * If we do a class_exists it will try to load the class which will |
942 | 942 | * make composer cache the result. Resulting in errors when enabling |
943 | 943 | * the theming app. |
944 | 944 | */ |
945 | - $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
946 | - if (isset($prefixes['OCA\\Theming\\'])) { |
|
947 | - $classExists = true; |
|
948 | - } else { |
|
949 | - $classExists = false; |
|
950 | - } |
|
951 | - |
|
952 | - if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
953 | - return new ThemingDefaults( |
|
954 | - $c->getConfig(), |
|
955 | - $c->getL10N('theming'), |
|
956 | - $c->getURLGenerator(), |
|
957 | - $c->getMemCacheFactory(), |
|
958 | - new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')), |
|
959 | - new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory(), $this->getLogger()), |
|
960 | - $c->getAppManager(), |
|
961 | - $c->getNavigationManager() |
|
962 | - ); |
|
963 | - } |
|
964 | - return new \OC_Defaults(); |
|
965 | - }); |
|
966 | - $this->registerService(SCSSCacher::class, function (Server $c) { |
|
967 | - return new SCSSCacher( |
|
968 | - $c->getLogger(), |
|
969 | - $c->query(\OC\Files\AppData\Factory::class), |
|
970 | - $c->getURLGenerator(), |
|
971 | - $c->getConfig(), |
|
972 | - $c->getThemingDefaults(), |
|
973 | - \OC::$SERVERROOT, |
|
974 | - $this->getMemCacheFactory(), |
|
975 | - $c->query(IconsCacher::class), |
|
976 | - new TimeFactory() |
|
977 | - ); |
|
978 | - }); |
|
979 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
980 | - return new JSCombiner( |
|
981 | - $c->getAppDataDir('js'), |
|
982 | - $c->getURLGenerator(), |
|
983 | - $this->getMemCacheFactory(), |
|
984 | - $c->getSystemConfig(), |
|
985 | - $c->getLogger() |
|
986 | - ); |
|
987 | - }); |
|
988 | - $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
|
989 | - $this->registerAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class); |
|
990 | - $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class); |
|
991 | - |
|
992 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
993 | - // FIXME: Instantiiated here due to cyclic dependency |
|
994 | - $request = new Request( |
|
995 | - [ |
|
996 | - 'get' => $_GET, |
|
997 | - 'post' => $_POST, |
|
998 | - 'files' => $_FILES, |
|
999 | - 'server' => $_SERVER, |
|
1000 | - 'env' => $_ENV, |
|
1001 | - 'cookies' => $_COOKIE, |
|
1002 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
1003 | - ? $_SERVER['REQUEST_METHOD'] |
|
1004 | - : null, |
|
1005 | - ], |
|
1006 | - $c->getSecureRandom(), |
|
1007 | - $c->getConfig() |
|
1008 | - ); |
|
1009 | - |
|
1010 | - return new CryptoWrapper( |
|
1011 | - $c->getConfig(), |
|
1012 | - $c->getCrypto(), |
|
1013 | - $c->getSecureRandom(), |
|
1014 | - $request |
|
1015 | - ); |
|
1016 | - }); |
|
1017 | - $this->registerService(CsrfTokenManager::class, function (Server $c) { |
|
1018 | - $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
1019 | - |
|
1020 | - return new CsrfTokenManager( |
|
1021 | - $tokenGenerator, |
|
1022 | - $c->query(SessionStorage::class) |
|
1023 | - ); |
|
1024 | - }); |
|
1025 | - $this->registerAlias('CsrfTokenManager', CsrfTokenManager::class); |
|
1026 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
1027 | - return new SessionStorage($c->getSession()); |
|
1028 | - }); |
|
1029 | - $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, \OC\Security\CSP\ContentSecurityPolicyManager::class); |
|
1030 | - $this->registerAlias('ContentSecurityPolicyManager', \OC\Security\CSP\ContentSecurityPolicyManager::class); |
|
1031 | - |
|
1032 | - $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
1033 | - return new ContentSecurityPolicyNonceManager( |
|
1034 | - $c->getCsrfTokenManager(), |
|
1035 | - $c->getRequest() |
|
1036 | - ); |
|
1037 | - }); |
|
1038 | - |
|
1039 | - $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
1040 | - $config = $c->getConfig(); |
|
1041 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
1042 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
1043 | - $factory = new $factoryClass($this); |
|
1044 | - |
|
1045 | - $manager = new \OC\Share20\Manager( |
|
1046 | - $c->getLogger(), |
|
1047 | - $c->getConfig(), |
|
1048 | - $c->getSecureRandom(), |
|
1049 | - $c->getHasher(), |
|
1050 | - $c->getMountManager(), |
|
1051 | - $c->getGroupManager(), |
|
1052 | - $c->getL10N('lib'), |
|
1053 | - $c->getL10NFactory(), |
|
1054 | - $factory, |
|
1055 | - $c->getUserManager(), |
|
1056 | - $c->getLazyRootFolder(), |
|
1057 | - $c->getEventDispatcher(), |
|
1058 | - $c->getMailer(), |
|
1059 | - $c->getURLGenerator(), |
|
1060 | - $c->getThemingDefaults() |
|
1061 | - ); |
|
1062 | - |
|
1063 | - return $manager; |
|
1064 | - }); |
|
1065 | - $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
1066 | - |
|
1067 | - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
|
1068 | - $instance = new Collaboration\Collaborators\Search($c); |
|
1069 | - |
|
1070 | - // register default plugins |
|
1071 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
1072 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
1073 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
1074 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
1075 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
1076 | - |
|
1077 | - return $instance; |
|
1078 | - }); |
|
1079 | - $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
1080 | - $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
1081 | - |
|
1082 | - $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
1083 | - |
|
1084 | - $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
1085 | - |
|
1086 | - $this->registerService('SettingsManager', function (Server $c) { |
|
1087 | - $manager = new \OC\Settings\Manager( |
|
1088 | - $c->getLogger(), |
|
1089 | - $c->getL10NFactory(), |
|
1090 | - $c->getURLGenerator(), |
|
1091 | - $c |
|
1092 | - ); |
|
1093 | - return $manager; |
|
1094 | - }); |
|
1095 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1096 | - return new \OC\Files\AppData\Factory( |
|
1097 | - $c->getRootFolder(), |
|
1098 | - $c->getSystemConfig() |
|
1099 | - ); |
|
1100 | - }); |
|
1101 | - |
|
1102 | - $this->registerService('LockdownManager', function (Server $c) { |
|
1103 | - return new LockdownManager(function () use ($c) { |
|
1104 | - return $c->getSession(); |
|
1105 | - }); |
|
1106 | - }); |
|
1107 | - |
|
1108 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1109 | - return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
1110 | - }); |
|
1111 | - |
|
1112 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1113 | - return new CloudIdManager(); |
|
1114 | - }); |
|
1115 | - |
|
1116 | - $this->registerService(IConfig::class, function (Server $c) { |
|
1117 | - return new GlobalScale\Config($c->getConfig()); |
|
1118 | - }); |
|
1119 | - |
|
1120 | - $this->registerService(ICloudFederationProviderManager::class, function (Server $c) { |
|
1121 | - return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger()); |
|
1122 | - }); |
|
1123 | - |
|
1124 | - $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
1125 | - return new CloudFederationFactory(); |
|
1126 | - }); |
|
1127 | - |
|
1128 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1129 | - $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1130 | - |
|
1131 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1132 | - $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1133 | - |
|
1134 | - $this->registerService(Defaults::class, function (Server $c) { |
|
1135 | - return new Defaults( |
|
1136 | - $c->getThemingDefaults() |
|
1137 | - ); |
|
1138 | - }); |
|
1139 | - $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
1140 | - |
|
1141 | - $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1142 | - return $c->query(\OCP\IUserSession::class)->getSession(); |
|
1143 | - }); |
|
1144 | - |
|
1145 | - $this->registerService(IShareHelper::class, function (Server $c) { |
|
1146 | - return new ShareHelper( |
|
1147 | - $c->query(\OCP\Share\IManager::class) |
|
1148 | - ); |
|
1149 | - }); |
|
1150 | - |
|
1151 | - $this->registerService(Installer::class, function(Server $c) { |
|
1152 | - return new Installer( |
|
1153 | - $c->getAppFetcher(), |
|
1154 | - $c->getHTTPClientService(), |
|
1155 | - $c->getTempManager(), |
|
1156 | - $c->getLogger(), |
|
1157 | - $c->getConfig() |
|
1158 | - ); |
|
1159 | - }); |
|
1160 | - |
|
1161 | - $this->registerService(IApiFactory::class, function(Server $c) { |
|
1162 | - return new ApiFactory($c->getHTTPClientService()); |
|
1163 | - }); |
|
1164 | - |
|
1165 | - $this->registerService(IInstanceFactory::class, function(Server $c) { |
|
1166 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
1167 | - return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); |
|
1168 | - }); |
|
1169 | - |
|
1170 | - $this->registerService(IContactsStore::class, function(Server $c) { |
|
1171 | - return new ContactsStore( |
|
1172 | - $c->getContactsManager(), |
|
1173 | - $c->getConfig(), |
|
1174 | - $c->getUserManager(), |
|
1175 | - $c->getGroupManager() |
|
1176 | - ); |
|
1177 | - }); |
|
1178 | - $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
1179 | - $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
1180 | - |
|
1181 | - $this->registerService(IStorageFactory::class, function() { |
|
1182 | - return new StorageFactory(); |
|
1183 | - }); |
|
1184 | - |
|
1185 | - $this->registerAlias(IDashboardManager::class, DashboardManager::class); |
|
1186 | - $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
1187 | - |
|
1188 | - $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
1189 | - |
|
1190 | - $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
1191 | - |
|
1192 | - $this->connectDispatcher(); |
|
1193 | - } |
|
1194 | - |
|
1195 | - /** |
|
1196 | - * @return \OCP\Calendar\IManager |
|
1197 | - */ |
|
1198 | - public function getCalendarManager() { |
|
1199 | - return $this->query('CalendarManager'); |
|
1200 | - } |
|
1201 | - |
|
1202 | - /** |
|
1203 | - * @return \OCP\Calendar\Resource\IManager |
|
1204 | - */ |
|
1205 | - public function getCalendarResourceBackendManager() { |
|
1206 | - return $this->query('CalendarResourceBackendManager'); |
|
1207 | - } |
|
1208 | - |
|
1209 | - /** |
|
1210 | - * @return \OCP\Calendar\Room\IManager |
|
1211 | - */ |
|
1212 | - public function getCalendarRoomBackendManager() { |
|
1213 | - return $this->query('CalendarRoomBackendManager'); |
|
1214 | - } |
|
1215 | - |
|
1216 | - private function connectDispatcher() { |
|
1217 | - $dispatcher = $this->getEventDispatcher(); |
|
1218 | - |
|
1219 | - // Delete avatar on user deletion |
|
1220 | - $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) { |
|
1221 | - $logger = $this->getLogger(); |
|
1222 | - $manager = $this->getAvatarManager(); |
|
1223 | - /** @var IUser $user */ |
|
1224 | - $user = $e->getSubject(); |
|
1225 | - |
|
1226 | - try { |
|
1227 | - $avatar = $manager->getAvatar($user->getUID()); |
|
1228 | - $avatar->remove(); |
|
1229 | - } catch (NotFoundException $e) { |
|
1230 | - // no avatar to remove |
|
1231 | - } catch (\Exception $e) { |
|
1232 | - // Ignore exceptions |
|
1233 | - $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1234 | - } |
|
1235 | - }); |
|
1236 | - |
|
1237 | - $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1238 | - $manager = $this->getAvatarManager(); |
|
1239 | - /** @var IUser $user */ |
|
1240 | - $user = $e->getSubject(); |
|
1241 | - $feature = $e->getArgument('feature'); |
|
1242 | - $oldValue = $e->getArgument('oldValue'); |
|
1243 | - $value = $e->getArgument('value'); |
|
1244 | - |
|
1245 | - // We only change the avatar on display name changes |
|
1246 | - if ($feature !== 'displayName') { |
|
1247 | - return; |
|
1248 | - } |
|
1249 | - |
|
1250 | - try { |
|
1251 | - $avatar = $manager->getAvatar($user->getUID()); |
|
1252 | - $avatar->userChanged($feature, $oldValue, $value); |
|
1253 | - } catch (NotFoundException $e) { |
|
1254 | - // no avatar to remove |
|
1255 | - } |
|
1256 | - }); |
|
1257 | - } |
|
1258 | - |
|
1259 | - /** |
|
1260 | - * @return \OCP\Contacts\IManager |
|
1261 | - */ |
|
1262 | - public function getContactsManager() { |
|
1263 | - return $this->query('ContactsManager'); |
|
1264 | - } |
|
1265 | - |
|
1266 | - /** |
|
1267 | - * @return \OC\Encryption\Manager |
|
1268 | - */ |
|
1269 | - public function getEncryptionManager() { |
|
1270 | - return $this->query('EncryptionManager'); |
|
1271 | - } |
|
1272 | - |
|
1273 | - /** |
|
1274 | - * @return \OC\Encryption\File |
|
1275 | - */ |
|
1276 | - public function getEncryptionFilesHelper() { |
|
1277 | - return $this->query('EncryptionFileHelper'); |
|
1278 | - } |
|
1279 | - |
|
1280 | - /** |
|
1281 | - * @return \OCP\Encryption\Keys\IStorage |
|
1282 | - */ |
|
1283 | - public function getEncryptionKeyStorage() { |
|
1284 | - return $this->query('EncryptionKeyStorage'); |
|
1285 | - } |
|
1286 | - |
|
1287 | - /** |
|
1288 | - * The current request object holding all information about the request |
|
1289 | - * currently being processed is returned from this method. |
|
1290 | - * In case the current execution was not initiated by a web request null is returned |
|
1291 | - * |
|
1292 | - * @return \OCP\IRequest |
|
1293 | - */ |
|
1294 | - public function getRequest() { |
|
1295 | - return $this->query('Request'); |
|
1296 | - } |
|
1297 | - |
|
1298 | - /** |
|
1299 | - * Returns the preview manager which can create preview images for a given file |
|
1300 | - * |
|
1301 | - * @return \OCP\IPreview |
|
1302 | - */ |
|
1303 | - public function getPreviewManager() { |
|
1304 | - return $this->query('PreviewManager'); |
|
1305 | - } |
|
1306 | - |
|
1307 | - /** |
|
1308 | - * Returns the tag manager which can get and set tags for different object types |
|
1309 | - * |
|
1310 | - * @see \OCP\ITagManager::load() |
|
1311 | - * @return \OCP\ITagManager |
|
1312 | - */ |
|
1313 | - public function getTagManager() { |
|
1314 | - return $this->query('TagManager'); |
|
1315 | - } |
|
1316 | - |
|
1317 | - /** |
|
1318 | - * Returns the system-tag manager |
|
1319 | - * |
|
1320 | - * @return \OCP\SystemTag\ISystemTagManager |
|
1321 | - * |
|
1322 | - * @since 9.0.0 |
|
1323 | - */ |
|
1324 | - public function getSystemTagManager() { |
|
1325 | - return $this->query('SystemTagManager'); |
|
1326 | - } |
|
1327 | - |
|
1328 | - /** |
|
1329 | - * Returns the system-tag object mapper |
|
1330 | - * |
|
1331 | - * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
1332 | - * |
|
1333 | - * @since 9.0.0 |
|
1334 | - */ |
|
1335 | - public function getSystemTagObjectMapper() { |
|
1336 | - return $this->query('SystemTagObjectMapper'); |
|
1337 | - } |
|
1338 | - |
|
1339 | - /** |
|
1340 | - * Returns the avatar manager, used for avatar functionality |
|
1341 | - * |
|
1342 | - * @return \OCP\IAvatarManager |
|
1343 | - */ |
|
1344 | - public function getAvatarManager() { |
|
1345 | - return $this->query('AvatarManager'); |
|
1346 | - } |
|
1347 | - |
|
1348 | - /** |
|
1349 | - * Returns the root folder of ownCloud's data directory |
|
1350 | - * |
|
1351 | - * @return \OCP\Files\IRootFolder |
|
1352 | - */ |
|
1353 | - public function getRootFolder() { |
|
1354 | - return $this->query('LazyRootFolder'); |
|
1355 | - } |
|
1356 | - |
|
1357 | - /** |
|
1358 | - * Returns the root folder of ownCloud's data directory |
|
1359 | - * This is the lazy variant so this gets only initialized once it |
|
1360 | - * is actually used. |
|
1361 | - * |
|
1362 | - * @return \OCP\Files\IRootFolder |
|
1363 | - */ |
|
1364 | - public function getLazyRootFolder() { |
|
1365 | - return $this->query('LazyRootFolder'); |
|
1366 | - } |
|
1367 | - |
|
1368 | - /** |
|
1369 | - * Returns a view to ownCloud's files folder |
|
1370 | - * |
|
1371 | - * @param string $userId user ID |
|
1372 | - * @return \OCP\Files\Folder|null |
|
1373 | - */ |
|
1374 | - public function getUserFolder($userId = null) { |
|
1375 | - if ($userId === null) { |
|
1376 | - $user = $this->getUserSession()->getUser(); |
|
1377 | - if (!$user) { |
|
1378 | - return null; |
|
1379 | - } |
|
1380 | - $userId = $user->getUID(); |
|
1381 | - } |
|
1382 | - $root = $this->getRootFolder(); |
|
1383 | - return $root->getUserFolder($userId); |
|
1384 | - } |
|
1385 | - |
|
1386 | - /** |
|
1387 | - * Returns an app-specific view in ownClouds data directory |
|
1388 | - * |
|
1389 | - * @return \OCP\Files\Folder |
|
1390 | - * @deprecated since 9.2.0 use IAppData |
|
1391 | - */ |
|
1392 | - public function getAppFolder() { |
|
1393 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
1394 | - $root = $this->getRootFolder(); |
|
1395 | - if (!$root->nodeExists($dir)) { |
|
1396 | - $folder = $root->newFolder($dir); |
|
1397 | - } else { |
|
1398 | - $folder = $root->get($dir); |
|
1399 | - } |
|
1400 | - return $folder; |
|
1401 | - } |
|
1402 | - |
|
1403 | - /** |
|
1404 | - * @return \OC\User\Manager |
|
1405 | - */ |
|
1406 | - public function getUserManager() { |
|
1407 | - return $this->query('UserManager'); |
|
1408 | - } |
|
1409 | - |
|
1410 | - /** |
|
1411 | - * @return \OC\Group\Manager |
|
1412 | - */ |
|
1413 | - public function getGroupManager() { |
|
1414 | - return $this->query('GroupManager'); |
|
1415 | - } |
|
1416 | - |
|
1417 | - /** |
|
1418 | - * @return \OC\User\Session |
|
1419 | - */ |
|
1420 | - public function getUserSession() { |
|
1421 | - return $this->query('UserSession'); |
|
1422 | - } |
|
1423 | - |
|
1424 | - /** |
|
1425 | - * @return \OCP\ISession |
|
1426 | - */ |
|
1427 | - public function getSession() { |
|
1428 | - return $this->query('UserSession')->getSession(); |
|
1429 | - } |
|
1430 | - |
|
1431 | - /** |
|
1432 | - * @param \OCP\ISession $session |
|
1433 | - */ |
|
1434 | - public function setSession(\OCP\ISession $session) { |
|
1435 | - $this->query(SessionStorage::class)->setSession($session); |
|
1436 | - $this->query('UserSession')->setSession($session); |
|
1437 | - $this->query(Store::class)->setSession($session); |
|
1438 | - } |
|
1439 | - |
|
1440 | - /** |
|
1441 | - * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1442 | - */ |
|
1443 | - public function getTwoFactorAuthManager() { |
|
1444 | - return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
1445 | - } |
|
1446 | - |
|
1447 | - /** |
|
1448 | - * @return \OC\NavigationManager |
|
1449 | - */ |
|
1450 | - public function getNavigationManager() { |
|
1451 | - return $this->query('NavigationManager'); |
|
1452 | - } |
|
1453 | - |
|
1454 | - /** |
|
1455 | - * @return \OCP\IConfig |
|
1456 | - */ |
|
1457 | - public function getConfig() { |
|
1458 | - return $this->query('AllConfig'); |
|
1459 | - } |
|
1460 | - |
|
1461 | - /** |
|
1462 | - * @return \OC\SystemConfig |
|
1463 | - */ |
|
1464 | - public function getSystemConfig() { |
|
1465 | - return $this->query('SystemConfig'); |
|
1466 | - } |
|
1467 | - |
|
1468 | - /** |
|
1469 | - * Returns the app config manager |
|
1470 | - * |
|
1471 | - * @return \OCP\IAppConfig |
|
1472 | - */ |
|
1473 | - public function getAppConfig() { |
|
1474 | - return $this->query('AppConfig'); |
|
1475 | - } |
|
1476 | - |
|
1477 | - /** |
|
1478 | - * @return \OCP\L10N\IFactory |
|
1479 | - */ |
|
1480 | - public function getL10NFactory() { |
|
1481 | - return $this->query('L10NFactory'); |
|
1482 | - } |
|
1483 | - |
|
1484 | - /** |
|
1485 | - * get an L10N instance |
|
1486 | - * |
|
1487 | - * @param string $app appid |
|
1488 | - * @param string $lang |
|
1489 | - * @return IL10N |
|
1490 | - */ |
|
1491 | - public function getL10N($app, $lang = null) { |
|
1492 | - return $this->getL10NFactory()->get($app, $lang); |
|
1493 | - } |
|
1494 | - |
|
1495 | - /** |
|
1496 | - * @return \OCP\IURLGenerator |
|
1497 | - */ |
|
1498 | - public function getURLGenerator() { |
|
1499 | - return $this->query('URLGenerator'); |
|
1500 | - } |
|
1501 | - |
|
1502 | - /** |
|
1503 | - * @return AppFetcher |
|
1504 | - */ |
|
1505 | - public function getAppFetcher() { |
|
1506 | - return $this->query(AppFetcher::class); |
|
1507 | - } |
|
1508 | - |
|
1509 | - /** |
|
1510 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1511 | - * getMemCacheFactory() instead. |
|
1512 | - * |
|
1513 | - * @return \OCP\ICache |
|
1514 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1515 | - */ |
|
1516 | - public function getCache() { |
|
1517 | - return $this->query('UserCache'); |
|
1518 | - } |
|
1519 | - |
|
1520 | - /** |
|
1521 | - * Returns an \OCP\CacheFactory instance |
|
1522 | - * |
|
1523 | - * @return \OCP\ICacheFactory |
|
1524 | - */ |
|
1525 | - public function getMemCacheFactory() { |
|
1526 | - return $this->query('MemCacheFactory'); |
|
1527 | - } |
|
1528 | - |
|
1529 | - /** |
|
1530 | - * Returns an \OC\RedisFactory instance |
|
1531 | - * |
|
1532 | - * @return \OC\RedisFactory |
|
1533 | - */ |
|
1534 | - public function getGetRedisFactory() { |
|
1535 | - return $this->query('RedisFactory'); |
|
1536 | - } |
|
1537 | - |
|
1538 | - |
|
1539 | - /** |
|
1540 | - * Returns the current session |
|
1541 | - * |
|
1542 | - * @return \OCP\IDBConnection |
|
1543 | - */ |
|
1544 | - public function getDatabaseConnection() { |
|
1545 | - return $this->query('DatabaseConnection'); |
|
1546 | - } |
|
1547 | - |
|
1548 | - /** |
|
1549 | - * Returns the activity manager |
|
1550 | - * |
|
1551 | - * @return \OCP\Activity\IManager |
|
1552 | - */ |
|
1553 | - public function getActivityManager() { |
|
1554 | - return $this->query('ActivityManager'); |
|
1555 | - } |
|
1556 | - |
|
1557 | - /** |
|
1558 | - * Returns an job list for controlling background jobs |
|
1559 | - * |
|
1560 | - * @return \OCP\BackgroundJob\IJobList |
|
1561 | - */ |
|
1562 | - public function getJobList() { |
|
1563 | - return $this->query('JobList'); |
|
1564 | - } |
|
1565 | - |
|
1566 | - /** |
|
1567 | - * Returns a logger instance |
|
1568 | - * |
|
1569 | - * @return \OCP\ILogger |
|
1570 | - */ |
|
1571 | - public function getLogger() { |
|
1572 | - return $this->query('Logger'); |
|
1573 | - } |
|
1574 | - |
|
1575 | - /** |
|
1576 | - * @return ILogFactory |
|
1577 | - * @throws \OCP\AppFramework\QueryException |
|
1578 | - */ |
|
1579 | - public function getLogFactory() { |
|
1580 | - return $this->query(ILogFactory::class); |
|
1581 | - } |
|
1582 | - |
|
1583 | - /** |
|
1584 | - * Returns a router for generating and matching urls |
|
1585 | - * |
|
1586 | - * @return \OCP\Route\IRouter |
|
1587 | - */ |
|
1588 | - public function getRouter() { |
|
1589 | - return $this->query('Router'); |
|
1590 | - } |
|
1591 | - |
|
1592 | - /** |
|
1593 | - * Returns a search instance |
|
1594 | - * |
|
1595 | - * @return \OCP\ISearch |
|
1596 | - */ |
|
1597 | - public function getSearch() { |
|
1598 | - return $this->query('Search'); |
|
1599 | - } |
|
1600 | - |
|
1601 | - /** |
|
1602 | - * Returns a SecureRandom instance |
|
1603 | - * |
|
1604 | - * @return \OCP\Security\ISecureRandom |
|
1605 | - */ |
|
1606 | - public function getSecureRandom() { |
|
1607 | - return $this->query('SecureRandom'); |
|
1608 | - } |
|
1609 | - |
|
1610 | - /** |
|
1611 | - * Returns a Crypto instance |
|
1612 | - * |
|
1613 | - * @return \OCP\Security\ICrypto |
|
1614 | - */ |
|
1615 | - public function getCrypto() { |
|
1616 | - return $this->query('Crypto'); |
|
1617 | - } |
|
1618 | - |
|
1619 | - /** |
|
1620 | - * Returns a Hasher instance |
|
1621 | - * |
|
1622 | - * @return \OCP\Security\IHasher |
|
1623 | - */ |
|
1624 | - public function getHasher() { |
|
1625 | - return $this->query('Hasher'); |
|
1626 | - } |
|
1627 | - |
|
1628 | - /** |
|
1629 | - * Returns a CredentialsManager instance |
|
1630 | - * |
|
1631 | - * @return \OCP\Security\ICredentialsManager |
|
1632 | - */ |
|
1633 | - public function getCredentialsManager() { |
|
1634 | - return $this->query('CredentialsManager'); |
|
1635 | - } |
|
1636 | - |
|
1637 | - /** |
|
1638 | - * Get the certificate manager for the user |
|
1639 | - * |
|
1640 | - * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1641 | - * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1642 | - */ |
|
1643 | - public function getCertificateManager($userId = '') { |
|
1644 | - if ($userId === '') { |
|
1645 | - $userSession = $this->getUserSession(); |
|
1646 | - $user = $userSession->getUser(); |
|
1647 | - if (is_null($user)) { |
|
1648 | - return null; |
|
1649 | - } |
|
1650 | - $userId = $user->getUID(); |
|
1651 | - } |
|
1652 | - return new CertificateManager( |
|
1653 | - $userId, |
|
1654 | - new View(), |
|
1655 | - $this->getConfig(), |
|
1656 | - $this->getLogger(), |
|
1657 | - $this->getSecureRandom() |
|
1658 | - ); |
|
1659 | - } |
|
1660 | - |
|
1661 | - /** |
|
1662 | - * Returns an instance of the HTTP client service |
|
1663 | - * |
|
1664 | - * @return \OCP\Http\Client\IClientService |
|
1665 | - */ |
|
1666 | - public function getHTTPClientService() { |
|
1667 | - return $this->query('HttpClientService'); |
|
1668 | - } |
|
1669 | - |
|
1670 | - /** |
|
1671 | - * Create a new event source |
|
1672 | - * |
|
1673 | - * @return \OCP\IEventSource |
|
1674 | - */ |
|
1675 | - public function createEventSource() { |
|
1676 | - return new \OC_EventSource(); |
|
1677 | - } |
|
1678 | - |
|
1679 | - /** |
|
1680 | - * Get the active event logger |
|
1681 | - * |
|
1682 | - * The returned logger only logs data when debug mode is enabled |
|
1683 | - * |
|
1684 | - * @return \OCP\Diagnostics\IEventLogger |
|
1685 | - */ |
|
1686 | - public function getEventLogger() { |
|
1687 | - return $this->query('EventLogger'); |
|
1688 | - } |
|
1689 | - |
|
1690 | - /** |
|
1691 | - * Get the active query logger |
|
1692 | - * |
|
1693 | - * The returned logger only logs data when debug mode is enabled |
|
1694 | - * |
|
1695 | - * @return \OCP\Diagnostics\IQueryLogger |
|
1696 | - */ |
|
1697 | - public function getQueryLogger() { |
|
1698 | - return $this->query('QueryLogger'); |
|
1699 | - } |
|
1700 | - |
|
1701 | - /** |
|
1702 | - * Get the manager for temporary files and folders |
|
1703 | - * |
|
1704 | - * @return \OCP\ITempManager |
|
1705 | - */ |
|
1706 | - public function getTempManager() { |
|
1707 | - return $this->query('TempManager'); |
|
1708 | - } |
|
1709 | - |
|
1710 | - /** |
|
1711 | - * Get the app manager |
|
1712 | - * |
|
1713 | - * @return \OCP\App\IAppManager |
|
1714 | - */ |
|
1715 | - public function getAppManager() { |
|
1716 | - return $this->query('AppManager'); |
|
1717 | - } |
|
1718 | - |
|
1719 | - /** |
|
1720 | - * Creates a new mailer |
|
1721 | - * |
|
1722 | - * @return \OCP\Mail\IMailer |
|
1723 | - */ |
|
1724 | - public function getMailer() { |
|
1725 | - return $this->query('Mailer'); |
|
1726 | - } |
|
1727 | - |
|
1728 | - /** |
|
1729 | - * Get the webroot |
|
1730 | - * |
|
1731 | - * @return string |
|
1732 | - */ |
|
1733 | - public function getWebRoot() { |
|
1734 | - return $this->webRoot; |
|
1735 | - } |
|
1736 | - |
|
1737 | - /** |
|
1738 | - * @return \OC\OCSClient |
|
1739 | - */ |
|
1740 | - public function getOcsClient() { |
|
1741 | - return $this->query('OcsClient'); |
|
1742 | - } |
|
1743 | - |
|
1744 | - /** |
|
1745 | - * @return \OCP\IDateTimeZone |
|
1746 | - */ |
|
1747 | - public function getDateTimeZone() { |
|
1748 | - return $this->query('DateTimeZone'); |
|
1749 | - } |
|
1750 | - |
|
1751 | - /** |
|
1752 | - * @return \OCP\IDateTimeFormatter |
|
1753 | - */ |
|
1754 | - public function getDateTimeFormatter() { |
|
1755 | - return $this->query('DateTimeFormatter'); |
|
1756 | - } |
|
1757 | - |
|
1758 | - /** |
|
1759 | - * @return \OCP\Files\Config\IMountProviderCollection |
|
1760 | - */ |
|
1761 | - public function getMountProviderCollection() { |
|
1762 | - return $this->query('MountConfigManager'); |
|
1763 | - } |
|
1764 | - |
|
1765 | - /** |
|
1766 | - * Get the IniWrapper |
|
1767 | - * |
|
1768 | - * @return IniGetWrapper |
|
1769 | - */ |
|
1770 | - public function getIniWrapper() { |
|
1771 | - return $this->query('IniWrapper'); |
|
1772 | - } |
|
1773 | - |
|
1774 | - /** |
|
1775 | - * @return \OCP\Command\IBus |
|
1776 | - */ |
|
1777 | - public function getCommandBus() { |
|
1778 | - return $this->query('AsyncCommandBus'); |
|
1779 | - } |
|
1780 | - |
|
1781 | - /** |
|
1782 | - * Get the trusted domain helper |
|
1783 | - * |
|
1784 | - * @return TrustedDomainHelper |
|
1785 | - */ |
|
1786 | - public function getTrustedDomainHelper() { |
|
1787 | - return $this->query('TrustedDomainHelper'); |
|
1788 | - } |
|
1789 | - |
|
1790 | - /** |
|
1791 | - * Get the locking provider |
|
1792 | - * |
|
1793 | - * @return \OCP\Lock\ILockingProvider |
|
1794 | - * @since 8.1.0 |
|
1795 | - */ |
|
1796 | - public function getLockingProvider() { |
|
1797 | - return $this->query('LockingProvider'); |
|
1798 | - } |
|
1799 | - |
|
1800 | - /** |
|
1801 | - * @return \OCP\Files\Mount\IMountManager |
|
1802 | - **/ |
|
1803 | - function getMountManager() { |
|
1804 | - return $this->query('MountManager'); |
|
1805 | - } |
|
1806 | - |
|
1807 | - /** @return \OCP\Files\Config\IUserMountCache */ |
|
1808 | - function getUserMountCache() { |
|
1809 | - return $this->query('UserMountCache'); |
|
1810 | - } |
|
1811 | - |
|
1812 | - /** |
|
1813 | - * Get the MimeTypeDetector |
|
1814 | - * |
|
1815 | - * @return \OCP\Files\IMimeTypeDetector |
|
1816 | - */ |
|
1817 | - public function getMimeTypeDetector() { |
|
1818 | - return $this->query('MimeTypeDetector'); |
|
1819 | - } |
|
1820 | - |
|
1821 | - /** |
|
1822 | - * Get the MimeTypeLoader |
|
1823 | - * |
|
1824 | - * @return \OCP\Files\IMimeTypeLoader |
|
1825 | - */ |
|
1826 | - public function getMimeTypeLoader() { |
|
1827 | - return $this->query('MimeTypeLoader'); |
|
1828 | - } |
|
1829 | - |
|
1830 | - /** |
|
1831 | - * Get the manager of all the capabilities |
|
1832 | - * |
|
1833 | - * @return \OC\CapabilitiesManager |
|
1834 | - */ |
|
1835 | - public function getCapabilitiesManager() { |
|
1836 | - return $this->query('CapabilitiesManager'); |
|
1837 | - } |
|
1838 | - |
|
1839 | - /** |
|
1840 | - * Get the EventDispatcher |
|
1841 | - * |
|
1842 | - * @return EventDispatcherInterface |
|
1843 | - * @since 8.2.0 |
|
1844 | - */ |
|
1845 | - public function getEventDispatcher() { |
|
1846 | - return $this->query(\OC\EventDispatcher\SymfonyAdapter::class); |
|
1847 | - } |
|
1848 | - |
|
1849 | - /** |
|
1850 | - * Get the Notification Manager |
|
1851 | - * |
|
1852 | - * @return \OCP\Notification\IManager |
|
1853 | - * @since 8.2.0 |
|
1854 | - */ |
|
1855 | - public function getNotificationManager() { |
|
1856 | - return $this->query('NotificationManager'); |
|
1857 | - } |
|
1858 | - |
|
1859 | - /** |
|
1860 | - * @return \OCP\Comments\ICommentsManager |
|
1861 | - */ |
|
1862 | - public function getCommentsManager() { |
|
1863 | - return $this->query('CommentsManager'); |
|
1864 | - } |
|
1865 | - |
|
1866 | - /** |
|
1867 | - * @return \OCA\Theming\ThemingDefaults |
|
1868 | - */ |
|
1869 | - public function getThemingDefaults() { |
|
1870 | - return $this->query('ThemingDefaults'); |
|
1871 | - } |
|
1872 | - |
|
1873 | - /** |
|
1874 | - * @return \OC\IntegrityCheck\Checker |
|
1875 | - */ |
|
1876 | - public function getIntegrityCodeChecker() { |
|
1877 | - return $this->query('IntegrityCodeChecker'); |
|
1878 | - } |
|
1879 | - |
|
1880 | - /** |
|
1881 | - * @return \OC\Session\CryptoWrapper |
|
1882 | - */ |
|
1883 | - public function getSessionCryptoWrapper() { |
|
1884 | - return $this->query('CryptoWrapper'); |
|
1885 | - } |
|
1886 | - |
|
1887 | - /** |
|
1888 | - * @return CsrfTokenManager |
|
1889 | - */ |
|
1890 | - public function getCsrfTokenManager() { |
|
1891 | - return $this->query(CsrfTokenManager::class); |
|
1892 | - } |
|
1893 | - |
|
1894 | - /** |
|
1895 | - * @return Throttler |
|
1896 | - */ |
|
1897 | - public function getBruteForceThrottler() { |
|
1898 | - return $this->query('Throttler'); |
|
1899 | - } |
|
1900 | - |
|
1901 | - /** |
|
1902 | - * @return IContentSecurityPolicyManager |
|
1903 | - */ |
|
1904 | - public function getContentSecurityPolicyManager() { |
|
1905 | - return $this->query('ContentSecurityPolicyManager'); |
|
1906 | - } |
|
1907 | - |
|
1908 | - /** |
|
1909 | - * @return ContentSecurityPolicyNonceManager |
|
1910 | - */ |
|
1911 | - public function getContentSecurityPolicyNonceManager() { |
|
1912 | - return $this->query('ContentSecurityPolicyNonceManager'); |
|
1913 | - } |
|
1914 | - |
|
1915 | - /** |
|
1916 | - * Not a public API as of 8.2, wait for 9.0 |
|
1917 | - * |
|
1918 | - * @return \OCA\Files_External\Service\BackendService |
|
1919 | - */ |
|
1920 | - public function getStoragesBackendService() { |
|
1921 | - return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
1922 | - } |
|
1923 | - |
|
1924 | - /** |
|
1925 | - * Not a public API as of 8.2, wait for 9.0 |
|
1926 | - * |
|
1927 | - * @return \OCA\Files_External\Service\GlobalStoragesService |
|
1928 | - */ |
|
1929 | - public function getGlobalStoragesService() { |
|
1930 | - return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
1931 | - } |
|
1932 | - |
|
1933 | - /** |
|
1934 | - * Not a public API as of 8.2, wait for 9.0 |
|
1935 | - * |
|
1936 | - * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
1937 | - */ |
|
1938 | - public function getUserGlobalStoragesService() { |
|
1939 | - return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
1940 | - } |
|
1941 | - |
|
1942 | - /** |
|
1943 | - * Not a public API as of 8.2, wait for 9.0 |
|
1944 | - * |
|
1945 | - * @return \OCA\Files_External\Service\UserStoragesService |
|
1946 | - */ |
|
1947 | - public function getUserStoragesService() { |
|
1948 | - return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
1949 | - } |
|
1950 | - |
|
1951 | - /** |
|
1952 | - * @return \OCP\Share\IManager |
|
1953 | - */ |
|
1954 | - public function getShareManager() { |
|
1955 | - return $this->query('ShareManager'); |
|
1956 | - } |
|
1957 | - |
|
1958 | - /** |
|
1959 | - * @return \OCP\Collaboration\Collaborators\ISearch |
|
1960 | - */ |
|
1961 | - public function getCollaboratorSearch() { |
|
1962 | - return $this->query('CollaboratorSearch'); |
|
1963 | - } |
|
1964 | - |
|
1965 | - /** |
|
1966 | - * @return \OCP\Collaboration\AutoComplete\IManager |
|
1967 | - */ |
|
1968 | - public function getAutoCompleteManager(){ |
|
1969 | - return $this->query(IManager::class); |
|
1970 | - } |
|
1971 | - |
|
1972 | - /** |
|
1973 | - * Returns the LDAP Provider |
|
1974 | - * |
|
1975 | - * @return \OCP\LDAP\ILDAPProvider |
|
1976 | - */ |
|
1977 | - public function getLDAPProvider() { |
|
1978 | - return $this->query('LDAPProvider'); |
|
1979 | - } |
|
1980 | - |
|
1981 | - /** |
|
1982 | - * @return \OCP\Settings\IManager |
|
1983 | - */ |
|
1984 | - public function getSettingsManager() { |
|
1985 | - return $this->query('SettingsManager'); |
|
1986 | - } |
|
1987 | - |
|
1988 | - /** |
|
1989 | - * @return \OCP\Files\IAppData |
|
1990 | - */ |
|
1991 | - public function getAppDataDir($app) { |
|
1992 | - /** @var \OC\Files\AppData\Factory $factory */ |
|
1993 | - $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
1994 | - return $factory->get($app); |
|
1995 | - } |
|
1996 | - |
|
1997 | - /** |
|
1998 | - * @return \OCP\Lockdown\ILockdownManager |
|
1999 | - */ |
|
2000 | - public function getLockdownManager() { |
|
2001 | - return $this->query('LockdownManager'); |
|
2002 | - } |
|
2003 | - |
|
2004 | - /** |
|
2005 | - * @return \OCP\Federation\ICloudIdManager |
|
2006 | - */ |
|
2007 | - public function getCloudIdManager() { |
|
2008 | - return $this->query(ICloudIdManager::class); |
|
2009 | - } |
|
2010 | - |
|
2011 | - /** |
|
2012 | - * @return \OCP\GlobalScale\IConfig |
|
2013 | - */ |
|
2014 | - public function getGlobalScaleConfig() { |
|
2015 | - return $this->query(IConfig::class); |
|
2016 | - } |
|
2017 | - |
|
2018 | - /** |
|
2019 | - * @return \OCP\Federation\ICloudFederationProviderManager |
|
2020 | - */ |
|
2021 | - public function getCloudFederationProviderManager() { |
|
2022 | - return $this->query(ICloudFederationProviderManager::class); |
|
2023 | - } |
|
2024 | - |
|
2025 | - /** |
|
2026 | - * @return \OCP\Remote\Api\IApiFactory |
|
2027 | - */ |
|
2028 | - public function getRemoteApiFactory() { |
|
2029 | - return $this->query(IApiFactory::class); |
|
2030 | - } |
|
2031 | - |
|
2032 | - /** |
|
2033 | - * @return \OCP\Federation\ICloudFederationFactory |
|
2034 | - */ |
|
2035 | - public function getCloudFederationFactory() { |
|
2036 | - return $this->query(ICloudFederationFactory::class); |
|
2037 | - } |
|
2038 | - |
|
2039 | - /** |
|
2040 | - * @return \OCP\Remote\IInstanceFactory |
|
2041 | - */ |
|
2042 | - public function getRemoteInstanceFactory() { |
|
2043 | - return $this->query(IInstanceFactory::class); |
|
2044 | - } |
|
2045 | - |
|
2046 | - /** |
|
2047 | - * @return IStorageFactory |
|
2048 | - */ |
|
2049 | - public function getStorageFactory() { |
|
2050 | - return $this->query(IStorageFactory::class); |
|
2051 | - } |
|
2052 | - |
|
2053 | - /** |
|
2054 | - * Get the Preview GeneratorHelper |
|
2055 | - * |
|
2056 | - * @return GeneratorHelper |
|
2057 | - * @since 17.0.0 |
|
2058 | - */ |
|
2059 | - public function getGeneratorHelper() { |
|
2060 | - return $this->query(\OC\Preview\GeneratorHelper::class); |
|
2061 | - } |
|
945 | + $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
946 | + if (isset($prefixes['OCA\\Theming\\'])) { |
|
947 | + $classExists = true; |
|
948 | + } else { |
|
949 | + $classExists = false; |
|
950 | + } |
|
951 | + |
|
952 | + if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
953 | + return new ThemingDefaults( |
|
954 | + $c->getConfig(), |
|
955 | + $c->getL10N('theming'), |
|
956 | + $c->getURLGenerator(), |
|
957 | + $c->getMemCacheFactory(), |
|
958 | + new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')), |
|
959 | + new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory(), $this->getLogger()), |
|
960 | + $c->getAppManager(), |
|
961 | + $c->getNavigationManager() |
|
962 | + ); |
|
963 | + } |
|
964 | + return new \OC_Defaults(); |
|
965 | + }); |
|
966 | + $this->registerService(SCSSCacher::class, function (Server $c) { |
|
967 | + return new SCSSCacher( |
|
968 | + $c->getLogger(), |
|
969 | + $c->query(\OC\Files\AppData\Factory::class), |
|
970 | + $c->getURLGenerator(), |
|
971 | + $c->getConfig(), |
|
972 | + $c->getThemingDefaults(), |
|
973 | + \OC::$SERVERROOT, |
|
974 | + $this->getMemCacheFactory(), |
|
975 | + $c->query(IconsCacher::class), |
|
976 | + new TimeFactory() |
|
977 | + ); |
|
978 | + }); |
|
979 | + $this->registerService(JSCombiner::class, function (Server $c) { |
|
980 | + return new JSCombiner( |
|
981 | + $c->getAppDataDir('js'), |
|
982 | + $c->getURLGenerator(), |
|
983 | + $this->getMemCacheFactory(), |
|
984 | + $c->getSystemConfig(), |
|
985 | + $c->getLogger() |
|
986 | + ); |
|
987 | + }); |
|
988 | + $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
|
989 | + $this->registerAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class); |
|
990 | + $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class); |
|
991 | + |
|
992 | + $this->registerService('CryptoWrapper', function (Server $c) { |
|
993 | + // FIXME: Instantiiated here due to cyclic dependency |
|
994 | + $request = new Request( |
|
995 | + [ |
|
996 | + 'get' => $_GET, |
|
997 | + 'post' => $_POST, |
|
998 | + 'files' => $_FILES, |
|
999 | + 'server' => $_SERVER, |
|
1000 | + 'env' => $_ENV, |
|
1001 | + 'cookies' => $_COOKIE, |
|
1002 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
1003 | + ? $_SERVER['REQUEST_METHOD'] |
|
1004 | + : null, |
|
1005 | + ], |
|
1006 | + $c->getSecureRandom(), |
|
1007 | + $c->getConfig() |
|
1008 | + ); |
|
1009 | + |
|
1010 | + return new CryptoWrapper( |
|
1011 | + $c->getConfig(), |
|
1012 | + $c->getCrypto(), |
|
1013 | + $c->getSecureRandom(), |
|
1014 | + $request |
|
1015 | + ); |
|
1016 | + }); |
|
1017 | + $this->registerService(CsrfTokenManager::class, function (Server $c) { |
|
1018 | + $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
1019 | + |
|
1020 | + return new CsrfTokenManager( |
|
1021 | + $tokenGenerator, |
|
1022 | + $c->query(SessionStorage::class) |
|
1023 | + ); |
|
1024 | + }); |
|
1025 | + $this->registerAlias('CsrfTokenManager', CsrfTokenManager::class); |
|
1026 | + $this->registerService(SessionStorage::class, function (Server $c) { |
|
1027 | + return new SessionStorage($c->getSession()); |
|
1028 | + }); |
|
1029 | + $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, \OC\Security\CSP\ContentSecurityPolicyManager::class); |
|
1030 | + $this->registerAlias('ContentSecurityPolicyManager', \OC\Security\CSP\ContentSecurityPolicyManager::class); |
|
1031 | + |
|
1032 | + $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
1033 | + return new ContentSecurityPolicyNonceManager( |
|
1034 | + $c->getCsrfTokenManager(), |
|
1035 | + $c->getRequest() |
|
1036 | + ); |
|
1037 | + }); |
|
1038 | + |
|
1039 | + $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
1040 | + $config = $c->getConfig(); |
|
1041 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
1042 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
1043 | + $factory = new $factoryClass($this); |
|
1044 | + |
|
1045 | + $manager = new \OC\Share20\Manager( |
|
1046 | + $c->getLogger(), |
|
1047 | + $c->getConfig(), |
|
1048 | + $c->getSecureRandom(), |
|
1049 | + $c->getHasher(), |
|
1050 | + $c->getMountManager(), |
|
1051 | + $c->getGroupManager(), |
|
1052 | + $c->getL10N('lib'), |
|
1053 | + $c->getL10NFactory(), |
|
1054 | + $factory, |
|
1055 | + $c->getUserManager(), |
|
1056 | + $c->getLazyRootFolder(), |
|
1057 | + $c->getEventDispatcher(), |
|
1058 | + $c->getMailer(), |
|
1059 | + $c->getURLGenerator(), |
|
1060 | + $c->getThemingDefaults() |
|
1061 | + ); |
|
1062 | + |
|
1063 | + return $manager; |
|
1064 | + }); |
|
1065 | + $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
1066 | + |
|
1067 | + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
|
1068 | + $instance = new Collaboration\Collaborators\Search($c); |
|
1069 | + |
|
1070 | + // register default plugins |
|
1071 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
1072 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
1073 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
1074 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
1075 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
1076 | + |
|
1077 | + return $instance; |
|
1078 | + }); |
|
1079 | + $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
1080 | + $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
1081 | + |
|
1082 | + $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
1083 | + |
|
1084 | + $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
1085 | + |
|
1086 | + $this->registerService('SettingsManager', function (Server $c) { |
|
1087 | + $manager = new \OC\Settings\Manager( |
|
1088 | + $c->getLogger(), |
|
1089 | + $c->getL10NFactory(), |
|
1090 | + $c->getURLGenerator(), |
|
1091 | + $c |
|
1092 | + ); |
|
1093 | + return $manager; |
|
1094 | + }); |
|
1095 | + $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1096 | + return new \OC\Files\AppData\Factory( |
|
1097 | + $c->getRootFolder(), |
|
1098 | + $c->getSystemConfig() |
|
1099 | + ); |
|
1100 | + }); |
|
1101 | + |
|
1102 | + $this->registerService('LockdownManager', function (Server $c) { |
|
1103 | + return new LockdownManager(function () use ($c) { |
|
1104 | + return $c->getSession(); |
|
1105 | + }); |
|
1106 | + }); |
|
1107 | + |
|
1108 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1109 | + return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
1110 | + }); |
|
1111 | + |
|
1112 | + $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1113 | + return new CloudIdManager(); |
|
1114 | + }); |
|
1115 | + |
|
1116 | + $this->registerService(IConfig::class, function (Server $c) { |
|
1117 | + return new GlobalScale\Config($c->getConfig()); |
|
1118 | + }); |
|
1119 | + |
|
1120 | + $this->registerService(ICloudFederationProviderManager::class, function (Server $c) { |
|
1121 | + return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger()); |
|
1122 | + }); |
|
1123 | + |
|
1124 | + $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
1125 | + return new CloudFederationFactory(); |
|
1126 | + }); |
|
1127 | + |
|
1128 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1129 | + $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1130 | + |
|
1131 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1132 | + $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1133 | + |
|
1134 | + $this->registerService(Defaults::class, function (Server $c) { |
|
1135 | + return new Defaults( |
|
1136 | + $c->getThemingDefaults() |
|
1137 | + ); |
|
1138 | + }); |
|
1139 | + $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
1140 | + |
|
1141 | + $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1142 | + return $c->query(\OCP\IUserSession::class)->getSession(); |
|
1143 | + }); |
|
1144 | + |
|
1145 | + $this->registerService(IShareHelper::class, function (Server $c) { |
|
1146 | + return new ShareHelper( |
|
1147 | + $c->query(\OCP\Share\IManager::class) |
|
1148 | + ); |
|
1149 | + }); |
|
1150 | + |
|
1151 | + $this->registerService(Installer::class, function(Server $c) { |
|
1152 | + return new Installer( |
|
1153 | + $c->getAppFetcher(), |
|
1154 | + $c->getHTTPClientService(), |
|
1155 | + $c->getTempManager(), |
|
1156 | + $c->getLogger(), |
|
1157 | + $c->getConfig() |
|
1158 | + ); |
|
1159 | + }); |
|
1160 | + |
|
1161 | + $this->registerService(IApiFactory::class, function(Server $c) { |
|
1162 | + return new ApiFactory($c->getHTTPClientService()); |
|
1163 | + }); |
|
1164 | + |
|
1165 | + $this->registerService(IInstanceFactory::class, function(Server $c) { |
|
1166 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
1167 | + return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); |
|
1168 | + }); |
|
1169 | + |
|
1170 | + $this->registerService(IContactsStore::class, function(Server $c) { |
|
1171 | + return new ContactsStore( |
|
1172 | + $c->getContactsManager(), |
|
1173 | + $c->getConfig(), |
|
1174 | + $c->getUserManager(), |
|
1175 | + $c->getGroupManager() |
|
1176 | + ); |
|
1177 | + }); |
|
1178 | + $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
1179 | + $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
1180 | + |
|
1181 | + $this->registerService(IStorageFactory::class, function() { |
|
1182 | + return new StorageFactory(); |
|
1183 | + }); |
|
1184 | + |
|
1185 | + $this->registerAlias(IDashboardManager::class, DashboardManager::class); |
|
1186 | + $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
1187 | + |
|
1188 | + $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
1189 | + |
|
1190 | + $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
1191 | + |
|
1192 | + $this->connectDispatcher(); |
|
1193 | + } |
|
1194 | + |
|
1195 | + /** |
|
1196 | + * @return \OCP\Calendar\IManager |
|
1197 | + */ |
|
1198 | + public function getCalendarManager() { |
|
1199 | + return $this->query('CalendarManager'); |
|
1200 | + } |
|
1201 | + |
|
1202 | + /** |
|
1203 | + * @return \OCP\Calendar\Resource\IManager |
|
1204 | + */ |
|
1205 | + public function getCalendarResourceBackendManager() { |
|
1206 | + return $this->query('CalendarResourceBackendManager'); |
|
1207 | + } |
|
1208 | + |
|
1209 | + /** |
|
1210 | + * @return \OCP\Calendar\Room\IManager |
|
1211 | + */ |
|
1212 | + public function getCalendarRoomBackendManager() { |
|
1213 | + return $this->query('CalendarRoomBackendManager'); |
|
1214 | + } |
|
1215 | + |
|
1216 | + private function connectDispatcher() { |
|
1217 | + $dispatcher = $this->getEventDispatcher(); |
|
1218 | + |
|
1219 | + // Delete avatar on user deletion |
|
1220 | + $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) { |
|
1221 | + $logger = $this->getLogger(); |
|
1222 | + $manager = $this->getAvatarManager(); |
|
1223 | + /** @var IUser $user */ |
|
1224 | + $user = $e->getSubject(); |
|
1225 | + |
|
1226 | + try { |
|
1227 | + $avatar = $manager->getAvatar($user->getUID()); |
|
1228 | + $avatar->remove(); |
|
1229 | + } catch (NotFoundException $e) { |
|
1230 | + // no avatar to remove |
|
1231 | + } catch (\Exception $e) { |
|
1232 | + // Ignore exceptions |
|
1233 | + $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1234 | + } |
|
1235 | + }); |
|
1236 | + |
|
1237 | + $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1238 | + $manager = $this->getAvatarManager(); |
|
1239 | + /** @var IUser $user */ |
|
1240 | + $user = $e->getSubject(); |
|
1241 | + $feature = $e->getArgument('feature'); |
|
1242 | + $oldValue = $e->getArgument('oldValue'); |
|
1243 | + $value = $e->getArgument('value'); |
|
1244 | + |
|
1245 | + // We only change the avatar on display name changes |
|
1246 | + if ($feature !== 'displayName') { |
|
1247 | + return; |
|
1248 | + } |
|
1249 | + |
|
1250 | + try { |
|
1251 | + $avatar = $manager->getAvatar($user->getUID()); |
|
1252 | + $avatar->userChanged($feature, $oldValue, $value); |
|
1253 | + } catch (NotFoundException $e) { |
|
1254 | + // no avatar to remove |
|
1255 | + } |
|
1256 | + }); |
|
1257 | + } |
|
1258 | + |
|
1259 | + /** |
|
1260 | + * @return \OCP\Contacts\IManager |
|
1261 | + */ |
|
1262 | + public function getContactsManager() { |
|
1263 | + return $this->query('ContactsManager'); |
|
1264 | + } |
|
1265 | + |
|
1266 | + /** |
|
1267 | + * @return \OC\Encryption\Manager |
|
1268 | + */ |
|
1269 | + public function getEncryptionManager() { |
|
1270 | + return $this->query('EncryptionManager'); |
|
1271 | + } |
|
1272 | + |
|
1273 | + /** |
|
1274 | + * @return \OC\Encryption\File |
|
1275 | + */ |
|
1276 | + public function getEncryptionFilesHelper() { |
|
1277 | + return $this->query('EncryptionFileHelper'); |
|
1278 | + } |
|
1279 | + |
|
1280 | + /** |
|
1281 | + * @return \OCP\Encryption\Keys\IStorage |
|
1282 | + */ |
|
1283 | + public function getEncryptionKeyStorage() { |
|
1284 | + return $this->query('EncryptionKeyStorage'); |
|
1285 | + } |
|
1286 | + |
|
1287 | + /** |
|
1288 | + * The current request object holding all information about the request |
|
1289 | + * currently being processed is returned from this method. |
|
1290 | + * In case the current execution was not initiated by a web request null is returned |
|
1291 | + * |
|
1292 | + * @return \OCP\IRequest |
|
1293 | + */ |
|
1294 | + public function getRequest() { |
|
1295 | + return $this->query('Request'); |
|
1296 | + } |
|
1297 | + |
|
1298 | + /** |
|
1299 | + * Returns the preview manager which can create preview images for a given file |
|
1300 | + * |
|
1301 | + * @return \OCP\IPreview |
|
1302 | + */ |
|
1303 | + public function getPreviewManager() { |
|
1304 | + return $this->query('PreviewManager'); |
|
1305 | + } |
|
1306 | + |
|
1307 | + /** |
|
1308 | + * Returns the tag manager which can get and set tags for different object types |
|
1309 | + * |
|
1310 | + * @see \OCP\ITagManager::load() |
|
1311 | + * @return \OCP\ITagManager |
|
1312 | + */ |
|
1313 | + public function getTagManager() { |
|
1314 | + return $this->query('TagManager'); |
|
1315 | + } |
|
1316 | + |
|
1317 | + /** |
|
1318 | + * Returns the system-tag manager |
|
1319 | + * |
|
1320 | + * @return \OCP\SystemTag\ISystemTagManager |
|
1321 | + * |
|
1322 | + * @since 9.0.0 |
|
1323 | + */ |
|
1324 | + public function getSystemTagManager() { |
|
1325 | + return $this->query('SystemTagManager'); |
|
1326 | + } |
|
1327 | + |
|
1328 | + /** |
|
1329 | + * Returns the system-tag object mapper |
|
1330 | + * |
|
1331 | + * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
1332 | + * |
|
1333 | + * @since 9.0.0 |
|
1334 | + */ |
|
1335 | + public function getSystemTagObjectMapper() { |
|
1336 | + return $this->query('SystemTagObjectMapper'); |
|
1337 | + } |
|
1338 | + |
|
1339 | + /** |
|
1340 | + * Returns the avatar manager, used for avatar functionality |
|
1341 | + * |
|
1342 | + * @return \OCP\IAvatarManager |
|
1343 | + */ |
|
1344 | + public function getAvatarManager() { |
|
1345 | + return $this->query('AvatarManager'); |
|
1346 | + } |
|
1347 | + |
|
1348 | + /** |
|
1349 | + * Returns the root folder of ownCloud's data directory |
|
1350 | + * |
|
1351 | + * @return \OCP\Files\IRootFolder |
|
1352 | + */ |
|
1353 | + public function getRootFolder() { |
|
1354 | + return $this->query('LazyRootFolder'); |
|
1355 | + } |
|
1356 | + |
|
1357 | + /** |
|
1358 | + * Returns the root folder of ownCloud's data directory |
|
1359 | + * This is the lazy variant so this gets only initialized once it |
|
1360 | + * is actually used. |
|
1361 | + * |
|
1362 | + * @return \OCP\Files\IRootFolder |
|
1363 | + */ |
|
1364 | + public function getLazyRootFolder() { |
|
1365 | + return $this->query('LazyRootFolder'); |
|
1366 | + } |
|
1367 | + |
|
1368 | + /** |
|
1369 | + * Returns a view to ownCloud's files folder |
|
1370 | + * |
|
1371 | + * @param string $userId user ID |
|
1372 | + * @return \OCP\Files\Folder|null |
|
1373 | + */ |
|
1374 | + public function getUserFolder($userId = null) { |
|
1375 | + if ($userId === null) { |
|
1376 | + $user = $this->getUserSession()->getUser(); |
|
1377 | + if (!$user) { |
|
1378 | + return null; |
|
1379 | + } |
|
1380 | + $userId = $user->getUID(); |
|
1381 | + } |
|
1382 | + $root = $this->getRootFolder(); |
|
1383 | + return $root->getUserFolder($userId); |
|
1384 | + } |
|
1385 | + |
|
1386 | + /** |
|
1387 | + * Returns an app-specific view in ownClouds data directory |
|
1388 | + * |
|
1389 | + * @return \OCP\Files\Folder |
|
1390 | + * @deprecated since 9.2.0 use IAppData |
|
1391 | + */ |
|
1392 | + public function getAppFolder() { |
|
1393 | + $dir = '/' . \OC_App::getCurrentApp(); |
|
1394 | + $root = $this->getRootFolder(); |
|
1395 | + if (!$root->nodeExists($dir)) { |
|
1396 | + $folder = $root->newFolder($dir); |
|
1397 | + } else { |
|
1398 | + $folder = $root->get($dir); |
|
1399 | + } |
|
1400 | + return $folder; |
|
1401 | + } |
|
1402 | + |
|
1403 | + /** |
|
1404 | + * @return \OC\User\Manager |
|
1405 | + */ |
|
1406 | + public function getUserManager() { |
|
1407 | + return $this->query('UserManager'); |
|
1408 | + } |
|
1409 | + |
|
1410 | + /** |
|
1411 | + * @return \OC\Group\Manager |
|
1412 | + */ |
|
1413 | + public function getGroupManager() { |
|
1414 | + return $this->query('GroupManager'); |
|
1415 | + } |
|
1416 | + |
|
1417 | + /** |
|
1418 | + * @return \OC\User\Session |
|
1419 | + */ |
|
1420 | + public function getUserSession() { |
|
1421 | + return $this->query('UserSession'); |
|
1422 | + } |
|
1423 | + |
|
1424 | + /** |
|
1425 | + * @return \OCP\ISession |
|
1426 | + */ |
|
1427 | + public function getSession() { |
|
1428 | + return $this->query('UserSession')->getSession(); |
|
1429 | + } |
|
1430 | + |
|
1431 | + /** |
|
1432 | + * @param \OCP\ISession $session |
|
1433 | + */ |
|
1434 | + public function setSession(\OCP\ISession $session) { |
|
1435 | + $this->query(SessionStorage::class)->setSession($session); |
|
1436 | + $this->query('UserSession')->setSession($session); |
|
1437 | + $this->query(Store::class)->setSession($session); |
|
1438 | + } |
|
1439 | + |
|
1440 | + /** |
|
1441 | + * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1442 | + */ |
|
1443 | + public function getTwoFactorAuthManager() { |
|
1444 | + return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
1445 | + } |
|
1446 | + |
|
1447 | + /** |
|
1448 | + * @return \OC\NavigationManager |
|
1449 | + */ |
|
1450 | + public function getNavigationManager() { |
|
1451 | + return $this->query('NavigationManager'); |
|
1452 | + } |
|
1453 | + |
|
1454 | + /** |
|
1455 | + * @return \OCP\IConfig |
|
1456 | + */ |
|
1457 | + public function getConfig() { |
|
1458 | + return $this->query('AllConfig'); |
|
1459 | + } |
|
1460 | + |
|
1461 | + /** |
|
1462 | + * @return \OC\SystemConfig |
|
1463 | + */ |
|
1464 | + public function getSystemConfig() { |
|
1465 | + return $this->query('SystemConfig'); |
|
1466 | + } |
|
1467 | + |
|
1468 | + /** |
|
1469 | + * Returns the app config manager |
|
1470 | + * |
|
1471 | + * @return \OCP\IAppConfig |
|
1472 | + */ |
|
1473 | + public function getAppConfig() { |
|
1474 | + return $this->query('AppConfig'); |
|
1475 | + } |
|
1476 | + |
|
1477 | + /** |
|
1478 | + * @return \OCP\L10N\IFactory |
|
1479 | + */ |
|
1480 | + public function getL10NFactory() { |
|
1481 | + return $this->query('L10NFactory'); |
|
1482 | + } |
|
1483 | + |
|
1484 | + /** |
|
1485 | + * get an L10N instance |
|
1486 | + * |
|
1487 | + * @param string $app appid |
|
1488 | + * @param string $lang |
|
1489 | + * @return IL10N |
|
1490 | + */ |
|
1491 | + public function getL10N($app, $lang = null) { |
|
1492 | + return $this->getL10NFactory()->get($app, $lang); |
|
1493 | + } |
|
1494 | + |
|
1495 | + /** |
|
1496 | + * @return \OCP\IURLGenerator |
|
1497 | + */ |
|
1498 | + public function getURLGenerator() { |
|
1499 | + return $this->query('URLGenerator'); |
|
1500 | + } |
|
1501 | + |
|
1502 | + /** |
|
1503 | + * @return AppFetcher |
|
1504 | + */ |
|
1505 | + public function getAppFetcher() { |
|
1506 | + return $this->query(AppFetcher::class); |
|
1507 | + } |
|
1508 | + |
|
1509 | + /** |
|
1510 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1511 | + * getMemCacheFactory() instead. |
|
1512 | + * |
|
1513 | + * @return \OCP\ICache |
|
1514 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1515 | + */ |
|
1516 | + public function getCache() { |
|
1517 | + return $this->query('UserCache'); |
|
1518 | + } |
|
1519 | + |
|
1520 | + /** |
|
1521 | + * Returns an \OCP\CacheFactory instance |
|
1522 | + * |
|
1523 | + * @return \OCP\ICacheFactory |
|
1524 | + */ |
|
1525 | + public function getMemCacheFactory() { |
|
1526 | + return $this->query('MemCacheFactory'); |
|
1527 | + } |
|
1528 | + |
|
1529 | + /** |
|
1530 | + * Returns an \OC\RedisFactory instance |
|
1531 | + * |
|
1532 | + * @return \OC\RedisFactory |
|
1533 | + */ |
|
1534 | + public function getGetRedisFactory() { |
|
1535 | + return $this->query('RedisFactory'); |
|
1536 | + } |
|
1537 | + |
|
1538 | + |
|
1539 | + /** |
|
1540 | + * Returns the current session |
|
1541 | + * |
|
1542 | + * @return \OCP\IDBConnection |
|
1543 | + */ |
|
1544 | + public function getDatabaseConnection() { |
|
1545 | + return $this->query('DatabaseConnection'); |
|
1546 | + } |
|
1547 | + |
|
1548 | + /** |
|
1549 | + * Returns the activity manager |
|
1550 | + * |
|
1551 | + * @return \OCP\Activity\IManager |
|
1552 | + */ |
|
1553 | + public function getActivityManager() { |
|
1554 | + return $this->query('ActivityManager'); |
|
1555 | + } |
|
1556 | + |
|
1557 | + /** |
|
1558 | + * Returns an job list for controlling background jobs |
|
1559 | + * |
|
1560 | + * @return \OCP\BackgroundJob\IJobList |
|
1561 | + */ |
|
1562 | + public function getJobList() { |
|
1563 | + return $this->query('JobList'); |
|
1564 | + } |
|
1565 | + |
|
1566 | + /** |
|
1567 | + * Returns a logger instance |
|
1568 | + * |
|
1569 | + * @return \OCP\ILogger |
|
1570 | + */ |
|
1571 | + public function getLogger() { |
|
1572 | + return $this->query('Logger'); |
|
1573 | + } |
|
1574 | + |
|
1575 | + /** |
|
1576 | + * @return ILogFactory |
|
1577 | + * @throws \OCP\AppFramework\QueryException |
|
1578 | + */ |
|
1579 | + public function getLogFactory() { |
|
1580 | + return $this->query(ILogFactory::class); |
|
1581 | + } |
|
1582 | + |
|
1583 | + /** |
|
1584 | + * Returns a router for generating and matching urls |
|
1585 | + * |
|
1586 | + * @return \OCP\Route\IRouter |
|
1587 | + */ |
|
1588 | + public function getRouter() { |
|
1589 | + return $this->query('Router'); |
|
1590 | + } |
|
1591 | + |
|
1592 | + /** |
|
1593 | + * Returns a search instance |
|
1594 | + * |
|
1595 | + * @return \OCP\ISearch |
|
1596 | + */ |
|
1597 | + public function getSearch() { |
|
1598 | + return $this->query('Search'); |
|
1599 | + } |
|
1600 | + |
|
1601 | + /** |
|
1602 | + * Returns a SecureRandom instance |
|
1603 | + * |
|
1604 | + * @return \OCP\Security\ISecureRandom |
|
1605 | + */ |
|
1606 | + public function getSecureRandom() { |
|
1607 | + return $this->query('SecureRandom'); |
|
1608 | + } |
|
1609 | + |
|
1610 | + /** |
|
1611 | + * Returns a Crypto instance |
|
1612 | + * |
|
1613 | + * @return \OCP\Security\ICrypto |
|
1614 | + */ |
|
1615 | + public function getCrypto() { |
|
1616 | + return $this->query('Crypto'); |
|
1617 | + } |
|
1618 | + |
|
1619 | + /** |
|
1620 | + * Returns a Hasher instance |
|
1621 | + * |
|
1622 | + * @return \OCP\Security\IHasher |
|
1623 | + */ |
|
1624 | + public function getHasher() { |
|
1625 | + return $this->query('Hasher'); |
|
1626 | + } |
|
1627 | + |
|
1628 | + /** |
|
1629 | + * Returns a CredentialsManager instance |
|
1630 | + * |
|
1631 | + * @return \OCP\Security\ICredentialsManager |
|
1632 | + */ |
|
1633 | + public function getCredentialsManager() { |
|
1634 | + return $this->query('CredentialsManager'); |
|
1635 | + } |
|
1636 | + |
|
1637 | + /** |
|
1638 | + * Get the certificate manager for the user |
|
1639 | + * |
|
1640 | + * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1641 | + * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1642 | + */ |
|
1643 | + public function getCertificateManager($userId = '') { |
|
1644 | + if ($userId === '') { |
|
1645 | + $userSession = $this->getUserSession(); |
|
1646 | + $user = $userSession->getUser(); |
|
1647 | + if (is_null($user)) { |
|
1648 | + return null; |
|
1649 | + } |
|
1650 | + $userId = $user->getUID(); |
|
1651 | + } |
|
1652 | + return new CertificateManager( |
|
1653 | + $userId, |
|
1654 | + new View(), |
|
1655 | + $this->getConfig(), |
|
1656 | + $this->getLogger(), |
|
1657 | + $this->getSecureRandom() |
|
1658 | + ); |
|
1659 | + } |
|
1660 | + |
|
1661 | + /** |
|
1662 | + * Returns an instance of the HTTP client service |
|
1663 | + * |
|
1664 | + * @return \OCP\Http\Client\IClientService |
|
1665 | + */ |
|
1666 | + public function getHTTPClientService() { |
|
1667 | + return $this->query('HttpClientService'); |
|
1668 | + } |
|
1669 | + |
|
1670 | + /** |
|
1671 | + * Create a new event source |
|
1672 | + * |
|
1673 | + * @return \OCP\IEventSource |
|
1674 | + */ |
|
1675 | + public function createEventSource() { |
|
1676 | + return new \OC_EventSource(); |
|
1677 | + } |
|
1678 | + |
|
1679 | + /** |
|
1680 | + * Get the active event logger |
|
1681 | + * |
|
1682 | + * The returned logger only logs data when debug mode is enabled |
|
1683 | + * |
|
1684 | + * @return \OCP\Diagnostics\IEventLogger |
|
1685 | + */ |
|
1686 | + public function getEventLogger() { |
|
1687 | + return $this->query('EventLogger'); |
|
1688 | + } |
|
1689 | + |
|
1690 | + /** |
|
1691 | + * Get the active query logger |
|
1692 | + * |
|
1693 | + * The returned logger only logs data when debug mode is enabled |
|
1694 | + * |
|
1695 | + * @return \OCP\Diagnostics\IQueryLogger |
|
1696 | + */ |
|
1697 | + public function getQueryLogger() { |
|
1698 | + return $this->query('QueryLogger'); |
|
1699 | + } |
|
1700 | + |
|
1701 | + /** |
|
1702 | + * Get the manager for temporary files and folders |
|
1703 | + * |
|
1704 | + * @return \OCP\ITempManager |
|
1705 | + */ |
|
1706 | + public function getTempManager() { |
|
1707 | + return $this->query('TempManager'); |
|
1708 | + } |
|
1709 | + |
|
1710 | + /** |
|
1711 | + * Get the app manager |
|
1712 | + * |
|
1713 | + * @return \OCP\App\IAppManager |
|
1714 | + */ |
|
1715 | + public function getAppManager() { |
|
1716 | + return $this->query('AppManager'); |
|
1717 | + } |
|
1718 | + |
|
1719 | + /** |
|
1720 | + * Creates a new mailer |
|
1721 | + * |
|
1722 | + * @return \OCP\Mail\IMailer |
|
1723 | + */ |
|
1724 | + public function getMailer() { |
|
1725 | + return $this->query('Mailer'); |
|
1726 | + } |
|
1727 | + |
|
1728 | + /** |
|
1729 | + * Get the webroot |
|
1730 | + * |
|
1731 | + * @return string |
|
1732 | + */ |
|
1733 | + public function getWebRoot() { |
|
1734 | + return $this->webRoot; |
|
1735 | + } |
|
1736 | + |
|
1737 | + /** |
|
1738 | + * @return \OC\OCSClient |
|
1739 | + */ |
|
1740 | + public function getOcsClient() { |
|
1741 | + return $this->query('OcsClient'); |
|
1742 | + } |
|
1743 | + |
|
1744 | + /** |
|
1745 | + * @return \OCP\IDateTimeZone |
|
1746 | + */ |
|
1747 | + public function getDateTimeZone() { |
|
1748 | + return $this->query('DateTimeZone'); |
|
1749 | + } |
|
1750 | + |
|
1751 | + /** |
|
1752 | + * @return \OCP\IDateTimeFormatter |
|
1753 | + */ |
|
1754 | + public function getDateTimeFormatter() { |
|
1755 | + return $this->query('DateTimeFormatter'); |
|
1756 | + } |
|
1757 | + |
|
1758 | + /** |
|
1759 | + * @return \OCP\Files\Config\IMountProviderCollection |
|
1760 | + */ |
|
1761 | + public function getMountProviderCollection() { |
|
1762 | + return $this->query('MountConfigManager'); |
|
1763 | + } |
|
1764 | + |
|
1765 | + /** |
|
1766 | + * Get the IniWrapper |
|
1767 | + * |
|
1768 | + * @return IniGetWrapper |
|
1769 | + */ |
|
1770 | + public function getIniWrapper() { |
|
1771 | + return $this->query('IniWrapper'); |
|
1772 | + } |
|
1773 | + |
|
1774 | + /** |
|
1775 | + * @return \OCP\Command\IBus |
|
1776 | + */ |
|
1777 | + public function getCommandBus() { |
|
1778 | + return $this->query('AsyncCommandBus'); |
|
1779 | + } |
|
1780 | + |
|
1781 | + /** |
|
1782 | + * Get the trusted domain helper |
|
1783 | + * |
|
1784 | + * @return TrustedDomainHelper |
|
1785 | + */ |
|
1786 | + public function getTrustedDomainHelper() { |
|
1787 | + return $this->query('TrustedDomainHelper'); |
|
1788 | + } |
|
1789 | + |
|
1790 | + /** |
|
1791 | + * Get the locking provider |
|
1792 | + * |
|
1793 | + * @return \OCP\Lock\ILockingProvider |
|
1794 | + * @since 8.1.0 |
|
1795 | + */ |
|
1796 | + public function getLockingProvider() { |
|
1797 | + return $this->query('LockingProvider'); |
|
1798 | + } |
|
1799 | + |
|
1800 | + /** |
|
1801 | + * @return \OCP\Files\Mount\IMountManager |
|
1802 | + **/ |
|
1803 | + function getMountManager() { |
|
1804 | + return $this->query('MountManager'); |
|
1805 | + } |
|
1806 | + |
|
1807 | + /** @return \OCP\Files\Config\IUserMountCache */ |
|
1808 | + function getUserMountCache() { |
|
1809 | + return $this->query('UserMountCache'); |
|
1810 | + } |
|
1811 | + |
|
1812 | + /** |
|
1813 | + * Get the MimeTypeDetector |
|
1814 | + * |
|
1815 | + * @return \OCP\Files\IMimeTypeDetector |
|
1816 | + */ |
|
1817 | + public function getMimeTypeDetector() { |
|
1818 | + return $this->query('MimeTypeDetector'); |
|
1819 | + } |
|
1820 | + |
|
1821 | + /** |
|
1822 | + * Get the MimeTypeLoader |
|
1823 | + * |
|
1824 | + * @return \OCP\Files\IMimeTypeLoader |
|
1825 | + */ |
|
1826 | + public function getMimeTypeLoader() { |
|
1827 | + return $this->query('MimeTypeLoader'); |
|
1828 | + } |
|
1829 | + |
|
1830 | + /** |
|
1831 | + * Get the manager of all the capabilities |
|
1832 | + * |
|
1833 | + * @return \OC\CapabilitiesManager |
|
1834 | + */ |
|
1835 | + public function getCapabilitiesManager() { |
|
1836 | + return $this->query('CapabilitiesManager'); |
|
1837 | + } |
|
1838 | + |
|
1839 | + /** |
|
1840 | + * Get the EventDispatcher |
|
1841 | + * |
|
1842 | + * @return EventDispatcherInterface |
|
1843 | + * @since 8.2.0 |
|
1844 | + */ |
|
1845 | + public function getEventDispatcher() { |
|
1846 | + return $this->query(\OC\EventDispatcher\SymfonyAdapter::class); |
|
1847 | + } |
|
1848 | + |
|
1849 | + /** |
|
1850 | + * Get the Notification Manager |
|
1851 | + * |
|
1852 | + * @return \OCP\Notification\IManager |
|
1853 | + * @since 8.2.0 |
|
1854 | + */ |
|
1855 | + public function getNotificationManager() { |
|
1856 | + return $this->query('NotificationManager'); |
|
1857 | + } |
|
1858 | + |
|
1859 | + /** |
|
1860 | + * @return \OCP\Comments\ICommentsManager |
|
1861 | + */ |
|
1862 | + public function getCommentsManager() { |
|
1863 | + return $this->query('CommentsManager'); |
|
1864 | + } |
|
1865 | + |
|
1866 | + /** |
|
1867 | + * @return \OCA\Theming\ThemingDefaults |
|
1868 | + */ |
|
1869 | + public function getThemingDefaults() { |
|
1870 | + return $this->query('ThemingDefaults'); |
|
1871 | + } |
|
1872 | + |
|
1873 | + /** |
|
1874 | + * @return \OC\IntegrityCheck\Checker |
|
1875 | + */ |
|
1876 | + public function getIntegrityCodeChecker() { |
|
1877 | + return $this->query('IntegrityCodeChecker'); |
|
1878 | + } |
|
1879 | + |
|
1880 | + /** |
|
1881 | + * @return \OC\Session\CryptoWrapper |
|
1882 | + */ |
|
1883 | + public function getSessionCryptoWrapper() { |
|
1884 | + return $this->query('CryptoWrapper'); |
|
1885 | + } |
|
1886 | + |
|
1887 | + /** |
|
1888 | + * @return CsrfTokenManager |
|
1889 | + */ |
|
1890 | + public function getCsrfTokenManager() { |
|
1891 | + return $this->query(CsrfTokenManager::class); |
|
1892 | + } |
|
1893 | + |
|
1894 | + /** |
|
1895 | + * @return Throttler |
|
1896 | + */ |
|
1897 | + public function getBruteForceThrottler() { |
|
1898 | + return $this->query('Throttler'); |
|
1899 | + } |
|
1900 | + |
|
1901 | + /** |
|
1902 | + * @return IContentSecurityPolicyManager |
|
1903 | + */ |
|
1904 | + public function getContentSecurityPolicyManager() { |
|
1905 | + return $this->query('ContentSecurityPolicyManager'); |
|
1906 | + } |
|
1907 | + |
|
1908 | + /** |
|
1909 | + * @return ContentSecurityPolicyNonceManager |
|
1910 | + */ |
|
1911 | + public function getContentSecurityPolicyNonceManager() { |
|
1912 | + return $this->query('ContentSecurityPolicyNonceManager'); |
|
1913 | + } |
|
1914 | + |
|
1915 | + /** |
|
1916 | + * Not a public API as of 8.2, wait for 9.0 |
|
1917 | + * |
|
1918 | + * @return \OCA\Files_External\Service\BackendService |
|
1919 | + */ |
|
1920 | + public function getStoragesBackendService() { |
|
1921 | + return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
1922 | + } |
|
1923 | + |
|
1924 | + /** |
|
1925 | + * Not a public API as of 8.2, wait for 9.0 |
|
1926 | + * |
|
1927 | + * @return \OCA\Files_External\Service\GlobalStoragesService |
|
1928 | + */ |
|
1929 | + public function getGlobalStoragesService() { |
|
1930 | + return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
1931 | + } |
|
1932 | + |
|
1933 | + /** |
|
1934 | + * Not a public API as of 8.2, wait for 9.0 |
|
1935 | + * |
|
1936 | + * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
1937 | + */ |
|
1938 | + public function getUserGlobalStoragesService() { |
|
1939 | + return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
1940 | + } |
|
1941 | + |
|
1942 | + /** |
|
1943 | + * Not a public API as of 8.2, wait for 9.0 |
|
1944 | + * |
|
1945 | + * @return \OCA\Files_External\Service\UserStoragesService |
|
1946 | + */ |
|
1947 | + public function getUserStoragesService() { |
|
1948 | + return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
1949 | + } |
|
1950 | + |
|
1951 | + /** |
|
1952 | + * @return \OCP\Share\IManager |
|
1953 | + */ |
|
1954 | + public function getShareManager() { |
|
1955 | + return $this->query('ShareManager'); |
|
1956 | + } |
|
1957 | + |
|
1958 | + /** |
|
1959 | + * @return \OCP\Collaboration\Collaborators\ISearch |
|
1960 | + */ |
|
1961 | + public function getCollaboratorSearch() { |
|
1962 | + return $this->query('CollaboratorSearch'); |
|
1963 | + } |
|
1964 | + |
|
1965 | + /** |
|
1966 | + * @return \OCP\Collaboration\AutoComplete\IManager |
|
1967 | + */ |
|
1968 | + public function getAutoCompleteManager(){ |
|
1969 | + return $this->query(IManager::class); |
|
1970 | + } |
|
1971 | + |
|
1972 | + /** |
|
1973 | + * Returns the LDAP Provider |
|
1974 | + * |
|
1975 | + * @return \OCP\LDAP\ILDAPProvider |
|
1976 | + */ |
|
1977 | + public function getLDAPProvider() { |
|
1978 | + return $this->query('LDAPProvider'); |
|
1979 | + } |
|
1980 | + |
|
1981 | + /** |
|
1982 | + * @return \OCP\Settings\IManager |
|
1983 | + */ |
|
1984 | + public function getSettingsManager() { |
|
1985 | + return $this->query('SettingsManager'); |
|
1986 | + } |
|
1987 | + |
|
1988 | + /** |
|
1989 | + * @return \OCP\Files\IAppData |
|
1990 | + */ |
|
1991 | + public function getAppDataDir($app) { |
|
1992 | + /** @var \OC\Files\AppData\Factory $factory */ |
|
1993 | + $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
1994 | + return $factory->get($app); |
|
1995 | + } |
|
1996 | + |
|
1997 | + /** |
|
1998 | + * @return \OCP\Lockdown\ILockdownManager |
|
1999 | + */ |
|
2000 | + public function getLockdownManager() { |
|
2001 | + return $this->query('LockdownManager'); |
|
2002 | + } |
|
2003 | + |
|
2004 | + /** |
|
2005 | + * @return \OCP\Federation\ICloudIdManager |
|
2006 | + */ |
|
2007 | + public function getCloudIdManager() { |
|
2008 | + return $this->query(ICloudIdManager::class); |
|
2009 | + } |
|
2010 | + |
|
2011 | + /** |
|
2012 | + * @return \OCP\GlobalScale\IConfig |
|
2013 | + */ |
|
2014 | + public function getGlobalScaleConfig() { |
|
2015 | + return $this->query(IConfig::class); |
|
2016 | + } |
|
2017 | + |
|
2018 | + /** |
|
2019 | + * @return \OCP\Federation\ICloudFederationProviderManager |
|
2020 | + */ |
|
2021 | + public function getCloudFederationProviderManager() { |
|
2022 | + return $this->query(ICloudFederationProviderManager::class); |
|
2023 | + } |
|
2024 | + |
|
2025 | + /** |
|
2026 | + * @return \OCP\Remote\Api\IApiFactory |
|
2027 | + */ |
|
2028 | + public function getRemoteApiFactory() { |
|
2029 | + return $this->query(IApiFactory::class); |
|
2030 | + } |
|
2031 | + |
|
2032 | + /** |
|
2033 | + * @return \OCP\Federation\ICloudFederationFactory |
|
2034 | + */ |
|
2035 | + public function getCloudFederationFactory() { |
|
2036 | + return $this->query(ICloudFederationFactory::class); |
|
2037 | + } |
|
2038 | + |
|
2039 | + /** |
|
2040 | + * @return \OCP\Remote\IInstanceFactory |
|
2041 | + */ |
|
2042 | + public function getRemoteInstanceFactory() { |
|
2043 | + return $this->query(IInstanceFactory::class); |
|
2044 | + } |
|
2045 | + |
|
2046 | + /** |
|
2047 | + * @return IStorageFactory |
|
2048 | + */ |
|
2049 | + public function getStorageFactory() { |
|
2050 | + return $this->query(IStorageFactory::class); |
|
2051 | + } |
|
2052 | + |
|
2053 | + /** |
|
2054 | + * Get the Preview GeneratorHelper |
|
2055 | + * |
|
2056 | + * @return GeneratorHelper |
|
2057 | + * @since 17.0.0 |
|
2058 | + */ |
|
2059 | + public function getGeneratorHelper() { |
|
2060 | + return $this->query(\OC\Preview\GeneratorHelper::class); |
|
2061 | + } |
|
2062 | 2062 | } |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | // To find out if we are running from CLI or not |
184 | 184 | $this->registerParameter('isCLI', \OC::$CLI); |
185 | 185 | |
186 | - $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
186 | + $this->registerService(\OCP\IServerContainer::class, function(IServerContainer $c) { |
|
187 | 187 | return $c; |
188 | 188 | }); |
189 | 189 | |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | $this->registerAlias(IActionFactory::class, ActionFactory::class); |
205 | 205 | |
206 | 206 | |
207 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
207 | + $this->registerService(\OCP\IPreview::class, function(Server $c) { |
|
208 | 208 | return new PreviewManager( |
209 | 209 | $c->getConfig(), |
210 | 210 | $c->getRootFolder(), |
@@ -216,13 +216,13 @@ discard block |
||
216 | 216 | }); |
217 | 217 | $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
218 | 218 | |
219 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
219 | + $this->registerService(\OC\Preview\Watcher::class, function(Server $c) { |
|
220 | 220 | return new \OC\Preview\Watcher( |
221 | 221 | $c->getAppDataDir('preview') |
222 | 222 | ); |
223 | 223 | }); |
224 | 224 | |
225 | - $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) { |
|
225 | + $this->registerService(\OCP\Encryption\IManager::class, function(Server $c) { |
|
226 | 226 | $view = new View(); |
227 | 227 | $util = new Encryption\Util( |
228 | 228 | $view, |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | }); |
242 | 242 | $this->registerAlias('EncryptionManager', \OCP\Encryption\IManager::class); |
243 | 243 | |
244 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
244 | + $this->registerService('EncryptionFileHelper', function(Server $c) { |
|
245 | 245 | $util = new Encryption\Util( |
246 | 246 | new View(), |
247 | 247 | $c->getUserManager(), |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | ); |
256 | 256 | }); |
257 | 257 | |
258 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
258 | + $this->registerService('EncryptionKeyStorage', function(Server $c) { |
|
259 | 259 | $view = new View(); |
260 | 260 | $util = new Encryption\Util( |
261 | 261 | $view, |
@@ -266,30 +266,30 @@ discard block |
||
266 | 266 | |
267 | 267 | return new Encryption\Keys\Storage($view, $util); |
268 | 268 | }); |
269 | - $this->registerService('TagMapper', function (Server $c) { |
|
269 | + $this->registerService('TagMapper', function(Server $c) { |
|
270 | 270 | return new TagMapper($c->getDatabaseConnection()); |
271 | 271 | }); |
272 | 272 | |
273 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
273 | + $this->registerService(\OCP\ITagManager::class, function(Server $c) { |
|
274 | 274 | $tagMapper = $c->query('TagMapper'); |
275 | 275 | return new TagManager($tagMapper, $c->getUserSession()); |
276 | 276 | }); |
277 | 277 | $this->registerAlias('TagManager', \OCP\ITagManager::class); |
278 | 278 | |
279 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
279 | + $this->registerService('SystemTagManagerFactory', function(Server $c) { |
|
280 | 280 | $config = $c->getConfig(); |
281 | 281 | $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
282 | 282 | return new $factoryClass($this); |
283 | 283 | }); |
284 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
284 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function(Server $c) { |
|
285 | 285 | return $c->query('SystemTagManagerFactory')->getManager(); |
286 | 286 | }); |
287 | 287 | $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
288 | 288 | |
289 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
289 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function(Server $c) { |
|
290 | 290 | return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
291 | 291 | }); |
292 | - $this->registerService('RootFolder', function (Server $c) { |
|
292 | + $this->registerService('RootFolder', function(Server $c) { |
|
293 | 293 | $manager = \OC\Files\Filesystem::getMountManager(null); |
294 | 294 | $view = new View(); |
295 | 295 | $root = new Root( |
@@ -310,8 +310,8 @@ discard block |
||
310 | 310 | }); |
311 | 311 | $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
312 | 312 | |
313 | - $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
314 | - return new LazyRoot(function () use ($c) { |
|
313 | + $this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) { |
|
314 | + return new LazyRoot(function() use ($c) { |
|
315 | 315 | return $c->query('RootFolder'); |
316 | 316 | }); |
317 | 317 | }); |
@@ -320,24 +320,24 @@ discard block |
||
320 | 320 | $this->registerAlias('UserManager', \OC\User\Manager::class); |
321 | 321 | $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
322 | 322 | |
323 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
323 | + $this->registerService(\OCP\IGroupManager::class, function(Server $c) { |
|
324 | 324 | $groupManager = new \OC\Group\Manager($this->getUserManager(), $c->getEventDispatcher(), $this->getLogger()); |
325 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
325 | + $groupManager->listen('\OC\Group', 'preCreate', function($gid) { |
|
326 | 326 | \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
327 | 327 | }); |
328 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
328 | + $groupManager->listen('\OC\Group', 'postCreate', function(\OC\Group\Group $gid) { |
|
329 | 329 | \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
330 | 330 | }); |
331 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
331 | + $groupManager->listen('\OC\Group', 'preDelete', function(\OC\Group\Group $group) { |
|
332 | 332 | \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
333 | 333 | }); |
334 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
334 | + $groupManager->listen('\OC\Group', 'postDelete', function(\OC\Group\Group $group) { |
|
335 | 335 | \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
336 | 336 | }); |
337 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
337 | + $groupManager->listen('\OC\Group', 'preAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
338 | 338 | \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
339 | 339 | }); |
340 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
340 | + $groupManager->listen('\OC\Group', 'postAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
341 | 341 | \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
342 | 342 | //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
343 | 343 | \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | }); |
347 | 347 | $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
348 | 348 | |
349 | - $this->registerService(Store::class, function (Server $c) { |
|
349 | + $this->registerService(Store::class, function(Server $c) { |
|
350 | 350 | $session = $c->getSession(); |
351 | 351 | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
352 | 352 | $tokenProvider = $c->query(IProvider::class); |
@@ -357,13 +357,13 @@ discard block |
||
357 | 357 | return new Store($session, $logger, $tokenProvider); |
358 | 358 | }); |
359 | 359 | $this->registerAlias(IStore::class, Store::class); |
360 | - $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) { |
|
360 | + $this->registerService(Authentication\Token\DefaultTokenMapper::class, function(Server $c) { |
|
361 | 361 | $dbConnection = $c->getDatabaseConnection(); |
362 | 362 | return new Authentication\Token\DefaultTokenMapper($dbConnection); |
363 | 363 | }); |
364 | 364 | $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
365 | 365 | |
366 | - $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
366 | + $this->registerService(\OC\User\Session::class, function(Server $c) { |
|
367 | 367 | $manager = $c->getUserManager(); |
368 | 368 | $session = new \OC\Session\Memory(''); |
369 | 369 | $timeFactory = new TimeFactory(); |
@@ -388,45 +388,45 @@ discard block |
||
388 | 388 | $c->getLogger(), |
389 | 389 | $c->query(IEventDispatcher::class) |
390 | 390 | ); |
391 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
391 | + $userSession->listen('\OC\User', 'preCreateUser', function($uid, $password) { |
|
392 | 392 | \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
393 | 393 | }); |
394 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
394 | + $userSession->listen('\OC\User', 'postCreateUser', function($user, $password) { |
|
395 | 395 | /** @var $user \OC\User\User */ |
396 | 396 | \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
397 | 397 | }); |
398 | - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
|
398 | + $userSession->listen('\OC\User', 'preDelete', function($user) use ($dispatcher) { |
|
399 | 399 | /** @var $user \OC\User\User */ |
400 | 400 | \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
401 | 401 | $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
402 | 402 | }); |
403 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
403 | + $userSession->listen('\OC\User', 'postDelete', function($user) { |
|
404 | 404 | /** @var $user \OC\User\User */ |
405 | 405 | \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
406 | 406 | }); |
407 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
407 | + $userSession->listen('\OC\User', 'preSetPassword', function($user, $password, $recoveryPassword) { |
|
408 | 408 | /** @var $user \OC\User\User */ |
409 | 409 | \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
410 | 410 | }); |
411 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
411 | + $userSession->listen('\OC\User', 'postSetPassword', function($user, $password, $recoveryPassword) { |
|
412 | 412 | /** @var $user \OC\User\User */ |
413 | 413 | \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
414 | 414 | }); |
415 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
415 | + $userSession->listen('\OC\User', 'preLogin', function($uid, $password) { |
|
416 | 416 | \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
417 | 417 | }); |
418 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password, $isTokenLogin) { |
|
418 | + $userSession->listen('\OC\User', 'postLogin', function($user, $password, $isTokenLogin) { |
|
419 | 419 | /** @var $user \OC\User\User */ |
420 | 420 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'isTokenLogin' => $isTokenLogin)); |
421 | 421 | }); |
422 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
422 | + $userSession->listen('\OC\User', 'postRememberedLogin', function($user, $password) { |
|
423 | 423 | /** @var $user \OC\User\User */ |
424 | 424 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
425 | 425 | }); |
426 | - $userSession->listen('\OC\User', 'logout', function () { |
|
426 | + $userSession->listen('\OC\User', 'logout', function() { |
|
427 | 427 | \OC_Hook::emit('OC_User', 'logout', array()); |
428 | 428 | }); |
429 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
429 | + $userSession->listen('\OC\User', 'changeUser', function($user, $feature, $value, $oldValue) { |
|
430 | 430 | /** @var $user \OC\User\User */ |
431 | 431 | \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
432 | 432 | }); |
@@ -440,7 +440,7 @@ discard block |
||
440 | 440 | $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
441 | 441 | $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
442 | 442 | |
443 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
443 | + $this->registerService(\OC\AllConfig::class, function(Server $c) { |
|
444 | 444 | return new \OC\AllConfig( |
445 | 445 | $c->getSystemConfig() |
446 | 446 | ); |
@@ -448,18 +448,18 @@ discard block |
||
448 | 448 | $this->registerAlias('AllConfig', \OC\AllConfig::class); |
449 | 449 | $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
450 | 450 | |
451 | - $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
451 | + $this->registerService(\OC\SystemConfig::class, function($c) use ($config) { |
|
452 | 452 | return new \OC\SystemConfig($config); |
453 | 453 | }); |
454 | 454 | $this->registerAlias('SystemConfig', \OC\SystemConfig::class); |
455 | 455 | |
456 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
456 | + $this->registerService(\OC\AppConfig::class, function(Server $c) { |
|
457 | 457 | return new \OC\AppConfig($c->getDatabaseConnection()); |
458 | 458 | }); |
459 | 459 | $this->registerAlias('AppConfig', \OC\AppConfig::class); |
460 | 460 | $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
461 | 461 | |
462 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
462 | + $this->registerService(\OCP\L10N\IFactory::class, function(Server $c) { |
|
463 | 463 | return new \OC\L10N\Factory( |
464 | 464 | $c->getConfig(), |
465 | 465 | $c->getRequest(), |
@@ -469,7 +469,7 @@ discard block |
||
469 | 469 | }); |
470 | 470 | $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
471 | 471 | |
472 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
472 | + $this->registerService(\OCP\IURLGenerator::class, function(Server $c) { |
|
473 | 473 | $config = $c->getConfig(); |
474 | 474 | $cacheFactory = $c->getMemCacheFactory(); |
475 | 475 | $request = $c->getRequest(); |
@@ -484,12 +484,12 @@ discard block |
||
484 | 484 | $this->registerAlias('AppFetcher', AppFetcher::class); |
485 | 485 | $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
486 | 486 | |
487 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
487 | + $this->registerService(\OCP\ICache::class, function($c) { |
|
488 | 488 | return new Cache\File(); |
489 | 489 | }); |
490 | 490 | $this->registerAlias('UserCache', \OCP\ICache::class); |
491 | 491 | |
492 | - $this->registerService(Factory::class, function (Server $c) { |
|
492 | + $this->registerService(Factory::class, function(Server $c) { |
|
493 | 493 | |
494 | 494 | $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
495 | 495 | ArrayCache::class, |
@@ -504,7 +504,7 @@ discard block |
||
504 | 504 | $version = implode(',', $v); |
505 | 505 | $instanceId = \OC_Util::getInstanceId(); |
506 | 506 | $path = \OC::$SERVERROOT; |
507 | - $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
507 | + $prefix = md5($instanceId.'-'.$version.'-'.$path); |
|
508 | 508 | return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
509 | 509 | $config->getSystemValue('memcache.local', null), |
510 | 510 | $config->getSystemValue('memcache.distributed', null), |
@@ -517,12 +517,12 @@ discard block |
||
517 | 517 | $this->registerAlias('MemCacheFactory', Factory::class); |
518 | 518 | $this->registerAlias(ICacheFactory::class, Factory::class); |
519 | 519 | |
520 | - $this->registerService('RedisFactory', function (Server $c) { |
|
520 | + $this->registerService('RedisFactory', function(Server $c) { |
|
521 | 521 | $systemConfig = $c->getSystemConfig(); |
522 | 522 | return new RedisFactory($systemConfig); |
523 | 523 | }); |
524 | 524 | |
525 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
525 | + $this->registerService(\OCP\Activity\IManager::class, function(Server $c) { |
|
526 | 526 | return new \OC\Activity\Manager( |
527 | 527 | $c->getRequest(), |
528 | 528 | $c->getUserSession(), |
@@ -532,7 +532,7 @@ discard block |
||
532 | 532 | }); |
533 | 533 | $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
534 | 534 | |
535 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
535 | + $this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) { |
|
536 | 536 | return new \OC\Activity\EventMerger( |
537 | 537 | $c->getL10N('lib') |
538 | 538 | ); |
@@ -554,7 +554,7 @@ discard block |
||
554 | 554 | $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
555 | 555 | $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
556 | 556 | |
557 | - $this->registerService(\OC\Log::class, function (Server $c) { |
|
557 | + $this->registerService(\OC\Log::class, function(Server $c) { |
|
558 | 558 | $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
559 | 559 | $factory = new LogFactory($c, $this->getSystemConfig()); |
560 | 560 | $logger = $factory->get($logType); |
@@ -565,11 +565,11 @@ discard block |
||
565 | 565 | $this->registerAlias(\OCP\ILogger::class, \OC\Log::class); |
566 | 566 | $this->registerAlias('Logger', \OC\Log::class); |
567 | 567 | |
568 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
568 | + $this->registerService(ILogFactory::class, function(Server $c) { |
|
569 | 569 | return new LogFactory($c, $this->getSystemConfig()); |
570 | 570 | }); |
571 | 571 | |
572 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
572 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function(Server $c) { |
|
573 | 573 | $config = $c->getConfig(); |
574 | 574 | return new \OC\BackgroundJob\JobList( |
575 | 575 | $c->getDatabaseConnection(), |
@@ -579,7 +579,7 @@ discard block |
||
579 | 579 | }); |
580 | 580 | $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
581 | 581 | |
582 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
582 | + $this->registerService(\OCP\Route\IRouter::class, function(Server $c) { |
|
583 | 583 | $cacheFactory = $c->getMemCacheFactory(); |
584 | 584 | $logger = $c->getLogger(); |
585 | 585 | if ($cacheFactory->isLocalCacheAvailable()) { |
@@ -591,39 +591,39 @@ discard block |
||
591 | 591 | }); |
592 | 592 | $this->registerAlias('Router', \OCP\Route\IRouter::class); |
593 | 593 | |
594 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
594 | + $this->registerService(\OCP\ISearch::class, function($c) { |
|
595 | 595 | return new Search(); |
596 | 596 | }); |
597 | 597 | $this->registerAlias('Search', \OCP\ISearch::class); |
598 | 598 | |
599 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
599 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) { |
|
600 | 600 | return new \OC\Security\RateLimiting\Backend\MemoryCache( |
601 | 601 | $this->getMemCacheFactory(), |
602 | 602 | new \OC\AppFramework\Utility\TimeFactory() |
603 | 603 | ); |
604 | 604 | }); |
605 | 605 | |
606 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
606 | + $this->registerService(\OCP\Security\ISecureRandom::class, function($c) { |
|
607 | 607 | return new SecureRandom(); |
608 | 608 | }); |
609 | 609 | $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
610 | 610 | |
611 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
611 | + $this->registerService(\OCP\Security\ICrypto::class, function(Server $c) { |
|
612 | 612 | return new Crypto($c->getConfig(), $c->getSecureRandom()); |
613 | 613 | }); |
614 | 614 | $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
615 | 615 | |
616 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
616 | + $this->registerService(\OCP\Security\IHasher::class, function(Server $c) { |
|
617 | 617 | return new Hasher($c->getConfig()); |
618 | 618 | }); |
619 | 619 | $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
620 | 620 | |
621 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
621 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function(Server $c) { |
|
622 | 622 | return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
623 | 623 | }); |
624 | 624 | $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
625 | 625 | |
626 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
626 | + $this->registerService(IDBConnection::class, function(Server $c) { |
|
627 | 627 | $systemConfig = $c->getSystemConfig(); |
628 | 628 | $factory = new \OC\DB\ConnectionFactory($systemConfig); |
629 | 629 | $type = $systemConfig->getValue('dbtype', 'sqlite'); |
@@ -638,7 +638,7 @@ discard block |
||
638 | 638 | $this->registerAlias('DatabaseConnection', IDBConnection::class); |
639 | 639 | |
640 | 640 | |
641 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
641 | + $this->registerService(\OCP\Http\Client\IClientService::class, function(Server $c) { |
|
642 | 642 | $user = \OC_User::getUser(); |
643 | 643 | $uid = $user ? $user : null; |
644 | 644 | return new ClientService( |
@@ -653,7 +653,7 @@ discard block |
||
653 | 653 | ); |
654 | 654 | }); |
655 | 655 | $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
656 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
656 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function(Server $c) { |
|
657 | 657 | $eventLogger = new EventLogger(); |
658 | 658 | if ($c->getSystemConfig()->getValue('debug', false)) { |
659 | 659 | // In debug mode, module is being activated by default |
@@ -663,7 +663,7 @@ discard block |
||
663 | 663 | }); |
664 | 664 | $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
665 | 665 | |
666 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
666 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function(Server $c) { |
|
667 | 667 | $queryLogger = new QueryLogger(); |
668 | 668 | if ($c->getSystemConfig()->getValue('debug', false)) { |
669 | 669 | // In debug mode, module is being activated by default |
@@ -673,7 +673,7 @@ discard block |
||
673 | 673 | }); |
674 | 674 | $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
675 | 675 | |
676 | - $this->registerService(TempManager::class, function (Server $c) { |
|
676 | + $this->registerService(TempManager::class, function(Server $c) { |
|
677 | 677 | return new TempManager( |
678 | 678 | $c->getLogger(), |
679 | 679 | $c->getConfig() |
@@ -682,7 +682,7 @@ discard block |
||
682 | 682 | $this->registerAlias('TempManager', TempManager::class); |
683 | 683 | $this->registerAlias(ITempManager::class, TempManager::class); |
684 | 684 | |
685 | - $this->registerService(AppManager::class, function (Server $c) { |
|
685 | + $this->registerService(AppManager::class, function(Server $c) { |
|
686 | 686 | return new \OC\App\AppManager( |
687 | 687 | $c->getUserSession(), |
688 | 688 | $c->query(\OC\AppConfig::class), |
@@ -695,7 +695,7 @@ discard block |
||
695 | 695 | $this->registerAlias('AppManager', AppManager::class); |
696 | 696 | $this->registerAlias(IAppManager::class, AppManager::class); |
697 | 697 | |
698 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
698 | + $this->registerService(\OCP\IDateTimeZone::class, function(Server $c) { |
|
699 | 699 | return new DateTimeZone( |
700 | 700 | $c->getConfig(), |
701 | 701 | $c->getSession() |
@@ -703,7 +703,7 @@ discard block |
||
703 | 703 | }); |
704 | 704 | $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
705 | 705 | |
706 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
706 | + $this->registerService(\OCP\IDateTimeFormatter::class, function(Server $c) { |
|
707 | 707 | $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
708 | 708 | |
709 | 709 | return new DateTimeFormatter( |
@@ -713,7 +713,7 @@ discard block |
||
713 | 713 | }); |
714 | 714 | $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
715 | 715 | |
716 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
716 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function(Server $c) { |
|
717 | 717 | $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
718 | 718 | $listener = new UserMountCacheListener($mountCache); |
719 | 719 | $listener->listen($c->getUserManager()); |
@@ -721,7 +721,7 @@ discard block |
||
721 | 721 | }); |
722 | 722 | $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
723 | 723 | |
724 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
724 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function(Server $c) { |
|
725 | 725 | $loader = \OC\Files\Filesystem::getLoader(); |
726 | 726 | $mountCache = $c->query('UserMountCache'); |
727 | 727 | $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
@@ -737,10 +737,10 @@ discard block |
||
737 | 737 | }); |
738 | 738 | $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
739 | 739 | |
740 | - $this->registerService('IniWrapper', function ($c) { |
|
740 | + $this->registerService('IniWrapper', function($c) { |
|
741 | 741 | return new IniGetWrapper(); |
742 | 742 | }); |
743 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
743 | + $this->registerService('AsyncCommandBus', function(Server $c) { |
|
744 | 744 | $busClass = $c->getConfig()->getSystemValue('commandbus'); |
745 | 745 | if ($busClass) { |
746 | 746 | list($app, $class) = explode('::', $busClass, 2); |
@@ -755,10 +755,10 @@ discard block |
||
755 | 755 | return new CronBus($jobList); |
756 | 756 | } |
757 | 757 | }); |
758 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
758 | + $this->registerService('TrustedDomainHelper', function($c) { |
|
759 | 759 | return new TrustedDomainHelper($this->getConfig()); |
760 | 760 | }); |
761 | - $this->registerService(Throttler::class, function (Server $c) { |
|
761 | + $this->registerService(Throttler::class, function(Server $c) { |
|
762 | 762 | return new Throttler( |
763 | 763 | $c->getDatabaseConnection(), |
764 | 764 | new TimeFactory(), |
@@ -767,7 +767,7 @@ discard block |
||
767 | 767 | ); |
768 | 768 | }); |
769 | 769 | $this->registerAlias('Throttler', Throttler::class); |
770 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
770 | + $this->registerService('IntegrityCodeChecker', function(Server $c) { |
|
771 | 771 | // IConfig and IAppManager requires a working database. This code |
772 | 772 | // might however be called when ownCloud is not yet setup. |
773 | 773 | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
@@ -789,7 +789,7 @@ discard block |
||
789 | 789 | $c->getMimeTypeDetector() |
790 | 790 | ); |
791 | 791 | }); |
792 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
792 | + $this->registerService(\OCP\IRequest::class, function($c) { |
|
793 | 793 | if (isset($this['urlParams'])) { |
794 | 794 | $urlParams = $this['urlParams']; |
795 | 795 | } else { |
@@ -825,7 +825,7 @@ discard block |
||
825 | 825 | }); |
826 | 826 | $this->registerAlias('Request', \OCP\IRequest::class); |
827 | 827 | |
828 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
828 | + $this->registerService(\OCP\Mail\IMailer::class, function(Server $c) { |
|
829 | 829 | return new Mailer( |
830 | 830 | $c->getConfig(), |
831 | 831 | $c->getLogger(), |
@@ -836,7 +836,7 @@ discard block |
||
836 | 836 | }); |
837 | 837 | $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
838 | 838 | |
839 | - $this->registerService('LDAPProvider', function (Server $c) { |
|
839 | + $this->registerService('LDAPProvider', function(Server $c) { |
|
840 | 840 | $config = $c->getConfig(); |
841 | 841 | $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
842 | 842 | if (is_null($factoryClass)) { |
@@ -846,7 +846,7 @@ discard block |
||
846 | 846 | $factory = new $factoryClass($this); |
847 | 847 | return $factory->getLDAPProvider(); |
848 | 848 | }); |
849 | - $this->registerService(ILockingProvider::class, function (Server $c) { |
|
849 | + $this->registerService(ILockingProvider::class, function(Server $c) { |
|
850 | 850 | $ini = $c->getIniWrapper(); |
851 | 851 | $config = $c->getConfig(); |
852 | 852 | $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
@@ -869,30 +869,30 @@ discard block |
||
869 | 869 | }); |
870 | 870 | $this->registerAlias('LockingProvider', ILockingProvider::class); |
871 | 871 | |
872 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
872 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function() { |
|
873 | 873 | return new \OC\Files\Mount\Manager(); |
874 | 874 | }); |
875 | 875 | $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
876 | 876 | |
877 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
877 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function(Server $c) { |
|
878 | 878 | return new \OC\Files\Type\Detection( |
879 | 879 | $c->getURLGenerator(), |
880 | 880 | \OC::$configDir, |
881 | - \OC::$SERVERROOT . '/resources/config/' |
|
881 | + \OC::$SERVERROOT.'/resources/config/' |
|
882 | 882 | ); |
883 | 883 | }); |
884 | 884 | $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
885 | 885 | |
886 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
886 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function(Server $c) { |
|
887 | 887 | return new \OC\Files\Type\Loader( |
888 | 888 | $c->getDatabaseConnection() |
889 | 889 | ); |
890 | 890 | }); |
891 | 891 | $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
892 | - $this->registerService(BundleFetcher::class, function () { |
|
892 | + $this->registerService(BundleFetcher::class, function() { |
|
893 | 893 | return new BundleFetcher($this->getL10N('lib')); |
894 | 894 | }); |
895 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
895 | + $this->registerService(\OCP\Notification\IManager::class, function(Server $c) { |
|
896 | 896 | return new Manager( |
897 | 897 | $c->query(IValidator::class), |
898 | 898 | $c->getLogger() |
@@ -900,19 +900,19 @@ discard block |
||
900 | 900 | }); |
901 | 901 | $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
902 | 902 | |
903 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
903 | + $this->registerService(\OC\CapabilitiesManager::class, function(Server $c) { |
|
904 | 904 | $manager = new \OC\CapabilitiesManager($c->getLogger()); |
905 | - $manager->registerCapability(function () use ($c) { |
|
905 | + $manager->registerCapability(function() use ($c) { |
|
906 | 906 | return new \OC\OCS\CoreCapabilities($c->getConfig()); |
907 | 907 | }); |
908 | - $manager->registerCapability(function () use ($c) { |
|
908 | + $manager->registerCapability(function() use ($c) { |
|
909 | 909 | return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
910 | 910 | }); |
911 | 911 | return $manager; |
912 | 912 | }); |
913 | 913 | $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
914 | 914 | |
915 | - $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
915 | + $this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) { |
|
916 | 916 | $config = $c->getConfig(); |
917 | 917 | $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
918 | 918 | /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
@@ -922,7 +922,7 @@ discard block |
||
922 | 922 | $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
923 | 923 | $manager = $c->getUserManager(); |
924 | 924 | $user = $manager->get($id); |
925 | - if(is_null($user)) { |
|
925 | + if (is_null($user)) { |
|
926 | 926 | $l = $c->getL10N('core'); |
927 | 927 | $displayName = $l->t('Unknown user'); |
928 | 928 | } else { |
@@ -935,7 +935,7 @@ discard block |
||
935 | 935 | }); |
936 | 936 | $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
937 | 937 | |
938 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
938 | + $this->registerService('ThemingDefaults', function(Server $c) { |
|
939 | 939 | /* |
940 | 940 | * Dark magic for autoloader. |
941 | 941 | * If we do a class_exists it will try to load the class which will |
@@ -963,7 +963,7 @@ discard block |
||
963 | 963 | } |
964 | 964 | return new \OC_Defaults(); |
965 | 965 | }); |
966 | - $this->registerService(SCSSCacher::class, function (Server $c) { |
|
966 | + $this->registerService(SCSSCacher::class, function(Server $c) { |
|
967 | 967 | return new SCSSCacher( |
968 | 968 | $c->getLogger(), |
969 | 969 | $c->query(\OC\Files\AppData\Factory::class), |
@@ -976,7 +976,7 @@ discard block |
||
976 | 976 | new TimeFactory() |
977 | 977 | ); |
978 | 978 | }); |
979 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
979 | + $this->registerService(JSCombiner::class, function(Server $c) { |
|
980 | 980 | return new JSCombiner( |
981 | 981 | $c->getAppDataDir('js'), |
982 | 982 | $c->getURLGenerator(), |
@@ -989,7 +989,7 @@ discard block |
||
989 | 989 | $this->registerAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class); |
990 | 990 | $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class); |
991 | 991 | |
992 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
992 | + $this->registerService('CryptoWrapper', function(Server $c) { |
|
993 | 993 | // FIXME: Instantiiated here due to cyclic dependency |
994 | 994 | $request = new Request( |
995 | 995 | [ |
@@ -1014,7 +1014,7 @@ discard block |
||
1014 | 1014 | $request |
1015 | 1015 | ); |
1016 | 1016 | }); |
1017 | - $this->registerService(CsrfTokenManager::class, function (Server $c) { |
|
1017 | + $this->registerService(CsrfTokenManager::class, function(Server $c) { |
|
1018 | 1018 | $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
1019 | 1019 | |
1020 | 1020 | return new CsrfTokenManager( |
@@ -1023,20 +1023,20 @@ discard block |
||
1023 | 1023 | ); |
1024 | 1024 | }); |
1025 | 1025 | $this->registerAlias('CsrfTokenManager', CsrfTokenManager::class); |
1026 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
1026 | + $this->registerService(SessionStorage::class, function(Server $c) { |
|
1027 | 1027 | return new SessionStorage($c->getSession()); |
1028 | 1028 | }); |
1029 | 1029 | $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, \OC\Security\CSP\ContentSecurityPolicyManager::class); |
1030 | 1030 | $this->registerAlias('ContentSecurityPolicyManager', \OC\Security\CSP\ContentSecurityPolicyManager::class); |
1031 | 1031 | |
1032 | - $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
1032 | + $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) { |
|
1033 | 1033 | return new ContentSecurityPolicyNonceManager( |
1034 | 1034 | $c->getCsrfTokenManager(), |
1035 | 1035 | $c->getRequest() |
1036 | 1036 | ); |
1037 | 1037 | }); |
1038 | 1038 | |
1039 | - $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
1039 | + $this->registerService(\OCP\Share\IManager::class, function(Server $c) { |
|
1040 | 1040 | $config = $c->getConfig(); |
1041 | 1041 | $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
1042 | 1042 | /** @var \OCP\Share\IProviderFactory $factory */ |
@@ -1083,7 +1083,7 @@ discard block |
||
1083 | 1083 | |
1084 | 1084 | $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
1085 | 1085 | |
1086 | - $this->registerService('SettingsManager', function (Server $c) { |
|
1086 | + $this->registerService('SettingsManager', function(Server $c) { |
|
1087 | 1087 | $manager = new \OC\Settings\Manager( |
1088 | 1088 | $c->getLogger(), |
1089 | 1089 | $c->getL10NFactory(), |
@@ -1092,36 +1092,36 @@ discard block |
||
1092 | 1092 | ); |
1093 | 1093 | return $manager; |
1094 | 1094 | }); |
1095 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1095 | + $this->registerService(\OC\Files\AppData\Factory::class, function(Server $c) { |
|
1096 | 1096 | return new \OC\Files\AppData\Factory( |
1097 | 1097 | $c->getRootFolder(), |
1098 | 1098 | $c->getSystemConfig() |
1099 | 1099 | ); |
1100 | 1100 | }); |
1101 | 1101 | |
1102 | - $this->registerService('LockdownManager', function (Server $c) { |
|
1103 | - return new LockdownManager(function () use ($c) { |
|
1102 | + $this->registerService('LockdownManager', function(Server $c) { |
|
1103 | + return new LockdownManager(function() use ($c) { |
|
1104 | 1104 | return $c->getSession(); |
1105 | 1105 | }); |
1106 | 1106 | }); |
1107 | 1107 | |
1108 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1108 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function(Server $c) { |
|
1109 | 1109 | return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
1110 | 1110 | }); |
1111 | 1111 | |
1112 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1112 | + $this->registerService(ICloudIdManager::class, function(Server $c) { |
|
1113 | 1113 | return new CloudIdManager(); |
1114 | 1114 | }); |
1115 | 1115 | |
1116 | - $this->registerService(IConfig::class, function (Server $c) { |
|
1116 | + $this->registerService(IConfig::class, function(Server $c) { |
|
1117 | 1117 | return new GlobalScale\Config($c->getConfig()); |
1118 | 1118 | }); |
1119 | 1119 | |
1120 | - $this->registerService(ICloudFederationProviderManager::class, function (Server $c) { |
|
1120 | + $this->registerService(ICloudFederationProviderManager::class, function(Server $c) { |
|
1121 | 1121 | return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger()); |
1122 | 1122 | }); |
1123 | 1123 | |
1124 | - $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
1124 | + $this->registerService(ICloudFederationFactory::class, function(Server $c) { |
|
1125 | 1125 | return new CloudFederationFactory(); |
1126 | 1126 | }); |
1127 | 1127 | |
@@ -1131,18 +1131,18 @@ discard block |
||
1131 | 1131 | $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
1132 | 1132 | $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
1133 | 1133 | |
1134 | - $this->registerService(Defaults::class, function (Server $c) { |
|
1134 | + $this->registerService(Defaults::class, function(Server $c) { |
|
1135 | 1135 | return new Defaults( |
1136 | 1136 | $c->getThemingDefaults() |
1137 | 1137 | ); |
1138 | 1138 | }); |
1139 | 1139 | $this->registerAlias('Defaults', \OCP\Defaults::class); |
1140 | 1140 | |
1141 | - $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1141 | + $this->registerService(\OCP\ISession::class, function(SimpleContainer $c) { |
|
1142 | 1142 | return $c->query(\OCP\IUserSession::class)->getSession(); |
1143 | 1143 | }); |
1144 | 1144 | |
1145 | - $this->registerService(IShareHelper::class, function (Server $c) { |
|
1145 | + $this->registerService(IShareHelper::class, function(Server $c) { |
|
1146 | 1146 | return new ShareHelper( |
1147 | 1147 | $c->query(\OCP\Share\IManager::class) |
1148 | 1148 | ); |
@@ -1230,11 +1230,11 @@ discard block |
||
1230 | 1230 | // no avatar to remove |
1231 | 1231 | } catch (\Exception $e) { |
1232 | 1232 | // Ignore exceptions |
1233 | - $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1233 | + $logger->info('Could not cleanup avatar of '.$user->getUID()); |
|
1234 | 1234 | } |
1235 | 1235 | }); |
1236 | 1236 | |
1237 | - $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1237 | + $dispatcher->addListener('OCP\IUser::changeUser', function(GenericEvent $e) { |
|
1238 | 1238 | $manager = $this->getAvatarManager(); |
1239 | 1239 | /** @var IUser $user */ |
1240 | 1240 | $user = $e->getSubject(); |
@@ -1390,7 +1390,7 @@ discard block |
||
1390 | 1390 | * @deprecated since 9.2.0 use IAppData |
1391 | 1391 | */ |
1392 | 1392 | public function getAppFolder() { |
1393 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
1393 | + $dir = '/'.\OC_App::getCurrentApp(); |
|
1394 | 1394 | $root = $this->getRootFolder(); |
1395 | 1395 | if (!$root->nodeExists($dir)) { |
1396 | 1396 | $folder = $root->newFolder($dir); |
@@ -1965,7 +1965,7 @@ discard block |
||
1965 | 1965 | /** |
1966 | 1966 | * @return \OCP\Collaboration\AutoComplete\IManager |
1967 | 1967 | */ |
1968 | - public function getAutoCompleteManager(){ |
|
1968 | + public function getAutoCompleteManager() { |
|
1969 | 1969 | return $this->query(IManager::class); |
1970 | 1970 | } |
1971 | 1971 |