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