Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Server often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Server, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
81 | class Server extends ServerContainer implements IServerContainer { |
||
82 | /** @var string */ |
||
83 | private $webRoot; |
||
84 | |||
85 | /** |
||
86 | * @param string $webRoot |
||
87 | * @param \OC\Config $config |
||
88 | */ |
||
89 | 557 | public function __construct($webRoot, \OC\Config $config) { |
|
90 | 95 | parent::__construct(); |
|
91 | 95 | $this->webRoot = $webRoot; |
|
92 | |||
93 | $this->registerService('ContactsManager', function ($c) { |
||
|
|||
94 | 2 | return new ContactsManager(); |
|
95 | 95 | }); |
|
96 | |||
97 | $this->registerService('PreviewManager', function (Server $c) { |
||
98 | 3 | return new PreviewManager($c->getConfig()); |
|
99 | 95 | }); |
|
100 | |||
101 | $this->registerService('EncryptionManager', function (Server $c) { |
||
102 | 2 | $view = new View(); |
|
103 | 2 | $util = new Encryption\Util( |
|
104 | 2 | $view, |
|
105 | 2 | $c->getUserManager(), |
|
106 | 2 | $c->getGroupManager(), |
|
107 | 2 | $c->getConfig() |
|
108 | 2 | ); |
|
109 | 2 | return new Encryption\Manager( |
|
110 | 2 | $c->getConfig(), |
|
111 | 2 | $c->getLogger(), |
|
112 | 2 | $c->getL10N('core'), |
|
113 | 2 | new View(), |
|
114 | $util |
||
115 | 2 | ); |
|
116 | 95 | }); |
|
117 | |||
118 | $this->registerService('EncryptionFileHelper', function (Server $c) { |
||
119 | 2 | $util = new Encryption\Util( |
|
120 | 2 | new View(), |
|
121 | 2 | $c->getUserManager(), |
|
122 | 2 | $c->getGroupManager(), |
|
123 | 2 | $c->getConfig() |
|
124 | 2 | ); |
|
125 | 2 | return new Encryption\File($util); |
|
126 | 95 | }); |
|
127 | |||
128 | $this->registerService('EncryptionKeyStorage', function (Server $c) { |
||
129 | 2 | $view = new View(); |
|
130 | 2 | $util = new Encryption\Util( |
|
131 | 95 | $view, |
|
132 | 2 | $c->getUserManager(), |
|
133 | 2 | $c->getGroupManager(), |
|
134 | 2 | $c->getConfig() |
|
135 | 95 | ); |
|
136 | |||
137 | 2 | return new Encryption\Keys\Storage($view, $util); |
|
138 | 95 | }); |
|
139 | $this->registerService('TagMapper', function(Server $c) { |
||
140 | 5 | return new TagMapper($c->getDatabaseConnection()); |
|
141 | 95 | }); |
|
142 | $this->registerService('TagManager', function (Server $c) { |
||
143 | 3 | $tagMapper = $c->query('TagMapper'); |
|
144 | 3 | return new TagManager($tagMapper, $c->getUserSession()); |
|
145 | 95 | }); |
|
146 | $this->registerService('SystemTagManager', function (Server $c) { |
||
147 | return new SystemTag\SystemTagManager($c->getDatabaseConnection()); |
||
148 | 95 | }); |
|
149 | $this->registerService('SystemTagObjectMapper', function (Server $c) { |
||
150 | return new SystemTag\SystemTagObjectMapper($c->getDatabaseConnection(), $c->getSystemTagManager()); |
||
151 | 95 | }); |
|
152 | $this->registerService('RootFolder', function (Server $c) { |
||
153 | // TODO: get user and user manager from container as well |
||
154 | 7 | $user = \OC_User::getUser(); |
|
155 | /** @var $c SimpleContainer */ |
||
156 | 7 | $userManager = $c->query('UserManager'); |
|
157 | 7 | $user = $userManager->get($user); |
|
158 | 7 | $manager = \OC\Files\Filesystem::getMountManager(); |
|
159 | 7 | $view = new View(); |
|
160 | 7 | $root = new Root($manager, $view, $user); |
|
161 | 7 | $connector = new HookConnector($root, $view); |
|
162 | 7 | $connector->viewToNode(); |
|
163 | 7 | return $root; |
|
164 | 95 | }); |
|
165 | $this->registerService('UserManager', function (Server $c) { |
||
166 | 30 | $config = $c->getConfig(); |
|
167 | 30 | return new \OC\User\Manager($config); |
|
168 | 95 | }); |
|
169 | $this->registerService('GroupManager', function (Server $c) { |
||
170 | 10 | $groupManager = new \OC\Group\Manager($this->getUserManager()); |
|
171 | $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
||
172 | 389 | \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
173 | 399 | }); |
|
174 | $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
||
175 | 389 | \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
176 | 399 | }); |
|
177 | $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
||
178 | 384 | \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
179 | 394 | }); |
|
180 | $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
||
181 | 384 | \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
182 | 394 | }); |
|
183 | $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
||
184 | 377 | \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
185 | 387 | }); |
|
186 | $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
||
187 | 377 | \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
188 | //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
||
189 | 377 | \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
190 | 387 | }); |
|
191 | 10 | return $groupManager; |
|
192 | 95 | }); |
|
193 | $this->registerService('UserSession', function (Server $c) { |
||
194 | 14 | $manager = $c->getUserManager(); |
|
195 | |||
196 | 14 | $session = new \OC\Session\Memory(''); |
|
197 | |||
198 | 14 | $userSession = new \OC\User\Session($manager, $session); |
|
199 | $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
||
200 | 543 | \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
201 | 557 | }); |
|
202 | $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
||
203 | /** @var $user \OC\User\User */ |
||
204 | 543 | \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
205 | 557 | }); |
|
206 | $userSession->listen('\OC\User', 'preDelete', function ($user) { |
||
207 | /** @var $user \OC\User\User */ |
||
208 | 517 | \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
209 | 531 | }); |
|
210 | $userSession->listen('\OC\User', 'postDelete', function ($user) { |
||
211 | /** @var $user \OC\User\User */ |
||
212 | 517 | \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
213 | 531 | }); |
|
214 | View Code Duplication | $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
215 | /** @var $user \OC\User\User */ |
||
216 | \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
||
217 | 14 | }); |
|
218 | View Code Duplication | $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
219 | /** @var $user \OC\User\User */ |
||
220 | \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
||
221 | 14 | }); |
|
222 | $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
||
223 | 273 | \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
224 | 287 | }); |
|
225 | $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
||
226 | /** @var $user \OC\User\User */ |
||
227 | 273 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
228 | 287 | }); |
|
229 | $userSession->listen('\OC\User', 'logout', function () { |
||
230 | \OC_Hook::emit('OC_User', 'logout', array()); |
||
231 | 14 | }); |
|
232 | 14 | return $userSession; |
|
233 | 95 | }); |
|
234 | $this->registerService('NavigationManager', function ($c) { |
||
235 | 2 | return new \OC\NavigationManager(); |
|
236 | 95 | }); |
|
237 | $this->registerService('AllConfig', function (Server $c) { |
||
238 | 63 | return new \OC\AllConfig( |
|
239 | 63 | $c->getSystemConfig() |
|
240 | 63 | ); |
|
241 | 95 | }); |
|
242 | $this->registerService('SystemConfig', function ($c) use ($config) { |
||
243 | 72 | return new \OC\SystemConfig($config); |
|
244 | 95 | }); |
|
245 | $this->registerService('AppConfig', function ($c) { |
||
246 | 4 | return new \OC\AppConfig(\OC_DB::getConnection()); |
|
247 | 95 | }); |
|
248 | $this->registerService('L10NFactory', function ($c) { |
||
249 | 8 | return new \OC\L10N\Factory(); |
|
250 | 95 | }); |
|
251 | $this->registerService('URLGenerator', function (Server $c) { |
||
252 | 2 | $config = $c->getConfig(); |
|
253 | 2 | $cacheFactory = $c->getMemCacheFactory(); |
|
254 | 2 | return new \OC\URLGenerator( |
|
255 | 2 | $config, |
|
256 | $cacheFactory |
||
257 | 2 | ); |
|
258 | 95 | }); |
|
259 | $this->registerService('AppHelper', function ($c) { |
||
260 | 2 | return new \OC\AppHelper(); |
|
261 | 95 | }); |
|
262 | $this->registerService('UserCache', function ($c) { |
||
263 | 2 | return new Cache\File(); |
|
264 | 95 | }); |
|
265 | $this->registerService('MemCacheFactory', function (Server $c) { |
||
266 | 8 | $config = $c->getConfig(); |
|
267 | |||
268 | 8 | if($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
269 | $v = \OC_App::getAppVersions(); |
||
270 | $v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php')); |
||
271 | $version = implode(',', $v); |
||
272 | $instanceId = \OC_Util::getInstanceId(); |
||
273 | $path = \OC::$SERVERROOT; |
||
274 | $prefix = md5($instanceId.'-'.$version.'-'.$path); |
||
275 | return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
||
276 | $config->getSystemValue('memcache.local', null), |
||
277 | $config->getSystemValue('memcache.distributed', null), |
||
278 | $config->getSystemValue('memcache.locking', null) |
||
279 | ); |
||
280 | } |
||
281 | |||
282 | 8 | return new \OC\Memcache\Factory('', $c->getLogger(), |
|
283 | 8 | '\\OC\\Memcache\\ArrayCache', |
|
284 | 8 | '\\OC\\Memcache\\ArrayCache', |
|
285 | '\\OC\\Memcache\\ArrayCache' |
||
286 | 8 | ); |
|
287 | 95 | }); |
|
288 | $this->registerService('ActivityManager', function (Server $c) { |
||
289 | 2 | return new ActivityManager( |
|
290 | 2 | $c->getRequest(), |
|
291 | 2 | $c->getUserSession(), |
|
292 | 2 | $c->getConfig() |
|
293 | 2 | ); |
|
294 | 95 | }); |
|
295 | $this->registerService('AvatarManager', function (Server $c) { |
||
296 | 2 | return new AvatarManager( |
|
297 | 2 | $c->getUserManager(), |
|
298 | 2 | $c->getRootFolder(), |
|
299 | 2 | $c->getL10N('lib') |
|
300 | 2 | ); |
|
301 | 95 | }); |
|
302 | $this->registerService('Logger', function (Server $c) { |
||
303 | 17 | $logClass = $c->query('AllConfig')->getSystemValue('log_type', 'owncloud'); |
|
304 | 17 | $logger = 'OC_Log_' . ucfirst($logClass); |
|
305 | 17 | call_user_func(array($logger, 'init')); |
|
306 | |||
307 | 17 | return new Log($logger); |
|
308 | 95 | }); |
|
309 | $this->registerService('JobList', function (Server $c) { |
||
310 | 4 | $config = $c->getConfig(); |
|
311 | 4 | return new \OC\BackgroundJob\JobList($c->getDatabaseConnection(), $config); |
|
312 | 95 | }); |
|
313 | $this->registerService('Router', function (Server $c) { |
||
314 | 2 | $cacheFactory = $c->getMemCacheFactory(); |
|
315 | 2 | $logger = $c->getLogger(); |
|
316 | 2 | if ($cacheFactory->isAvailable()) { |
|
317 | 2 | $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger); |
|
318 | 2 | } else { |
|
319 | $router = new \OC\Route\Router($logger); |
||
320 | } |
||
321 | 2 | return $router; |
|
322 | 95 | }); |
|
323 | $this->registerService('Search', function ($c) { |
||
324 | 2 | return new Search(); |
|
325 | 95 | }); |
|
326 | $this->registerService('SecureRandom', function ($c) { |
||
327 | 9 | return new SecureRandom(); |
|
328 | 95 | }); |
|
329 | $this->registerService('Crypto', function (Server $c) { |
||
330 | 3 | return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
331 | 95 | }); |
|
332 | $this->registerService('Hasher', function (Server $c) { |
||
333 | 3 | return new Hasher($c->getConfig()); |
|
334 | 95 | }); |
|
335 | $this->registerService('DatabaseConnection', function (Server $c) { |
||
336 | 12 | $factory = new \OC\DB\ConnectionFactory(); |
|
337 | 12 | $systemConfig = $c->getSystemConfig(); |
|
338 | 12 | $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
339 | 12 | if (!$factory->isValidType($type)) { |
|
340 | throw new \OC\DatabaseException('Invalid database type'); |
||
341 | } |
||
342 | 12 | $connectionParams = $factory->createConnectionParams($systemConfig); |
|
343 | 12 | $connection = $factory->getConnection($type, $connectionParams); |
|
344 | 12 | $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
345 | 12 | return $connection; |
|
346 | 95 | }); |
|
347 | $this->registerService('Db', function (Server $c) { |
||
348 | 2 | return new Db($c->getDatabaseConnection()); |
|
349 | 95 | }); |
|
350 | $this->registerService('HTTPHelper', function (Server $c) { |
||
351 | 1 | $config = $c->getConfig(); |
|
352 | 1 | return new HTTPHelper( |
|
353 | 1 | $config, |
|
354 | 1 | $c->getHTTPClientService() |
|
355 | 1 | ); |
|
356 | 95 | }); |
|
357 | $this->registerService('HttpClientService', function (Server $c) { |
||
358 | 4 | $user = \OC_User::getUser(); |
|
359 | 4 | $uid = $user ? $user : null; |
|
360 | 4 | return new ClientService( |
|
361 | 4 | $c->getConfig(), |
|
362 | 4 | new \OC\Security\CertificateManager($uid, new View(), $c->getConfig()) |
|
363 | 4 | ); |
|
364 | 95 | }); |
|
365 | $this->registerService('EventLogger', function (Server $c) { |
||
366 | 1 | if ($c->getSystemConfig()->getValue('debug', false)) { |
|
367 | return new EventLogger(); |
||
368 | } else { |
||
369 | 1 | return new NullEventLogger(); |
|
370 | } |
||
371 | 95 | }); |
|
372 | $this->registerService('QueryLogger', function (Server $c) { |
||
373 | 13 | if ($c->getSystemConfig()->getValue('debug', false)) { |
|
374 | return new QueryLogger(); |
||
375 | } else { |
||
376 | 13 | return new NullQueryLogger(); |
|
377 | } |
||
378 | 95 | }); |
|
379 | $this->registerService('TempManager', function (Server $c) { |
||
380 | 2 | return new TempManager( |
|
381 | 2 | $c->getLogger(), |
|
382 | 2 | $c->getConfig() |
|
383 | 2 | ); |
|
384 | 95 | }); |
|
385 | $this->registerService('AppManager', function(Server $c) { |
||
386 | 2 | return new \OC\App\AppManager( |
|
387 | 2 | $c->getUserSession(), |
|
388 | 2 | $c->getAppConfig(), |
|
389 | 2 | $c->getGroupManager(), |
|
390 | 2 | $c->getMemCacheFactory() |
|
391 | 2 | ); |
|
392 | 95 | }); |
|
393 | $this->registerService('DateTimeZone', function(Server $c) { |
||
394 | 5 | return new DateTimeZone( |
|
395 | 5 | $c->getConfig(), |
|
396 | 5 | $c->getSession() |
|
397 | 5 | ); |
|
398 | 95 | }); |
|
399 | $this->registerService('DateTimeFormatter', function(Server $c) { |
||
400 | 3 | $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
401 | |||
402 | 3 | return new DateTimeFormatter( |
|
403 | 3 | $c->getDateTimeZone()->getTimeZone(), |
|
404 | 3 | $c->getL10N('lib', $language) |
|
405 | 3 | ); |
|
406 | 95 | }); |
|
407 | $this->registerService('MountConfigManager', function () { |
||
408 | 2 | $loader = \OC\Files\Filesystem::getLoader(); |
|
409 | 2 | return new \OC\Files\Config\MountProviderCollection($loader); |
|
410 | 95 | }); |
|
411 | $this->registerService('IniWrapper', function ($c) { |
||
412 | 1 | return new IniGetWrapper(); |
|
413 | 95 | }); |
|
414 | $this->registerService('AsyncCommandBus', function (Server $c) { |
||
415 | 2 | $jobList = $c->getJobList(); |
|
416 | 2 | return new AsyncBus($jobList); |
|
417 | 95 | }); |
|
418 | $this->registerService('TrustedDomainHelper', function ($c) { |
||
419 | 1 | return new TrustedDomainHelper($this->getConfig()); |
|
420 | 95 | }); |
|
421 | $this->registerService('IntegrityCodeChecker', function (Server $c) { |
||
422 | // IConfig and IAppManager requires a working database. This code |
||
423 | // might however be called when ownCloud is not yet setup. |
||
424 | if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
||
425 | $config = $c->getConfig(); |
||
426 | $appManager = $c->getAppManager(); |
||
427 | } else { |
||
428 | $config = null; |
||
429 | $appManager = null; |
||
430 | } |
||
431 | |||
432 | return new Checker( |
||
433 | new EnvironmentHelper(), |
||
434 | new FileAccessHelper(), |
||
435 | new AppLocator(), |
||
436 | $config, |
||
437 | $c->getMemCacheFactory(), |
||
438 | $appManager |
||
439 | ); |
||
440 | 95 | }); |
|
441 | $this->registerService('Request', function ($c) { |
||
442 | 4 | if (isset($this['urlParams'])) { |
|
443 | $urlParams = $this['urlParams']; |
||
444 | } else { |
||
445 | 4 | $urlParams = []; |
|
446 | } |
||
447 | |||
448 | 4 | if ($this->getSession()->exists('requesttoken')) { |
|
449 | $requestToken = $this->getSession()->get('requesttoken'); |
||
450 | } else { |
||
451 | 4 | $requestToken = false; |
|
452 | } |
||
453 | |||
454 | 4 | if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
455 | 4 | && in_array('fakeinput', stream_get_wrappers()) |
|
456 | 4 | ) { |
|
457 | $stream = 'fakeinput://data'; |
||
458 | } else { |
||
459 | 4 | $stream = 'php://input'; |
|
460 | } |
||
461 | |||
462 | 4 | return new Request( |
|
463 | [ |
||
464 | 4 | 'get' => $_GET, |
|
465 | 4 | 'post' => $_POST, |
|
466 | 4 | 'files' => $_FILES, |
|
467 | 4 | 'server' => $_SERVER, |
|
468 | 4 | 'env' => $_ENV, |
|
469 | 4 | 'cookies' => $_COOKIE, |
|
470 | 4 | 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
471 | 4 | ? $_SERVER['REQUEST_METHOD'] |
|
472 | 4 | : null, |
|
473 | 4 | 'urlParams' => $urlParams, |
|
474 | 4 | 'requesttoken' => $requestToken, |
|
475 | 4 | ], |
|
476 | 4 | $this->getSecureRandom(), |
|
477 | 4 | $this->getConfig(), |
|
478 | $stream |
||
479 | 4 | ); |
|
480 | 95 | }); |
|
481 | $this->registerService('Mailer', function(Server $c) { |
||
482 | 2 | return new Mailer( |
|
483 | 2 | $c->getConfig(), |
|
484 | 2 | $c->getLogger(), |
|
485 | 2 | new \OC_Defaults() |
|
486 | 2 | ); |
|
487 | 95 | }); |
|
488 | $this->registerService('OcsClient', function(Server $c) { |
||
489 | 2 | return new OCSClient( |
|
490 | 2 | $this->getHTTPClientService(), |
|
491 | 2 | $this->getConfig(), |
|
492 | 2 | $this->getLogger() |
|
493 | 2 | ); |
|
494 | 95 | }); |
|
495 | $this->registerService('LockingProvider', function (Server $c) { |
||
496 | 1 | if ($c->getConfig()->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
497 | /** @var \OC\Memcache\Factory $memcacheFactory */ |
||
498 | 1 | $memcacheFactory = $c->getMemCacheFactory(); |
|
499 | 1 | $memcache = $memcacheFactory->createLocking('lock'); |
|
500 | 1 | if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
501 | 1 | return new MemcacheLockingProvider($memcache); |
|
502 | } |
||
503 | return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory()); |
||
504 | } |
||
505 | return new NoopLockingProvider(); |
||
506 | 95 | }); |
|
507 | $this->registerService('MountManager', function () { |
||
508 | 1 | return new \OC\Files\Mount\Manager(); |
|
509 | 95 | }); |
|
510 | $this->registerService('MimeTypeDetector', function(Server $c) { |
||
511 | 1 | return new \OC\Files\Type\Detection( |
|
512 | 1 | $c->getURLGenerator(), |
|
513 | 1 | \OC::$SERVERROOT . '/config/', |
|
514 | \OC::$SERVERROOT . '/resources/config/' |
||
515 | 1 | ); |
|
516 | 95 | }); |
|
517 | $this->registerService('MimeTypeLoader', function(Server $c) { |
||
518 | 1 | return new \OC\Files\Type\Loader( |
|
519 | 1 | $c->getDatabaseConnection() |
|
520 | 1 | ); |
|
521 | 95 | }); |
|
522 | $this->registerService('NotificationManager', function() { |
||
523 | 2 | return new Manager(); |
|
524 | 95 | }); |
|
525 | $this->registerService('CapabilitiesManager', function (Server $c) { |
||
526 | 1 | $manager = new \OC\CapabilitiesManager(); |
|
527 | $manager->registerCapability(function() use ($c) { |
||
528 | return new \OC\OCS\CoreCapabilities($c->getConfig()); |
||
529 | 1 | }); |
|
530 | 1 | return $manager; |
|
531 | 95 | }); |
|
532 | $this->registerService('CommentsManager', function(Server $c) { |
||
533 | 3 | $config = $c->getConfig(); |
|
534 | 3 | $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory'); |
|
535 | /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
||
536 | 3 | $factory = new $factoryClass(); |
|
537 | 3 | return $factory->getManager(); |
|
538 | 95 | }); |
|
539 | $this->registerService('EventDispatcher', function() { |
||
540 | return new EventDispatcher(); |
||
541 | 95 | }); |
|
542 | 95 | $this->registerService('CryptoWrapper', function (Server $c) { |
|
543 | // FIXME: Instantiiated here due to cyclic dependency |
||
544 | 1 | $request = new Request( |
|
545 | [ |
||
546 | 1 | 'get' => $_GET, |
|
547 | 1 | 'post' => $_POST, |
|
548 | 1 | 'files' => $_FILES, |
|
549 | 1 | 'server' => $_SERVER, |
|
550 | 1 | 'env' => $_ENV, |
|
551 | 1 | 'cookies' => $_COOKIE, |
|
552 | 1 | 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
553 | 1 | ? $_SERVER['REQUEST_METHOD'] |
|
554 | 1 | : null, |
|
555 | 1 | ], |
|
556 | 1 | new SecureRandom(), |
|
557 | 1 | $c->getConfig() |
|
558 | 1 | ); |
|
559 | |||
560 | 1 | return new CryptoWrapper( |
|
561 | 1 | $c->getConfig(), |
|
562 | 1 | $c->getCrypto(), |
|
563 | 1 | $c->getSecureRandom(), |
|
564 | $request |
||
565 | 1 | ); |
|
566 | 95 | }); |
|
567 | 95 | } |
|
568 | |||
569 | /** |
||
570 | * @return \OCP\Contacts\IManager |
||
571 | */ |
||
572 | 14 | public function getContactsManager() { |
|
575 | |||
576 | /** |
||
577 | * @return \OC\Encryption\Manager |
||
578 | */ |
||
579 | 12 | public function getEncryptionManager() { |
|
582 | |||
583 | /** |
||
584 | * @return \OC\Encryption\File |
||
585 | */ |
||
586 | 11 | public function getEncryptionFilesHelper() { |
|
589 | |||
590 | /** |
||
591 | * @return \OCP\Encryption\Keys\IStorage |
||
592 | */ |
||
593 | 11 | public function getEncryptionKeyStorage() { |
|
596 | |||
597 | /** |
||
598 | * The current request object holding all information about the request |
||
599 | * currently being processed is returned from this method. |
||
600 | * In case the current execution was not initiated by a web request null is returned |
||
601 | * |
||
602 | * @return \OCP\IRequest |
||
603 | */ |
||
604 | 244 | public function getRequest() { |
|
607 | |||
608 | /** |
||
609 | * Returns the preview manager which can create preview images for a given file |
||
610 | * |
||
611 | * @return \OCP\IPreview |
||
612 | */ |
||
613 | 172 | public function getPreviewManager() { |
|
616 | |||
617 | /** |
||
618 | * Returns the tag manager which can get and set tags for different object types |
||
619 | * |
||
620 | * @see \OCP\ITagManager::load() |
||
621 | * @return \OCP\ITagManager |
||
622 | */ |
||
623 | 27 | public function getTagManager() { |
|
626 | |||
627 | /** |
||
628 | * Returns the system-tag manager |
||
629 | * |
||
630 | * @return \OCP\SystemTag\ISystemTagManager |
||
631 | * |
||
632 | * @since 9.0.0 |
||
633 | */ |
||
634 | public function getSystemTagManager() { |
||
637 | |||
638 | /** |
||
639 | * Returns the system-tag object mapper |
||
640 | * |
||
641 | * @return \OCP\SystemTag\ISystemTagObjectMapper |
||
642 | * |
||
643 | * @since 9.0.0 |
||
644 | */ |
||
645 | public function getSystemTagObjectMapper() { |
||
648 | |||
649 | |||
650 | /** |
||
651 | * Returns the avatar manager, used for avatar functionality |
||
652 | * |
||
653 | * @return \OCP\IAvatarManager |
||
654 | */ |
||
655 | public function getAvatarManager() { |
||
658 | |||
659 | /** |
||
660 | * Returns the root folder of ownCloud's data directory |
||
661 | * |
||
662 | * @return \OCP\Files\IRootFolder |
||
663 | */ |
||
664 | 915 | public function getRootFolder() { |
|
667 | |||
668 | /** |
||
669 | * Returns a view to ownCloud's files folder |
||
670 | * |
||
671 | * @param string $userId user ID |
||
672 | * @return \OCP\Files\Folder |
||
673 | */ |
||
674 | 913 | public function getUserFolder($userId = null) { |
|
685 | |||
686 | /** |
||
687 | * Returns an app-specific view in ownClouds data directory |
||
688 | * |
||
689 | * @return \OCP\Files\Folder |
||
690 | */ |
||
691 | public function getAppFolder() { |
||
702 | |||
703 | /** |
||
704 | * @return \OC\User\Manager |
||
705 | */ |
||
706 | 1712 | public function getUserManager() { |
|
709 | |||
710 | /** |
||
711 | * @return \OC\Group\Manager |
||
712 | */ |
||
713 | 1064 | public function getGroupManager() { |
|
716 | |||
717 | /** |
||
718 | * @return \OC\User\Session |
||
719 | */ |
||
720 | 1224 | public function getUserSession() { |
|
723 | |||
724 | /** |
||
725 | * @return \OCP\ISession |
||
726 | */ |
||
727 | 1249 | public function getSession() { |
|
730 | |||
731 | /** |
||
732 | * @param \OCP\ISession $session |
||
733 | */ |
||
734 | public function setSession(\OCP\ISession $session) { |
||
737 | |||
738 | /** |
||
739 | * @return \OC\NavigationManager |
||
740 | */ |
||
741 | 1 | public function getNavigationManager() { |
|
744 | |||
745 | /** |
||
746 | * @return \OCP\IConfig |
||
747 | */ |
||
748 | 1466 | public function getConfig() { |
|
751 | |||
752 | /** |
||
753 | * For internal use only |
||
754 | * |
||
755 | * @return \OC\SystemConfig |
||
756 | */ |
||
757 | 1904 | public function getSystemConfig() { |
|
760 | |||
761 | /** |
||
762 | * Returns the app config manager |
||
763 | * |
||
764 | * @return \OCP\IAppConfig |
||
765 | */ |
||
766 | 1117 | public function getAppConfig() { |
|
769 | |||
770 | /** |
||
771 | * @return \OCP\L10N\IFactory |
||
772 | */ |
||
773 | 966 | public function getL10NFactory() { |
|
776 | |||
777 | /** |
||
778 | * get an L10N instance |
||
779 | * |
||
780 | * @param string $app appid |
||
781 | * @param string $lang |
||
782 | * @return \OC_L10N |
||
783 | */ |
||
784 | 965 | public function getL10N($app, $lang = null) { |
|
787 | |||
788 | /** |
||
789 | * @return \OCP\IURLGenerator |
||
790 | */ |
||
791 | 1040 | public function getURLGenerator() { |
|
794 | |||
795 | /** |
||
796 | * @return \OCP\IHelper |
||
797 | */ |
||
798 | public function getHelper() { |
||
801 | |||
802 | /** |
||
803 | * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
||
804 | * getMemCacheFactory() instead. |
||
805 | * |
||
806 | * @return \OCP\ICache |
||
807 | * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
||
808 | */ |
||
809 | public function getCache() { |
||
812 | |||
813 | /** |
||
814 | * Returns an \OCP\CacheFactory instance |
||
815 | * |
||
816 | * @return \OCP\ICacheFactory |
||
817 | */ |
||
818 | 113 | public function getMemCacheFactory() { |
|
821 | |||
822 | /** |
||
823 | * Returns the current session |
||
824 | * |
||
825 | * @return \OCP\IDBConnection |
||
826 | */ |
||
827 | 1949 | public function getDatabaseConnection() { |
|
830 | |||
831 | /** |
||
832 | * Returns the activity manager |
||
833 | * |
||
834 | * @return \OCP\Activity\IManager |
||
835 | */ |
||
836 | 9 | public function getActivityManager() { |
|
839 | |||
840 | /** |
||
841 | * Returns an job list for controlling background jobs |
||
842 | * |
||
843 | * @return \OCP\BackgroundJob\IJobList |
||
844 | */ |
||
845 | 4 | public function getJobList() { |
|
848 | |||
849 | /** |
||
850 | * Returns a logger instance |
||
851 | * |
||
852 | * @return \OCP\ILogger |
||
853 | */ |
||
854 | 1011 | public function getLogger() { |
|
857 | |||
858 | /** |
||
859 | * Returns a router for generating and matching urls |
||
860 | * |
||
861 | * @return \OCP\Route\IRouter |
||
862 | */ |
||
863 | 10 | public function getRouter() { |
|
866 | |||
867 | /** |
||
868 | * Returns a search instance |
||
869 | * |
||
870 | * @return \OCP\ISearch |
||
871 | */ |
||
872 | public function getSearch() { |
||
875 | |||
876 | /** |
||
877 | * Returns a SecureRandom instance |
||
878 | * |
||
879 | * @return \OCP\Security\ISecureRandom |
||
880 | */ |
||
881 | 519 | public function getSecureRandom() { |
|
884 | |||
885 | /** |
||
886 | * Returns a Crypto instance |
||
887 | * |
||
888 | * @return \OCP\Security\ICrypto |
||
889 | */ |
||
890 | 1 | public function getCrypto() { |
|
893 | |||
894 | /** |
||
895 | * Returns a Hasher instance |
||
896 | * |
||
897 | * @return \OCP\Security\IHasher |
||
898 | */ |
||
899 | 51 | public function getHasher() { |
|
902 | |||
903 | /** |
||
904 | * Returns an instance of the db facade |
||
905 | * @deprecated use getDatabaseConnection, will be removed in ownCloud 10 |
||
906 | * @return \OCP\IDb |
||
907 | */ |
||
908 | public function getDb() { |
||
911 | |||
912 | /** |
||
913 | * Returns an instance of the HTTP helper class |
||
914 | * @deprecated Use getHTTPClientService() |
||
915 | * @return \OC\HTTPHelper |
||
916 | */ |
||
917 | 22 | public function getHTTPHelper() { |
|
920 | |||
921 | /** |
||
922 | * Get the certificate manager for the user |
||
923 | * |
||
924 | * @param string $userId (optional) if not specified the current loggedin user is used |
||
925 | * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
||
926 | */ |
||
927 | 8 | public function getCertificateManager($userId = null) { |
|
938 | |||
939 | /** |
||
940 | * Returns an instance of the HTTP client service |
||
941 | * |
||
942 | * @return \OCP\Http\Client\IClientService |
||
943 | */ |
||
944 | 10 | public function getHTTPClientService() { |
|
947 | |||
948 | /** |
||
949 | * Create a new event source |
||
950 | * |
||
951 | * @return \OCP\IEventSource |
||
952 | */ |
||
953 | 1 | public function createEventSource() { |
|
956 | |||
957 | /** |
||
958 | * Get the active event logger |
||
959 | * |
||
960 | * The returned logger only logs data when debug mode is enabled |
||
961 | * |
||
962 | * @return \OCP\Diagnostics\IEventLogger |
||
963 | */ |
||
964 | 1078 | public function getEventLogger() { |
|
967 | |||
968 | /** |
||
969 | * Get the active query logger |
||
970 | * |
||
971 | * The returned logger only logs data when debug mode is enabled |
||
972 | * |
||
973 | * @return \OCP\Diagnostics\IQueryLogger |
||
974 | */ |
||
975 | 12 | public function getQueryLogger() { |
|
978 | |||
979 | /** |
||
980 | * Get the manager for temporary files and folders |
||
981 | * |
||
982 | * @return \OCP\ITempManager |
||
983 | */ |
||
984 | 1481 | public function getTempManager() { |
|
987 | |||
988 | /** |
||
989 | * Get the app manager |
||
990 | * |
||
991 | * @return \OCP\App\IAppManager |
||
992 | */ |
||
993 | 1146 | public function getAppManager() { |
|
996 | |||
997 | /** |
||
998 | * Creates a new mailer |
||
999 | * |
||
1000 | * @return \OCP\Mail\IMailer |
||
1001 | */ |
||
1002 | 13 | public function getMailer() { |
|
1005 | |||
1006 | /** |
||
1007 | * Get the webroot |
||
1008 | * |
||
1009 | * @return string |
||
1010 | */ |
||
1011 | public function getWebRoot() { |
||
1014 | |||
1015 | /** |
||
1016 | * @return \OC\OCSClient |
||
1017 | */ |
||
1018 | 1 | public function getOcsClient() { |
|
1019 | 1 | return $this->query('OcsClient'); |
|
1020 | } |
||
1021 | |||
1022 | /** |
||
1023 | * @return \OCP\IDateTimeZone |
||
1024 | */ |
||
1025 | 9 | public function getDateTimeZone() { |
|
1028 | |||
1029 | /** |
||
1030 | * @return \OCP\IDateTimeFormatter |
||
1031 | */ |
||
1032 | public function getDateTimeFormatter() { |
||
1035 | |||
1036 | /** |
||
1037 | * @return \OCP\Files\Config\IMountProviderCollection |
||
1038 | */ |
||
1039 | 968 | public function getMountProviderCollection(){ |
|
1042 | |||
1043 | /** |
||
1044 | * Get the IniWrapper |
||
1045 | * |
||
1046 | * @return IniGetWrapper |
||
1047 | */ |
||
1048 | 25 | public function getIniWrapper() { |
|
1051 | |||
1052 | /** |
||
1053 | * @return \OCP\Command\IBus |
||
1054 | */ |
||
1055 | 65 | public function getCommandBus(){ |
|
1058 | |||
1059 | /** |
||
1060 | * Get the trusted domain helper |
||
1061 | * |
||
1062 | * @return TrustedDomainHelper |
||
1063 | */ |
||
1064 | public function getTrustedDomainHelper() { |
||
1067 | |||
1068 | /** |
||
1069 | * Get the locking provider |
||
1070 | * |
||
1071 | * @return \OCP\Lock\ILockingProvider |
||
1072 | * @since 8.1.0 |
||
1073 | */ |
||
1074 | 6122 | public function getLockingProvider() { |
|
1077 | |||
1078 | /** |
||
1079 | * @return \OCP\Files\Mount\IMountManager |
||
1080 | **/ |
||
1081 | 22 | function getMountManager() { |
|
1084 | |||
1085 | /* |
||
1086 | * Get the MimeTypeDetector |
||
1087 | * |
||
1088 | * @return \OCP\Files\IMimeTypeDetector |
||
1089 | */ |
||
1090 | 862 | public function getMimeTypeDetector() { |
|
1093 | |||
1094 | /** |
||
1095 | * Get the MimeTypeLoader |
||
1096 | * |
||
1097 | * @return \OCP\Files\IMimeTypeLoader |
||
1098 | */ |
||
1099 | 1092 | public function getMimeTypeLoader() { |
|
1102 | |||
1103 | /** |
||
1104 | * Get the manager of all the capabilities |
||
1105 | * |
||
1106 | * @return \OC\CapabilitiesManager |
||
1107 | */ |
||
1108 | 63 | public function getCapabilitiesManager() { |
|
1111 | |||
1112 | /** |
||
1113 | * Get the EventDispatcher |
||
1114 | * |
||
1115 | * @return EventDispatcherInterface |
||
1116 | * @since 8.2.0 |
||
1117 | */ |
||
1118 | 45 | public function getEventDispatcher() { |
|
1121 | |||
1122 | /** |
||
1123 | * Get the Notification Manager |
||
1124 | * |
||
1125 | * @return \OC\Notification\IManager |
||
1126 | * @since 8.2.0 |
||
1127 | */ |
||
1128 | 6 | public function getNotificationManager() { |
|
1131 | |||
1132 | /** |
||
1133 | * @return \OCP\Comments\ICommentsManager |
||
1134 | */ |
||
1135 | 519 | public function getCommentsManager() { |
|
1136 | 519 | return $this->query('CommentsManager'); |
|
1137 | } |
||
1138 | |||
1139 | /** |
||
1140 | * @return \OC\IntegrityCheck\Checker |
||
1141 | */ |
||
1142 | public function getIntegrityCodeChecker() { |
||
1145 | |||
1146 | /** |
||
1147 | * @return \OC\Session\CryptoWrapper |
||
1148 | */ |
||
1149 | public function getSessionCryptoWrapper() { |
||
1152 | |||
1153 | /** |
||
1154 | * Not a public API as of 8.2, wait for 9.0 |
||
1155 | * @return \OCA\Files_External\Service\BackendService |
||
1156 | */ |
||
1157 | public function getStoragesBackendService() { |
||
1160 | |||
1161 | /** |
||
1162 | * Not a public API as of 8.2, wait for 9.0 |
||
1163 | * @return \OCA\Files_External\Service\GlobalStoragesService |
||
1164 | */ |
||
1165 | public function getGlobalStoragesService() { |
||
1168 | |||
1169 | /** |
||
1170 | * Not a public API as of 8.2, wait for 9.0 |
||
1171 | * @return \OCA\Files_External\Service\UserGlobalStoragesService |
||
1172 | */ |
||
1173 | public function getUserGlobalStoragesService() { |
||
1176 | |||
1177 | /** |
||
1178 | * Not a public API as of 8.2, wait for 9.0 |
||
1179 | * @return \OCA\Files_External\Service\UserStoragesService |
||
1180 | */ |
||
1181 | public function getUserStoragesService() { |
||
1184 | |||
1185 | } |
||
1186 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.