| Conditions | 23 |
| Paths | 1 |
| Total Lines | 573 |
| Code Lines | 403 |
| Lines | 38 |
| Ratio | 6.63 % |
| Changes | 6 | ||
| Bugs | 2 | Features | 2 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 100 | public function __construct($webRoot, \OC\Config $config) { |
||
| 101 | parent::__construct(); |
||
| 102 | $this->webRoot = $webRoot; |
||
| 103 | |||
| 104 | $this->registerService('ContactsManager', function ($c) { |
||
|
|
|||
| 105 | return new ContactsManager(); |
||
| 106 | }); |
||
| 107 | |||
| 108 | $this->registerService('PreviewManager', function (Server $c) { |
||
| 109 | return new PreviewManager($c->getConfig()); |
||
| 110 | }); |
||
| 111 | |||
| 112 | $this->registerService('EncryptionManager', function (Server $c) { |
||
| 113 | $view = new View(); |
||
| 114 | $util = new Encryption\Util( |
||
| 115 | $view, |
||
| 116 | $c->getUserManager(), |
||
| 117 | $c->getGroupManager(), |
||
| 118 | $c->getConfig() |
||
| 119 | ); |
||
| 120 | return new Encryption\Manager( |
||
| 121 | $c->getConfig(), |
||
| 122 | $c->getLogger(), |
||
| 123 | $c->getL10N('core'), |
||
| 124 | new View(), |
||
| 125 | $util, |
||
| 126 | new ArrayCache() |
||
| 127 | ); |
||
| 128 | }); |
||
| 129 | |||
| 130 | $this->registerService('EncryptionFileHelper', function (Server $c) { |
||
| 131 | $util = new Encryption\Util( |
||
| 132 | new View(), |
||
| 133 | $c->getUserManager(), |
||
| 134 | $c->getGroupManager(), |
||
| 135 | $c->getConfig() |
||
| 136 | ); |
||
| 137 | return new Encryption\File($util); |
||
| 138 | }); |
||
| 139 | |||
| 140 | $this->registerService('EncryptionKeyStorage', function (Server $c) { |
||
| 141 | $view = new View(); |
||
| 142 | $util = new Encryption\Util( |
||
| 143 | $view, |
||
| 144 | $c->getUserManager(), |
||
| 145 | $c->getGroupManager(), |
||
| 146 | $c->getConfig() |
||
| 147 | ); |
||
| 148 | |||
| 149 | return new Encryption\Keys\Storage($view, $util); |
||
| 150 | }); |
||
| 151 | $this->registerService('TagMapper', function (Server $c) { |
||
| 152 | return new TagMapper($c->getDatabaseConnection()); |
||
| 153 | }); |
||
| 154 | $this->registerService('TagManager', function (Server $c) { |
||
| 155 | $tagMapper = $c->query('TagMapper'); |
||
| 156 | return new TagManager($tagMapper, $c->getUserSession()); |
||
| 157 | }); |
||
| 158 | View Code Duplication | $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
| 159 | $config = $c->getConfig(); |
||
| 160 | $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory'); |
||
| 161 | /** @var \OC\SystemTag\ManagerFactory $factory */ |
||
| 162 | $factory = new $factoryClass($this); |
||
| 163 | return $factory; |
||
| 164 | }); |
||
| 165 | $this->registerService('SystemTagManager', function (Server $c) { |
||
| 166 | return $c->query('SystemTagManagerFactory')->getManager(); |
||
| 167 | }); |
||
| 168 | $this->registerService('SystemTagObjectMapper', function (Server $c) { |
||
| 169 | return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
||
| 170 | }); |
||
| 171 | $this->registerService('RootFolder', function () { |
||
| 172 | $manager = \OC\Files\Filesystem::getMountManager(null); |
||
| 173 | $view = new View(); |
||
| 174 | $root = new Root($manager, $view, null); |
||
| 175 | $connector = new HookConnector($root, $view); |
||
| 176 | $connector->viewToNode(); |
||
| 177 | return $root; |
||
| 178 | }); |
||
| 179 | $this->registerService('LazyRootFolder', function(Server $c) { |
||
| 180 | return new LazyRoot(function() use ($c) { |
||
| 181 | return $c->getRootFolder(); |
||
| 182 | }); |
||
| 183 | }); |
||
| 184 | $this->registerService('UserManager', function (Server $c) { |
||
| 185 | $config = $c->getConfig(); |
||
| 186 | return new \OC\User\Manager($config); |
||
| 187 | }); |
||
| 188 | $this->registerService('GroupManager', function (Server $c) { |
||
| 189 | $groupManager = new \OC\Group\Manager($this->getUserManager()); |
||
| 190 | $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
||
| 191 | \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
||
| 192 | }); |
||
| 193 | $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
||
| 194 | \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
||
| 195 | }); |
||
| 196 | $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
||
| 197 | \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
||
| 198 | }); |
||
| 199 | $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
||
| 200 | \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
||
| 201 | }); |
||
| 202 | $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
||
| 203 | \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
||
| 204 | }); |
||
| 205 | $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
||
| 206 | \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
||
| 207 | //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
||
| 208 | \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
||
| 209 | }); |
||
| 210 | return $groupManager; |
||
| 211 | }); |
||
| 212 | $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) { |
||
| 213 | $dbConnection = $c->getDatabaseConnection(); |
||
| 214 | return new Authentication\Token\DefaultTokenMapper($dbConnection); |
||
| 215 | }); |
||
| 216 | $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) { |
||
| 217 | $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper'); |
||
| 218 | $crypto = $c->getCrypto(); |
||
| 219 | $config = $c->getConfig(); |
||
| 220 | $logger = $c->getLogger(); |
||
| 221 | $timeFactory = new TimeFactory(); |
||
| 222 | return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
||
| 223 | }); |
||
| 224 | $this->registerService('UserSession', function (Server $c) { |
||
| 225 | $manager = $c->getUserManager(); |
||
| 226 | $session = new \OC\Session\Memory(''); |
||
| 227 | $timeFactory = new TimeFactory(); |
||
| 228 | // Token providers might require a working database. This code |
||
| 229 | // might however be called when ownCloud is not yet setup. |
||
| 230 | View Code Duplication | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 231 | $defaultTokenProvider = $c->query('OC\Authentication\Token\DefaultTokenProvider'); |
||
| 232 | $tokenProviders = [ |
||
| 233 | $defaultTokenProvider, |
||
| 234 | ]; |
||
| 235 | } else { |
||
| 236 | $defaultTokenProvider = null; |
||
| 237 | $tokenProviders = []; |
||
| 238 | } |
||
| 239 | |||
| 240 | $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $tokenProviders); |
||
| 241 | $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
||
| 242 | \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
||
| 243 | }); |
||
| 244 | $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
||
| 245 | /** @var $user \OC\User\User */ |
||
| 246 | \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
||
| 247 | }); |
||
| 248 | $userSession->listen('\OC\User', 'preDelete', function ($user) { |
||
| 249 | /** @var $user \OC\User\User */ |
||
| 250 | \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
||
| 251 | }); |
||
| 252 | $userSession->listen('\OC\User', 'postDelete', function ($user) { |
||
| 253 | /** @var $user \OC\User\User */ |
||
| 254 | \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
||
| 255 | }); |
||
| 256 | View Code Duplication | $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 257 | /** @var $user \OC\User\User */ |
||
| 258 | \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
||
| 259 | }); |
||
| 260 | View Code Duplication | $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 261 | /** @var $user \OC\User\User */ |
||
| 262 | \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
||
| 263 | }); |
||
| 264 | $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
||
| 265 | \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
||
| 266 | }); |
||
| 267 | $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
||
| 268 | /** @var $user \OC\User\User */ |
||
| 269 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
||
| 270 | }); |
||
| 271 | $userSession->listen('\OC\User', 'logout', function () { |
||
| 272 | \OC_Hook::emit('OC_User', 'logout', array()); |
||
| 273 | }); |
||
| 274 | $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value) { |
||
| 275 | /** @var $user \OC\User\User */ |
||
| 276 | \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value)); |
||
| 277 | }); |
||
| 278 | return $userSession; |
||
| 279 | }); |
||
| 280 | $this->registerService('NavigationManager', function ($c) { |
||
| 281 | return new \OC\NavigationManager(); |
||
| 282 | }); |
||
| 283 | $this->registerService('AllConfig', function (Server $c) { |
||
| 284 | return new \OC\AllConfig( |
||
| 285 | $c->getSystemConfig() |
||
| 286 | ); |
||
| 287 | }); |
||
| 288 | $this->registerService('SystemConfig', function ($c) use ($config) { |
||
| 289 | return new \OC\SystemConfig($config); |
||
| 290 | }); |
||
| 291 | $this->registerService('AppConfig', function (Server $c) { |
||
| 292 | return new \OC\AppConfig($c->getDatabaseConnection()); |
||
| 293 | }); |
||
| 294 | $this->registerService('L10NFactory', function (Server $c) { |
||
| 295 | return new \OC\L10N\Factory( |
||
| 296 | $c->getConfig(), |
||
| 297 | $c->getRequest(), |
||
| 298 | $c->getUserSession(), |
||
| 299 | \OC::$SERVERROOT |
||
| 300 | ); |
||
| 301 | }); |
||
| 302 | $this->registerService('URLGenerator', function (Server $c) { |
||
| 303 | $config = $c->getConfig(); |
||
| 304 | $cacheFactory = $c->getMemCacheFactory(); |
||
| 305 | return new \OC\URLGenerator( |
||
| 306 | $config, |
||
| 307 | $cacheFactory |
||
| 308 | ); |
||
| 309 | }); |
||
| 310 | $this->registerService('AppHelper', function ($c) { |
||
| 311 | return new \OC\AppHelper(); |
||
| 312 | }); |
||
| 313 | $this->registerService('UserCache', function ($c) { |
||
| 314 | return new Cache\File(); |
||
| 315 | }); |
||
| 316 | $this->registerService('MemCacheFactory', function (Server $c) { |
||
| 317 | $config = $c->getConfig(); |
||
| 318 | |||
| 319 | if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
||
| 320 | $v = \OC_App::getAppVersions(); |
||
| 321 | $v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php')); |
||
| 322 | $version = implode(',', $v); |
||
| 323 | $instanceId = \OC_Util::getInstanceId(); |
||
| 324 | $path = \OC::$SERVERROOT; |
||
| 325 | $prefix = md5($instanceId . '-' . $version . '-' . $path); |
||
| 326 | return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
||
| 327 | $config->getSystemValue('memcache.local', null), |
||
| 328 | $config->getSystemValue('memcache.distributed', null), |
||
| 329 | $config->getSystemValue('memcache.locking', null) |
||
| 330 | ); |
||
| 331 | } |
||
| 332 | |||
| 333 | return new \OC\Memcache\Factory('', $c->getLogger(), |
||
| 334 | '\\OC\\Memcache\\ArrayCache', |
||
| 335 | '\\OC\\Memcache\\ArrayCache', |
||
| 336 | '\\OC\\Memcache\\ArrayCache' |
||
| 337 | ); |
||
| 338 | }); |
||
| 339 | $this->registerService('RedisFactory', function (Server $c) { |
||
| 340 | $systemConfig = $c->getSystemConfig(); |
||
| 341 | return new RedisFactory($systemConfig); |
||
| 342 | }); |
||
| 343 | $this->registerService('ActivityManager', function (Server $c) { |
||
| 344 | return new \OC\Activity\Manager( |
||
| 345 | $c->getRequest(), |
||
| 346 | $c->getUserSession(), |
||
| 347 | $c->getConfig() |
||
| 348 | ); |
||
| 349 | }); |
||
| 350 | $this->registerService('AvatarManager', function (Server $c) { |
||
| 351 | return new AvatarManager( |
||
| 352 | $c->getUserManager(), |
||
| 353 | $c->getRootFolder(), |
||
| 354 | $c->getL10N('lib'), |
||
| 355 | $c->getLogger() |
||
| 356 | ); |
||
| 357 | }); |
||
| 358 | $this->registerService('Logger', function (Server $c) { |
||
| 359 | $logClass = $c->query('AllConfig')->getSystemValue('log_type', 'owncloud'); |
||
| 360 | $logger = 'OC\\Log\\' . ucfirst($logClass); |
||
| 361 | call_user_func(array($logger, 'init')); |
||
| 362 | |||
| 363 | return new Log($logger); |
||
| 364 | }); |
||
| 365 | $this->registerService('JobList', function (Server $c) { |
||
| 366 | $config = $c->getConfig(); |
||
| 367 | return new \OC\BackgroundJob\JobList($c->getDatabaseConnection(), $config); |
||
| 368 | }); |
||
| 369 | $this->registerService('Router', function (Server $c) { |
||
| 370 | $cacheFactory = $c->getMemCacheFactory(); |
||
| 371 | $logger = $c->getLogger(); |
||
| 372 | if ($cacheFactory->isAvailable()) { |
||
| 373 | $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger); |
||
| 374 | } else { |
||
| 375 | $router = new \OC\Route\Router($logger); |
||
| 376 | } |
||
| 377 | return $router; |
||
| 378 | }); |
||
| 379 | $this->registerService('Search', function ($c) { |
||
| 380 | return new Search(); |
||
| 381 | }); |
||
| 382 | $this->registerService('SecureRandom', function ($c) { |
||
| 383 | return new SecureRandom(); |
||
| 384 | }); |
||
| 385 | $this->registerService('Crypto', function (Server $c) { |
||
| 386 | return new Crypto($c->getConfig(), $c->getSecureRandom()); |
||
| 387 | }); |
||
| 388 | $this->registerService('Hasher', function (Server $c) { |
||
| 389 | return new Hasher($c->getConfig()); |
||
| 390 | }); |
||
| 391 | $this->registerService('CredentialsManager', function (Server $c) { |
||
| 392 | return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
||
| 393 | }); |
||
| 394 | $this->registerService('DatabaseConnection', function (Server $c) { |
||
| 395 | $factory = new \OC\DB\ConnectionFactory(); |
||
| 396 | $systemConfig = $c->getSystemConfig(); |
||
| 397 | $type = $systemConfig->getValue('dbtype', 'sqlite'); |
||
| 398 | if (!$factory->isValidType($type)) { |
||
| 399 | throw new \OC\DatabaseException('Invalid database type'); |
||
| 400 | } |
||
| 401 | $connectionParams = $factory->createConnectionParams($systemConfig); |
||
| 402 | $connection = $factory->getConnection($type, $connectionParams); |
||
| 403 | $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
||
| 404 | return $connection; |
||
| 405 | }); |
||
| 406 | $this->registerService('Db', function (Server $c) { |
||
| 407 | return new Db($c->getDatabaseConnection()); |
||
| 408 | }); |
||
| 409 | $this->registerService('HTTPHelper', function (Server $c) { |
||
| 410 | $config = $c->getConfig(); |
||
| 411 | return new HTTPHelper( |
||
| 412 | $config, |
||
| 413 | $c->getHTTPClientService() |
||
| 414 | ); |
||
| 415 | }); |
||
| 416 | $this->registerService('HttpClientService', function (Server $c) { |
||
| 417 | $user = \OC_User::getUser(); |
||
| 418 | $uid = $user ? $user : null; |
||
| 419 | return new ClientService( |
||
| 420 | $c->getConfig(), |
||
| 421 | new \OC\Security\CertificateManager($uid, new View(), $c->getConfig()) |
||
| 422 | ); |
||
| 423 | }); |
||
| 424 | $this->registerService('EventLogger', function (Server $c) { |
||
| 425 | if ($c->getSystemConfig()->getValue('debug', false)) { |
||
| 426 | return new EventLogger(); |
||
| 427 | } else { |
||
| 428 | return new NullEventLogger(); |
||
| 429 | } |
||
| 430 | }); |
||
| 431 | $this->registerService('QueryLogger', function (Server $c) { |
||
| 432 | if ($c->getSystemConfig()->getValue('debug', false)) { |
||
| 433 | return new QueryLogger(); |
||
| 434 | } else { |
||
| 435 | return new NullQueryLogger(); |
||
| 436 | } |
||
| 437 | }); |
||
| 438 | $this->registerService('TempManager', function (Server $c) { |
||
| 439 | return new TempManager( |
||
| 440 | $c->getLogger(), |
||
| 441 | $c->getConfig() |
||
| 442 | ); |
||
| 443 | }); |
||
| 444 | $this->registerService('AppManager', function (Server $c) { |
||
| 445 | return new \OC\App\AppManager( |
||
| 446 | $c->getUserSession(), |
||
| 447 | $c->getAppConfig(), |
||
| 448 | $c->getGroupManager(), |
||
| 449 | $c->getMemCacheFactory(), |
||
| 450 | $c->getEventDispatcher() |
||
| 451 | ); |
||
| 452 | }); |
||
| 453 | $this->registerService('DateTimeZone', function (Server $c) { |
||
| 454 | return new DateTimeZone( |
||
| 455 | $c->getConfig(), |
||
| 456 | $c->getSession() |
||
| 457 | ); |
||
| 458 | }); |
||
| 459 | $this->registerService('DateTimeFormatter', function (Server $c) { |
||
| 460 | $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
||
| 461 | |||
| 462 | return new DateTimeFormatter( |
||
| 463 | $c->getDateTimeZone()->getTimeZone(), |
||
| 464 | $c->getL10N('lib', $language) |
||
| 465 | ); |
||
| 466 | }); |
||
| 467 | $this->registerService('UserMountCache', function (Server $c) { |
||
| 468 | $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
||
| 469 | $listener = new UserMountCacheListener($mountCache); |
||
| 470 | $listener->listen($c->getUserManager()); |
||
| 471 | return $mountCache; |
||
| 472 | }); |
||
| 473 | $this->registerService('MountConfigManager', function (Server $c) { |
||
| 474 | $loader = \OC\Files\Filesystem::getLoader(); |
||
| 475 | $mountCache = $c->query('UserMountCache'); |
||
| 476 | $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
||
| 477 | |||
| 478 | // builtin providers |
||
| 479 | |||
| 480 | $config = $c->getConfig(); |
||
| 481 | $manager->registerProvider(new CacheMountProvider($config)); |
||
| 482 | |||
| 483 | return $manager; |
||
| 484 | }); |
||
| 485 | $this->registerService('IniWrapper', function ($c) { |
||
| 486 | return new IniGetWrapper(); |
||
| 487 | }); |
||
| 488 | $this->registerService('AsyncCommandBus', function (Server $c) { |
||
| 489 | $jobList = $c->getJobList(); |
||
| 490 | return new AsyncBus($jobList); |
||
| 491 | }); |
||
| 492 | $this->registerService('TrustedDomainHelper', function ($c) { |
||
| 493 | return new TrustedDomainHelper($this->getConfig()); |
||
| 494 | }); |
||
| 495 | $this->registerService('IntegrityCodeChecker', function (Server $c) { |
||
| 496 | // IConfig and IAppManager requires a working database. This code |
||
| 497 | // might however be called when ownCloud is not yet setup. |
||
| 498 | View Code Duplication | if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 499 | $config = $c->getConfig(); |
||
| 500 | $appManager = $c->getAppManager(); |
||
| 501 | } else { |
||
| 502 | $config = null; |
||
| 503 | $appManager = null; |
||
| 504 | } |
||
| 505 | |||
| 506 | return new Checker( |
||
| 507 | new EnvironmentHelper(), |
||
| 508 | new FileAccessHelper(), |
||
| 509 | new AppLocator(), |
||
| 510 | $config, |
||
| 511 | $c->getMemCacheFactory(), |
||
| 512 | $appManager, |
||
| 513 | $c->getTempManager() |
||
| 514 | ); |
||
| 515 | }); |
||
| 516 | $this->registerService('Request', function ($c) { |
||
| 517 | if (isset($this['urlParams'])) { |
||
| 518 | $urlParams = $this['urlParams']; |
||
| 519 | } else { |
||
| 520 | $urlParams = []; |
||
| 521 | } |
||
| 522 | |||
| 523 | if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
||
| 524 | && in_array('fakeinput', stream_get_wrappers()) |
||
| 525 | ) { |
||
| 526 | $stream = 'fakeinput://data'; |
||
| 527 | } else { |
||
| 528 | $stream = 'php://input'; |
||
| 529 | } |
||
| 530 | |||
| 531 | return new Request( |
||
| 532 | [ |
||
| 533 | 'get' => $_GET, |
||
| 534 | 'post' => $_POST, |
||
| 535 | 'files' => $_FILES, |
||
| 536 | 'server' => $_SERVER, |
||
| 537 | 'env' => $_ENV, |
||
| 538 | 'cookies' => $_COOKIE, |
||
| 539 | 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
||
| 540 | ? $_SERVER['REQUEST_METHOD'] |
||
| 541 | : null, |
||
| 542 | 'urlParams' => $urlParams, |
||
| 543 | ], |
||
| 544 | $this->getSecureRandom(), |
||
| 545 | $this->getConfig(), |
||
| 546 | $this->getCsrfTokenManager(), |
||
| 547 | $stream |
||
| 548 | ); |
||
| 549 | }); |
||
| 550 | $this->registerService('Mailer', function (Server $c) { |
||
| 551 | return new Mailer( |
||
| 552 | $c->getConfig(), |
||
| 553 | $c->getLogger(), |
||
| 554 | new \OC_Defaults() |
||
| 555 | ); |
||
| 556 | }); |
||
| 557 | $this->registerService('OcsClient', function (Server $c) { |
||
| 558 | return new OCSClient( |
||
| 559 | $this->getHTTPClientService(), |
||
| 560 | $this->getConfig(), |
||
| 561 | $this->getLogger() |
||
| 562 | ); |
||
| 563 | }); |
||
| 564 | $this->registerService('LockingProvider', function (Server $c) { |
||
| 565 | $ini = $c->getIniWrapper(); |
||
| 566 | $config = $c->getConfig(); |
||
| 567 | $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
||
| 568 | if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
||
| 569 | /** @var \OC\Memcache\Factory $memcacheFactory */ |
||
| 570 | $memcacheFactory = $c->getMemCacheFactory(); |
||
| 571 | $memcache = $memcacheFactory->createLocking('lock'); |
||
| 572 | if (!($memcache instanceof \OC\Memcache\NullCache)) { |
||
| 573 | return new MemcacheLockingProvider($memcache, $ttl); |
||
| 574 | } |
||
| 575 | return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl); |
||
| 576 | } |
||
| 577 | return new NoopLockingProvider(); |
||
| 578 | }); |
||
| 579 | $this->registerService('MountManager', function () { |
||
| 580 | return new \OC\Files\Mount\Manager(); |
||
| 581 | }); |
||
| 582 | $this->registerService('MimeTypeDetector', function (Server $c) { |
||
| 583 | return new \OC\Files\Type\Detection( |
||
| 584 | $c->getURLGenerator(), |
||
| 585 | \OC::$SERVERROOT . '/config/', |
||
| 586 | \OC::$SERVERROOT . '/resources/config/' |
||
| 587 | ); |
||
| 588 | }); |
||
| 589 | $this->registerService('MimeTypeLoader', function (Server $c) { |
||
| 590 | return new \OC\Files\Type\Loader( |
||
| 591 | $c->getDatabaseConnection() |
||
| 592 | ); |
||
| 593 | }); |
||
| 594 | $this->registerService('NotificationManager', function () { |
||
| 595 | return new Manager(); |
||
| 596 | }); |
||
| 597 | $this->registerService('CapabilitiesManager', function (Server $c) { |
||
| 598 | $manager = new \OC\CapabilitiesManager(); |
||
| 599 | $manager->registerCapability(function () use ($c) { |
||
| 600 | return new \OC\OCS\CoreCapabilities($c->getConfig()); |
||
| 601 | }); |
||
| 602 | return $manager; |
||
| 603 | }); |
||
| 604 | View Code Duplication | $this->registerService('CommentsManager', function(Server $c) { |
|
| 605 | $config = $c->getConfig(); |
||
| 606 | $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory'); |
||
| 607 | /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
||
| 608 | $factory = new $factoryClass($this); |
||
| 609 | return $factory->getManager(); |
||
| 610 | }); |
||
| 611 | $this->registerService('EventDispatcher', function () { |
||
| 612 | return new EventDispatcher(); |
||
| 613 | }); |
||
| 614 | $this->registerService('CryptoWrapper', function (Server $c) { |
||
| 615 | // FIXME: Instantiiated here due to cyclic dependency |
||
| 616 | $request = new Request( |
||
| 617 | [ |
||
| 618 | 'get' => $_GET, |
||
| 619 | 'post' => $_POST, |
||
| 620 | 'files' => $_FILES, |
||
| 621 | 'server' => $_SERVER, |
||
| 622 | 'env' => $_ENV, |
||
| 623 | 'cookies' => $_COOKIE, |
||
| 624 | 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
||
| 625 | ? $_SERVER['REQUEST_METHOD'] |
||
| 626 | : null, |
||
| 627 | ], |
||
| 628 | $c->getSecureRandom(), |
||
| 629 | $c->getConfig() |
||
| 630 | ); |
||
| 631 | |||
| 632 | return new CryptoWrapper( |
||
| 633 | $c->getConfig(), |
||
| 634 | $c->getCrypto(), |
||
| 635 | $c->getSecureRandom(), |
||
| 636 | $request |
||
| 637 | ); |
||
| 638 | }); |
||
| 639 | $this->registerService('CsrfTokenManager', function (Server $c) { |
||
| 640 | $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
||
| 641 | $sessionStorage = new SessionStorage($c->getSession()); |
||
| 642 | |||
| 643 | return new CsrfTokenManager( |
||
| 644 | $tokenGenerator, |
||
| 645 | $sessionStorage |
||
| 646 | ); |
||
| 647 | }); |
||
| 648 | $this->registerService('ContentSecurityPolicyManager', function (Server $c) { |
||
| 649 | return new ContentSecurityPolicyManager(); |
||
| 650 | }); |
||
| 651 | $this->registerService('ShareManager', function(Server $c) { |
||
| 652 | $config = $c->getConfig(); |
||
| 653 | $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory'); |
||
| 654 | /** @var \OCP\Share\IProviderFactory $factory */ |
||
| 655 | $factory = new $factoryClass($this); |
||
| 656 | |||
| 657 | $manager = new \OC\Share20\Manager( |
||
| 658 | $c->getLogger(), |
||
| 659 | $c->getConfig(), |
||
| 660 | $c->getSecureRandom(), |
||
| 661 | $c->getHasher(), |
||
| 662 | $c->getMountManager(), |
||
| 663 | $c->getGroupManager(), |
||
| 664 | $c->getL10N('core'), |
||
| 665 | $factory, |
||
| 666 | $c->getUserManager(), |
||
| 667 | $c->getLazyRootFolder() |
||
| 668 | ); |
||
| 669 | |||
| 670 | return $manager; |
||
| 671 | }); |
||
| 672 | } |
||
| 673 | |||
| 1346 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.