@@ -23,37 +23,37 @@ |
||
| 23 | 23 | * created by the service container |
| 24 | 24 | */ |
| 25 | 25 | final class ServiceEventListener { |
| 26 | - private ?IEventListener $service = null; |
|
| 27 | - |
|
| 28 | - public function __construct( |
|
| 29 | - private ContainerInterface $container, |
|
| 30 | - private string $class, |
|
| 31 | - private LoggerInterface $logger, |
|
| 32 | - ) { |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - public function __invoke(Event $event) { |
|
| 36 | - if ($this->service === null) { |
|
| 37 | - try { |
|
| 38 | - // TODO: fetch from the app containers, otherwise any custom services, |
|
| 39 | - // parameters and aliases won't be resolved. |
|
| 40 | - // See https://github.com/nextcloud/server/issues/27793 for details. |
|
| 41 | - $this->service = $this->container->get($this->class); |
|
| 42 | - } catch (QueryException $e) { |
|
| 43 | - $this->logger->error( |
|
| 44 | - sprintf( |
|
| 45 | - 'Could not load event listener service %s: %s. Make sure the class is auto-loadable by the Nextcloud server container', |
|
| 46 | - $this->class, |
|
| 47 | - $e->getMessage() |
|
| 48 | - ), |
|
| 49 | - [ |
|
| 50 | - 'exception' => $e, |
|
| 51 | - ] |
|
| 52 | - ); |
|
| 53 | - return; |
|
| 54 | - } |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - $this->service->handle($event); |
|
| 58 | - } |
|
| 26 | + private ?IEventListener $service = null; |
|
| 27 | + |
|
| 28 | + public function __construct( |
|
| 29 | + private ContainerInterface $container, |
|
| 30 | + private string $class, |
|
| 31 | + private LoggerInterface $logger, |
|
| 32 | + ) { |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + public function __invoke(Event $event) { |
|
| 36 | + if ($this->service === null) { |
|
| 37 | + try { |
|
| 38 | + // TODO: fetch from the app containers, otherwise any custom services, |
|
| 39 | + // parameters and aliases won't be resolved. |
|
| 40 | + // See https://github.com/nextcloud/server/issues/27793 for details. |
|
| 41 | + $this->service = $this->container->get($this->class); |
|
| 42 | + } catch (QueryException $e) { |
|
| 43 | + $this->logger->error( |
|
| 44 | + sprintf( |
|
| 45 | + 'Could not load event listener service %s: %s. Make sure the class is auto-loadable by the Nextcloud server container', |
|
| 46 | + $this->class, |
|
| 47 | + $e->getMessage() |
|
| 48 | + ), |
|
| 49 | + [ |
|
| 50 | + 'exception' => $e, |
|
| 51 | + ] |
|
| 52 | + ); |
|
| 53 | + return; |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + $this->service->handle($event); |
|
| 58 | + } |
|
| 59 | 59 | } |
@@ -20,70 +20,70 @@ |
||
| 20 | 20 | use function get_class; |
| 21 | 21 | |
| 22 | 22 | class EventDispatcher implements IEventDispatcher { |
| 23 | - public function __construct( |
|
| 24 | - private SymfonyDispatcher $dispatcher, |
|
| 25 | - private ContainerInterface $container, |
|
| 26 | - private LoggerInterface $logger, |
|
| 27 | - ) { |
|
| 28 | - // inject the event dispatcher into the logger |
|
| 29 | - // this is done here because there is a cyclic dependency between the event dispatcher and logger |
|
| 30 | - if ($this->logger instanceof Log || $this->logger instanceof Log\PsrLoggerAdapter) { |
|
| 31 | - $this->logger->setEventDispatcher($this); |
|
| 32 | - } |
|
| 33 | - } |
|
| 23 | + public function __construct( |
|
| 24 | + private SymfonyDispatcher $dispatcher, |
|
| 25 | + private ContainerInterface $container, |
|
| 26 | + private LoggerInterface $logger, |
|
| 27 | + ) { |
|
| 28 | + // inject the event dispatcher into the logger |
|
| 29 | + // this is done here because there is a cyclic dependency between the event dispatcher and logger |
|
| 30 | + if ($this->logger instanceof Log || $this->logger instanceof Log\PsrLoggerAdapter) { |
|
| 31 | + $this->logger->setEventDispatcher($this); |
|
| 32 | + } |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - public function addListener(string $eventName, |
|
| 36 | - callable $listener, |
|
| 37 | - int $priority = 0): void { |
|
| 38 | - $this->dispatcher->addListener($eventName, $listener, $priority); |
|
| 39 | - } |
|
| 35 | + public function addListener(string $eventName, |
|
| 36 | + callable $listener, |
|
| 37 | + int $priority = 0): void { |
|
| 38 | + $this->dispatcher->addListener($eventName, $listener, $priority); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - public function removeListener(string $eventName, |
|
| 42 | - callable $listener): void { |
|
| 43 | - $this->dispatcher->removeListener($eventName, $listener); |
|
| 44 | - } |
|
| 41 | + public function removeListener(string $eventName, |
|
| 42 | + callable $listener): void { |
|
| 43 | + $this->dispatcher->removeListener($eventName, $listener); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - public function addServiceListener(string $eventName, |
|
| 47 | - string $className, |
|
| 48 | - int $priority = 0): void { |
|
| 49 | - $listener = new ServiceEventListener( |
|
| 50 | - $this->container, |
|
| 51 | - $className, |
|
| 52 | - $this->logger |
|
| 53 | - ); |
|
| 46 | + public function addServiceListener(string $eventName, |
|
| 47 | + string $className, |
|
| 48 | + int $priority = 0): void { |
|
| 49 | + $listener = new ServiceEventListener( |
|
| 50 | + $this->container, |
|
| 51 | + $className, |
|
| 52 | + $this->logger |
|
| 53 | + ); |
|
| 54 | 54 | |
| 55 | - $this->addListener($eventName, $listener, $priority); |
|
| 56 | - } |
|
| 55 | + $this->addListener($eventName, $listener, $priority); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - public function hasListeners(string $eventName): bool { |
|
| 59 | - return $this->dispatcher->hasListeners($eventName); |
|
| 60 | - } |
|
| 58 | + public function hasListeners(string $eventName): bool { |
|
| 59 | + return $this->dispatcher->hasListeners($eventName); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * @deprecated |
|
| 64 | - */ |
|
| 65 | - public function dispatch(string $eventName, |
|
| 66 | - Event $event): void { |
|
| 67 | - $this->dispatcher->dispatch($event, $eventName); |
|
| 62 | + /** |
|
| 63 | + * @deprecated |
|
| 64 | + */ |
|
| 65 | + public function dispatch(string $eventName, |
|
| 66 | + Event $event): void { |
|
| 67 | + $this->dispatcher->dispatch($event, $eventName); |
|
| 68 | 68 | |
| 69 | - if ($event instanceof ABroadcastedEvent && !$event->isPropagationStopped()) { |
|
| 70 | - // Propagate broadcast |
|
| 71 | - $this->dispatch( |
|
| 72 | - IBroadcastEvent::class, |
|
| 73 | - new BroadcastEvent($event) |
|
| 74 | - ); |
|
| 75 | - } |
|
| 76 | - } |
|
| 69 | + if ($event instanceof ABroadcastedEvent && !$event->isPropagationStopped()) { |
|
| 70 | + // Propagate broadcast |
|
| 71 | + $this->dispatch( |
|
| 72 | + IBroadcastEvent::class, |
|
| 73 | + new BroadcastEvent($event) |
|
| 74 | + ); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - public function dispatchTyped(Event $event): void { |
|
| 79 | - $this->dispatch(get_class($event), $event); |
|
| 80 | - } |
|
| 78 | + public function dispatchTyped(Event $event): void { |
|
| 79 | + $this->dispatch(get_class($event), $event); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * @return SymfonyDispatcher |
|
| 84 | - * @deprecated 20.0.0 |
|
| 85 | - */ |
|
| 86 | - public function getSymfonyDispatcher(): SymfonyDispatcher { |
|
| 87 | - return $this->dispatcher; |
|
| 88 | - } |
|
| 82 | + /** |
|
| 83 | + * @return SymfonyDispatcher |
|
| 84 | + * @deprecated 20.0.0 |
|
| 85 | + */ |
|
| 86 | + public function getSymfonyDispatcher(): SymfonyDispatcher { |
|
| 87 | + return $this->dispatcher; |
|
| 88 | + } |
|
| 89 | 89 | } |
@@ -249,1446 +249,1446 @@ |
||
| 249 | 249 | * TODO: hookup all manager classes |
| 250 | 250 | */ |
| 251 | 251 | class Server extends ServerContainer implements IServerContainer { |
| 252 | - /** @var string */ |
|
| 253 | - private $webRoot; |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * @param string $webRoot |
|
| 257 | - * @param \OC\Config $config |
|
| 258 | - */ |
|
| 259 | - public function __construct($webRoot, \OC\Config $config) { |
|
| 260 | - parent::__construct(); |
|
| 261 | - $this->webRoot = $webRoot; |
|
| 262 | - |
|
| 263 | - // To find out if we are running from CLI or not |
|
| 264 | - $this->registerParameter('isCLI', \OC::$CLI); |
|
| 265 | - $this->registerParameter('serverRoot', \OC::$SERVERROOT); |
|
| 266 | - |
|
| 267 | - $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
| 268 | - return $c; |
|
| 269 | - }); |
|
| 270 | - $this->registerDeprecatedAlias(\OCP\IServerContainer::class, ContainerInterface::class); |
|
| 271 | - |
|
| 272 | - $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
| 273 | - |
|
| 274 | - $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
| 275 | - |
|
| 276 | - $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
| 277 | - |
|
| 278 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
| 279 | - |
|
| 280 | - $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class); |
|
| 281 | - $this->registerAlias(ITemplateManager::class, TemplateManager::class); |
|
| 282 | - $this->registerAlias(\OCP\Template\ITemplateManager::class, \OC\Template\TemplateManager::class); |
|
| 283 | - |
|
| 284 | - $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
| 285 | - |
|
| 286 | - $this->registerService(View::class, function (Server $c) { |
|
| 287 | - return new View(); |
|
| 288 | - }, false); |
|
| 289 | - |
|
| 290 | - $this->registerService(IPreview::class, function (ContainerInterface $c) { |
|
| 291 | - return new PreviewManager( |
|
| 292 | - $c->get(\OCP\IConfig::class), |
|
| 293 | - $c->get(IRootFolder::class), |
|
| 294 | - new \OC\Preview\Storage\Root( |
|
| 295 | - $c->get(IRootFolder::class), |
|
| 296 | - $c->get(SystemConfig::class) |
|
| 297 | - ), |
|
| 298 | - $c->get(IEventDispatcher::class), |
|
| 299 | - $c->get(GeneratorHelper::class), |
|
| 300 | - $c->get(ISession::class)->get('user_id'), |
|
| 301 | - $c->get(Coordinator::class), |
|
| 302 | - $c->get(IServerContainer::class), |
|
| 303 | - $c->get(IBinaryFinder::class), |
|
| 304 | - $c->get(IMagickSupport::class) |
|
| 305 | - ); |
|
| 306 | - }); |
|
| 307 | - $this->registerAlias(IMimeIconProvider::class, MimeIconProvider::class); |
|
| 308 | - |
|
| 309 | - $this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) { |
|
| 310 | - return new \OC\Preview\Watcher( |
|
| 311 | - new \OC\Preview\Storage\Root( |
|
| 312 | - $c->get(IRootFolder::class), |
|
| 313 | - $c->get(SystemConfig::class) |
|
| 314 | - ) |
|
| 315 | - ); |
|
| 316 | - }); |
|
| 317 | - |
|
| 318 | - $this->registerService(IProfiler::class, function (Server $c) { |
|
| 319 | - return new Profiler($c->get(SystemConfig::class)); |
|
| 320 | - }); |
|
| 321 | - |
|
| 322 | - $this->registerService(Encryption\Manager::class, function (Server $c): Encryption\Manager { |
|
| 323 | - $view = new View(); |
|
| 324 | - $util = new Encryption\Util( |
|
| 325 | - $view, |
|
| 326 | - $c->get(IUserManager::class), |
|
| 327 | - $c->get(IGroupManager::class), |
|
| 328 | - $c->get(\OCP\IConfig::class) |
|
| 329 | - ); |
|
| 330 | - return new Encryption\Manager( |
|
| 331 | - $c->get(\OCP\IConfig::class), |
|
| 332 | - $c->get(LoggerInterface::class), |
|
| 333 | - $c->getL10N('core'), |
|
| 334 | - new View(), |
|
| 335 | - $util, |
|
| 336 | - new ArrayCache() |
|
| 337 | - ); |
|
| 338 | - }); |
|
| 339 | - $this->registerAlias(\OCP\Encryption\IManager::class, Encryption\Manager::class); |
|
| 340 | - |
|
| 341 | - $this->registerService(IFile::class, function (ContainerInterface $c) { |
|
| 342 | - $util = new Encryption\Util( |
|
| 343 | - new View(), |
|
| 344 | - $c->get(IUserManager::class), |
|
| 345 | - $c->get(IGroupManager::class), |
|
| 346 | - $c->get(\OCP\IConfig::class) |
|
| 347 | - ); |
|
| 348 | - return new Encryption\File( |
|
| 349 | - $util, |
|
| 350 | - $c->get(IRootFolder::class), |
|
| 351 | - $c->get(\OCP\Share\IManager::class) |
|
| 352 | - ); |
|
| 353 | - }); |
|
| 354 | - |
|
| 355 | - $this->registerService(IStorage::class, function (ContainerInterface $c) { |
|
| 356 | - $view = new View(); |
|
| 357 | - $util = new Encryption\Util( |
|
| 358 | - $view, |
|
| 359 | - $c->get(IUserManager::class), |
|
| 360 | - $c->get(IGroupManager::class), |
|
| 361 | - $c->get(\OCP\IConfig::class) |
|
| 362 | - ); |
|
| 363 | - |
|
| 364 | - return new Encryption\Keys\Storage( |
|
| 365 | - $view, |
|
| 366 | - $util, |
|
| 367 | - $c->get(ICrypto::class), |
|
| 368 | - $c->get(\OCP\IConfig::class) |
|
| 369 | - ); |
|
| 370 | - }); |
|
| 371 | - |
|
| 372 | - $this->registerAlias(\OCP\ITagManager::class, TagManager::class); |
|
| 373 | - |
|
| 374 | - $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) { |
|
| 375 | - /** @var \OCP\IConfig $config */ |
|
| 376 | - $config = $c->get(\OCP\IConfig::class); |
|
| 377 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
| 378 | - return new $factoryClass($this); |
|
| 379 | - }); |
|
| 380 | - $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) { |
|
| 381 | - return $c->get('SystemTagManagerFactory')->getManager(); |
|
| 382 | - }); |
|
| 383 | - /** @deprecated 19.0.0 */ |
|
| 384 | - $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); |
|
| 385 | - |
|
| 386 | - $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) { |
|
| 387 | - return $c->get('SystemTagManagerFactory')->getObjectMapper(); |
|
| 388 | - }); |
|
| 389 | - $this->registerAlias(IFileAccess::class, FileAccess::class); |
|
| 390 | - $this->registerService('RootFolder', function (ContainerInterface $c) { |
|
| 391 | - $manager = \OC\Files\Filesystem::getMountManager(); |
|
| 392 | - $view = new View(); |
|
| 393 | - /** @var IUserSession $userSession */ |
|
| 394 | - $userSession = $c->get(IUserSession::class); |
|
| 395 | - $root = new Root( |
|
| 396 | - $manager, |
|
| 397 | - $view, |
|
| 398 | - $userSession->getUser(), |
|
| 399 | - $c->get(IUserMountCache::class), |
|
| 400 | - $this->get(LoggerInterface::class), |
|
| 401 | - $this->get(IUserManager::class), |
|
| 402 | - $this->get(IEventDispatcher::class), |
|
| 403 | - $this->get(ICacheFactory::class), |
|
| 404 | - ); |
|
| 405 | - |
|
| 406 | - $previewConnector = new \OC\Preview\WatcherConnector( |
|
| 407 | - $root, |
|
| 408 | - $c->get(SystemConfig::class), |
|
| 409 | - $this->get(IEventDispatcher::class) |
|
| 410 | - ); |
|
| 411 | - $previewConnector->connectWatcher(); |
|
| 412 | - |
|
| 413 | - return $root; |
|
| 414 | - }); |
|
| 415 | - $this->registerService(HookConnector::class, function (ContainerInterface $c) { |
|
| 416 | - return new HookConnector( |
|
| 417 | - $c->get(IRootFolder::class), |
|
| 418 | - new View(), |
|
| 419 | - $c->get(IEventDispatcher::class), |
|
| 420 | - $c->get(LoggerInterface::class) |
|
| 421 | - ); |
|
| 422 | - }); |
|
| 423 | - |
|
| 424 | - $this->registerService(IRootFolder::class, function (ContainerInterface $c) { |
|
| 425 | - return new LazyRoot(function () use ($c) { |
|
| 426 | - return $c->get('RootFolder'); |
|
| 427 | - }); |
|
| 428 | - }); |
|
| 429 | - |
|
| 430 | - $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
| 431 | - |
|
| 432 | - $this->registerService(DisplayNameCache::class, function (ContainerInterface $c) { |
|
| 433 | - return $c->get(\OC\User\Manager::class)->getDisplayNameCache(); |
|
| 434 | - }); |
|
| 435 | - |
|
| 436 | - $this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) { |
|
| 437 | - $groupManager = new \OC\Group\Manager( |
|
| 438 | - $this->get(IUserManager::class), |
|
| 439 | - $this->get(IEventDispatcher::class), |
|
| 440 | - $this->get(LoggerInterface::class), |
|
| 441 | - $this->get(ICacheFactory::class), |
|
| 442 | - $this->get(IRemoteAddress::class), |
|
| 443 | - ); |
|
| 444 | - return $groupManager; |
|
| 445 | - }); |
|
| 446 | - |
|
| 447 | - $this->registerService(Store::class, function (ContainerInterface $c) { |
|
| 448 | - $session = $c->get(ISession::class); |
|
| 449 | - if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 450 | - $tokenProvider = $c->get(IProvider::class); |
|
| 451 | - } else { |
|
| 452 | - $tokenProvider = null; |
|
| 453 | - } |
|
| 454 | - $logger = $c->get(LoggerInterface::class); |
|
| 455 | - $crypto = $c->get(ICrypto::class); |
|
| 456 | - return new Store($session, $logger, $crypto, $tokenProvider); |
|
| 457 | - }); |
|
| 458 | - $this->registerAlias(IStore::class, Store::class); |
|
| 459 | - $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
| 460 | - $this->registerAlias(OCPIProvider::class, Authentication\Token\Manager::class); |
|
| 461 | - |
|
| 462 | - $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
| 463 | - $manager = $c->get(IUserManager::class); |
|
| 464 | - $session = new \OC\Session\Memory(); |
|
| 465 | - $timeFactory = new TimeFactory(); |
|
| 466 | - // Token providers might require a working database. This code |
|
| 467 | - // might however be called when Nextcloud is not yet setup. |
|
| 468 | - if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 469 | - $provider = $c->get(IProvider::class); |
|
| 470 | - } else { |
|
| 471 | - $provider = null; |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - $userSession = new \OC\User\Session( |
|
| 475 | - $manager, |
|
| 476 | - $session, |
|
| 477 | - $timeFactory, |
|
| 478 | - $provider, |
|
| 479 | - $c->get(\OCP\IConfig::class), |
|
| 480 | - $c->get(ISecureRandom::class), |
|
| 481 | - $c->get('LockdownManager'), |
|
| 482 | - $c->get(LoggerInterface::class), |
|
| 483 | - $c->get(IEventDispatcher::class), |
|
| 484 | - ); |
|
| 485 | - /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */ |
|
| 486 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
| 487 | - \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 488 | - }); |
|
| 489 | - /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */ |
|
| 490 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 491 | - /** @var \OC\User\User $user */ |
|
| 492 | - \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
|
| 493 | - }); |
|
| 494 | - /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */ |
|
| 495 | - $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
| 496 | - /** @var \OC\User\User $user */ |
|
| 497 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
|
| 498 | - }); |
|
| 499 | - /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ |
|
| 500 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 501 | - /** @var \OC\User\User $user */ |
|
| 502 | - \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
|
| 503 | - }); |
|
| 504 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 505 | - /** @var \OC\User\User $user */ |
|
| 506 | - \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 507 | - }); |
|
| 508 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 509 | - /** @var \OC\User\User $user */ |
|
| 510 | - \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 511 | - }); |
|
| 512 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 513 | - \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 514 | - |
|
| 515 | - /** @var IEventDispatcher $dispatcher */ |
|
| 516 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 517 | - $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); |
|
| 518 | - }); |
|
| 519 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) { |
|
| 520 | - /** @var \OC\User\User $user */ |
|
| 521 | - \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]); |
|
| 522 | - |
|
| 523 | - /** @var IEventDispatcher $dispatcher */ |
|
| 524 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 525 | - $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin)); |
|
| 526 | - }); |
|
| 527 | - $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { |
|
| 528 | - /** @var IEventDispatcher $dispatcher */ |
|
| 529 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 530 | - $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); |
|
| 531 | - }); |
|
| 532 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
| 533 | - /** @var \OC\User\User $user */ |
|
| 534 | - \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
|
| 535 | - |
|
| 536 | - /** @var IEventDispatcher $dispatcher */ |
|
| 537 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 538 | - $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); |
|
| 539 | - }); |
|
| 540 | - $userSession->listen('\OC\User', 'logout', function ($user) { |
|
| 541 | - \OC_Hook::emit('OC_User', 'logout', []); |
|
| 542 | - |
|
| 543 | - /** @var IEventDispatcher $dispatcher */ |
|
| 544 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 545 | - $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); |
|
| 546 | - }); |
|
| 547 | - $userSession->listen('\OC\User', 'postLogout', function ($user) { |
|
| 548 | - /** @var IEventDispatcher $dispatcher */ |
|
| 549 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 550 | - $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); |
|
| 551 | - }); |
|
| 552 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
| 553 | - /** @var \OC\User\User $user */ |
|
| 554 | - \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); |
|
| 555 | - }); |
|
| 556 | - return $userSession; |
|
| 557 | - }); |
|
| 558 | - $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
| 559 | - |
|
| 560 | - $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
| 561 | - |
|
| 562 | - $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class); |
|
| 563 | - |
|
| 564 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
| 565 | - |
|
| 566 | - $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
| 567 | - return new \OC\SystemConfig($config); |
|
| 568 | - }); |
|
| 569 | - |
|
| 570 | - $this->registerAlias(IAppConfig::class, \OC\AppConfig::class); |
|
| 571 | - $this->registerAlias(IUserConfig::class, \OC\Config\UserConfig::class); |
|
| 572 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
| 573 | - |
|
| 574 | - $this->registerService(IFactory::class, function (Server $c) { |
|
| 575 | - return new \OC\L10N\Factory( |
|
| 576 | - $c->get(\OCP\IConfig::class), |
|
| 577 | - $c->getRequest(), |
|
| 578 | - $c->get(IUserSession::class), |
|
| 579 | - $c->get(ICacheFactory::class), |
|
| 580 | - \OC::$SERVERROOT, |
|
| 581 | - $c->get(IAppManager::class), |
|
| 582 | - ); |
|
| 583 | - }); |
|
| 584 | - |
|
| 585 | - $this->registerAlias(IURLGenerator::class, URLGenerator::class); |
|
| 586 | - |
|
| 587 | - $this->registerService(ICache::class, function ($c) { |
|
| 588 | - return new Cache\File(); |
|
| 589 | - }); |
|
| 590 | - |
|
| 591 | - $this->registerService(Factory::class, function (Server $c) { |
|
| 592 | - $profiler = $c->get(IProfiler::class); |
|
| 593 | - $arrayCacheFactory = new \OC\Memcache\Factory(fn () => '', $c->get(LoggerInterface::class), |
|
| 594 | - $profiler, |
|
| 595 | - ArrayCache::class, |
|
| 596 | - ArrayCache::class, |
|
| 597 | - ArrayCache::class |
|
| 598 | - ); |
|
| 599 | - /** @var SystemConfig $config */ |
|
| 600 | - $config = $c->get(SystemConfig::class); |
|
| 601 | - /** @var ServerVersion $serverVersion */ |
|
| 602 | - $serverVersion = $c->get(ServerVersion::class); |
|
| 603 | - |
|
| 604 | - if ($config->getValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 605 | - $logQuery = $config->getValue('log_query'); |
|
| 606 | - $prefixClosure = function () use ($logQuery, $serverVersion): ?string { |
|
| 607 | - if (!$logQuery) { |
|
| 608 | - try { |
|
| 609 | - $v = \OCP\Server::get(IAppConfig::class)->getAppInstalledVersions(true); |
|
| 610 | - } catch (\Doctrine\DBAL\Exception $e) { |
|
| 611 | - // Database service probably unavailable |
|
| 612 | - // Probably related to https://github.com/nextcloud/server/issues/37424 |
|
| 613 | - return null; |
|
| 614 | - } |
|
| 615 | - } else { |
|
| 616 | - // If the log_query is enabled, we can not get the app versions |
|
| 617 | - // as that does a query, which will be logged and the logging |
|
| 618 | - // depends on redis and here we are back again in the same function. |
|
| 619 | - $v = [ |
|
| 620 | - 'log_query' => 'enabled', |
|
| 621 | - ]; |
|
| 622 | - } |
|
| 623 | - $v['core'] = implode(',', $serverVersion->getVersion()); |
|
| 624 | - $version = implode(',', array_keys($v)) . implode(',', $v); |
|
| 625 | - $instanceId = \OC_Util::getInstanceId(); |
|
| 626 | - $path = \OC::$SERVERROOT; |
|
| 627 | - return md5($instanceId . '-' . $version . '-' . $path); |
|
| 628 | - }; |
|
| 629 | - return new \OC\Memcache\Factory($prefixClosure, |
|
| 630 | - $c->get(LoggerInterface::class), |
|
| 631 | - $profiler, |
|
| 632 | - /** @psalm-taint-escape callable */ |
|
| 633 | - $config->getValue('memcache.local', null), |
|
| 634 | - /** @psalm-taint-escape callable */ |
|
| 635 | - $config->getValue('memcache.distributed', null), |
|
| 636 | - /** @psalm-taint-escape callable */ |
|
| 637 | - $config->getValue('memcache.locking', null), |
|
| 638 | - /** @psalm-taint-escape callable */ |
|
| 639 | - $config->getValue('redis_log_file') |
|
| 640 | - ); |
|
| 641 | - } |
|
| 642 | - return $arrayCacheFactory; |
|
| 643 | - }); |
|
| 644 | - $this->registerAlias(ICacheFactory::class, Factory::class); |
|
| 645 | - |
|
| 646 | - $this->registerService('RedisFactory', function (Server $c) { |
|
| 647 | - $systemConfig = $c->get(SystemConfig::class); |
|
| 648 | - return new RedisFactory($systemConfig, $c->get(IEventLogger::class)); |
|
| 649 | - }); |
|
| 650 | - |
|
| 651 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 652 | - $l10n = $this->get(IFactory::class)->get('lib'); |
|
| 653 | - return new \OC\Activity\Manager( |
|
| 654 | - $c->getRequest(), |
|
| 655 | - $c->get(IUserSession::class), |
|
| 656 | - $c->get(\OCP\IConfig::class), |
|
| 657 | - $c->get(IValidator::class), |
|
| 658 | - $c->get(IRichTextFormatter::class), |
|
| 659 | - $l10n |
|
| 660 | - ); |
|
| 661 | - }); |
|
| 662 | - |
|
| 663 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 664 | - return new \OC\Activity\EventMerger( |
|
| 665 | - $c->getL10N('lib') |
|
| 666 | - ); |
|
| 667 | - }); |
|
| 668 | - $this->registerAlias(IValidator::class, Validator::class); |
|
| 669 | - |
|
| 670 | - $this->registerService(AvatarManager::class, function (Server $c) { |
|
| 671 | - return new AvatarManager( |
|
| 672 | - $c->get(IUserSession::class), |
|
| 673 | - $c->get(\OC\User\Manager::class), |
|
| 674 | - $c->getAppDataDir('avatar'), |
|
| 675 | - $c->getL10N('lib'), |
|
| 676 | - $c->get(LoggerInterface::class), |
|
| 677 | - $c->get(\OCP\IConfig::class), |
|
| 678 | - $c->get(IAccountManager::class), |
|
| 679 | - $c->get(KnownUserService::class) |
|
| 680 | - ); |
|
| 681 | - }); |
|
| 682 | - |
|
| 683 | - $this->registerAlias(IAvatarManager::class, AvatarManager::class); |
|
| 684 | - |
|
| 685 | - $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
| 686 | - $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
|
| 687 | - $this->registerAlias(\OCP\Support\Subscription\IAssertion::class, \OC\Support\Subscription\Assertion::class); |
|
| 688 | - |
|
| 689 | - /** Only used by the PsrLoggerAdapter should not be used by apps */ |
|
| 690 | - $this->registerService(\OC\Log::class, function (Server $c) { |
|
| 691 | - $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file'); |
|
| 692 | - $factory = new LogFactory($c, $this->get(SystemConfig::class)); |
|
| 693 | - $logger = $factory->get($logType); |
|
| 694 | - $registry = $c->get(\OCP\Support\CrashReport\IRegistry::class); |
|
| 695 | - |
|
| 696 | - return new Log($logger, $this->get(SystemConfig::class), crashReporters: $registry); |
|
| 697 | - }); |
|
| 698 | - // PSR-3 logger |
|
| 699 | - $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); |
|
| 700 | - |
|
| 701 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
| 702 | - return new LogFactory($c, $this->get(SystemConfig::class)); |
|
| 703 | - }); |
|
| 704 | - |
|
| 705 | - $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class); |
|
| 706 | - |
|
| 707 | - $this->registerService(Router::class, function (Server $c) { |
|
| 708 | - $cacheFactory = $c->get(ICacheFactory::class); |
|
| 709 | - if ($cacheFactory->isLocalCacheAvailable()) { |
|
| 710 | - $router = $c->resolve(CachingRouter::class); |
|
| 711 | - } else { |
|
| 712 | - $router = $c->resolve(Router::class); |
|
| 713 | - } |
|
| 714 | - return $router; |
|
| 715 | - }); |
|
| 716 | - $this->registerAlias(IRouter::class, Router::class); |
|
| 717 | - |
|
| 718 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
| 719 | - $config = $c->get(\OCP\IConfig::class); |
|
| 720 | - if (ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === \OC\Memcache\Redis::class) { |
|
| 721 | - $backend = new \OC\Security\RateLimiting\Backend\MemoryCacheBackend( |
|
| 722 | - $c->get(AllConfig::class), |
|
| 723 | - $this->get(ICacheFactory::class), |
|
| 724 | - new \OC\AppFramework\Utility\TimeFactory() |
|
| 725 | - ); |
|
| 726 | - } else { |
|
| 727 | - $backend = new \OC\Security\RateLimiting\Backend\DatabaseBackend( |
|
| 728 | - $c->get(AllConfig::class), |
|
| 729 | - $c->get(IDBConnection::class), |
|
| 730 | - new \OC\AppFramework\Utility\TimeFactory() |
|
| 731 | - ); |
|
| 732 | - } |
|
| 733 | - |
|
| 734 | - return $backend; |
|
| 735 | - }); |
|
| 736 | - |
|
| 737 | - $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class); |
|
| 738 | - $this->registerAlias(\OCP\Security\IRemoteHostValidator::class, \OC\Security\RemoteHostValidator::class); |
|
| 739 | - $this->registerAlias(IVerificationToken::class, VerificationToken::class); |
|
| 740 | - |
|
| 741 | - $this->registerAlias(ICrypto::class, Crypto::class); |
|
| 742 | - |
|
| 743 | - $this->registerAlias(IHasher::class, Hasher::class); |
|
| 744 | - |
|
| 745 | - $this->registerAlias(ICredentialsManager::class, CredentialsManager::class); |
|
| 746 | - |
|
| 747 | - $this->registerAlias(IDBConnection::class, ConnectionAdapter::class); |
|
| 748 | - $this->registerService(Connection::class, function (Server $c) { |
|
| 749 | - $systemConfig = $c->get(SystemConfig::class); |
|
| 750 | - $factory = new \OC\DB\ConnectionFactory($systemConfig, $c->get(ICacheFactory::class)); |
|
| 751 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
| 752 | - if (!$factory->isValidType($type)) { |
|
| 753 | - throw new \OC\DatabaseException('Invalid database type'); |
|
| 754 | - } |
|
| 755 | - $connection = $factory->getConnection($type, []); |
|
| 756 | - return $connection; |
|
| 757 | - }); |
|
| 758 | - |
|
| 759 | - $this->registerAlias(ICertificateManager::class, CertificateManager::class); |
|
| 760 | - $this->registerAlias(IClientService::class, ClientService::class); |
|
| 761 | - $this->registerService(NegativeDnsCache::class, function (ContainerInterface $c) { |
|
| 762 | - return new NegativeDnsCache( |
|
| 763 | - $c->get(ICacheFactory::class), |
|
| 764 | - ); |
|
| 765 | - }); |
|
| 766 | - $this->registerDeprecatedAlias('HttpClientService', IClientService::class); |
|
| 767 | - $this->registerService(IEventLogger::class, function (ContainerInterface $c) { |
|
| 768 | - return new EventLogger($c->get(SystemConfig::class), $c->get(LoggerInterface::class), $c->get(Log::class)); |
|
| 769 | - }); |
|
| 770 | - |
|
| 771 | - $this->registerService(IQueryLogger::class, function (ContainerInterface $c) { |
|
| 772 | - $queryLogger = new QueryLogger(); |
|
| 773 | - if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
|
| 774 | - // In debug mode, module is being activated by default |
|
| 775 | - $queryLogger->activate(); |
|
| 776 | - } |
|
| 777 | - return $queryLogger; |
|
| 778 | - }); |
|
| 779 | - |
|
| 780 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
| 781 | - $this->registerAlias(IDateTimeZone::class, DateTimeZone::class); |
|
| 782 | - |
|
| 783 | - $this->registerService(IDateTimeFormatter::class, function (Server $c) { |
|
| 784 | - $language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null); |
|
| 785 | - |
|
| 786 | - return new DateTimeFormatter( |
|
| 787 | - $c->get(IDateTimeZone::class)->getTimeZone(), |
|
| 788 | - $c->getL10N('lib', $language) |
|
| 789 | - ); |
|
| 790 | - }); |
|
| 791 | - |
|
| 792 | - $this->registerService(IUserMountCache::class, function (ContainerInterface $c) { |
|
| 793 | - $mountCache = $c->get(UserMountCache::class); |
|
| 794 | - $listener = new UserMountCacheListener($mountCache); |
|
| 795 | - $listener->listen($c->get(IUserManager::class)); |
|
| 796 | - return $mountCache; |
|
| 797 | - }); |
|
| 798 | - |
|
| 799 | - $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) { |
|
| 800 | - $loader = $c->get(IStorageFactory::class); |
|
| 801 | - $mountCache = $c->get(IUserMountCache::class); |
|
| 802 | - $eventLogger = $c->get(IEventLogger::class); |
|
| 803 | - $manager = new MountProviderCollection($loader, $mountCache, $eventLogger); |
|
| 804 | - |
|
| 805 | - // builtin providers |
|
| 806 | - |
|
| 807 | - $config = $c->get(\OCP\IConfig::class); |
|
| 808 | - $logger = $c->get(LoggerInterface::class); |
|
| 809 | - $objectStoreConfig = $c->get(PrimaryObjectStoreConfig::class); |
|
| 810 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
| 811 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
| 812 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($objectStoreConfig)); |
|
| 813 | - $manager->registerRootProvider(new RootMountProvider($objectStoreConfig, $config)); |
|
| 814 | - $manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config)); |
|
| 815 | - |
|
| 816 | - return $manager; |
|
| 817 | - }); |
|
| 818 | - |
|
| 819 | - $this->registerService(IBus::class, function (ContainerInterface $c) { |
|
| 820 | - $busClass = $c->get(\OCP\IConfig::class)->getSystemValueString('commandbus'); |
|
| 821 | - if ($busClass) { |
|
| 822 | - [$app, $class] = explode('::', $busClass, 2); |
|
| 823 | - if ($c->get(IAppManager::class)->isEnabledForUser($app)) { |
|
| 824 | - $c->get(IAppManager::class)->loadApp($app); |
|
| 825 | - return $c->get($class); |
|
| 826 | - } else { |
|
| 827 | - throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
| 828 | - } |
|
| 829 | - } else { |
|
| 830 | - $jobList = $c->get(IJobList::class); |
|
| 831 | - return new CronBus($jobList); |
|
| 832 | - } |
|
| 833 | - }); |
|
| 834 | - $this->registerDeprecatedAlias('AsyncCommandBus', IBus::class); |
|
| 835 | - $this->registerAlias(ITrustedDomainHelper::class, TrustedDomainHelper::class); |
|
| 836 | - $this->registerAlias(IThrottler::class, Throttler::class); |
|
| 837 | - |
|
| 838 | - $this->registerService(\OC\Security\Bruteforce\Backend\IBackend::class, function ($c) { |
|
| 839 | - $config = $c->get(\OCP\IConfig::class); |
|
| 840 | - if (!$config->getSystemValueBool('auth.bruteforce.protection.force.database', false) |
|
| 841 | - && ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === \OC\Memcache\Redis::class) { |
|
| 842 | - $backend = $c->get(\OC\Security\Bruteforce\Backend\MemoryCacheBackend::class); |
|
| 843 | - } else { |
|
| 844 | - $backend = $c->get(\OC\Security\Bruteforce\Backend\DatabaseBackend::class); |
|
| 845 | - } |
|
| 846 | - |
|
| 847 | - return $backend; |
|
| 848 | - }); |
|
| 849 | - |
|
| 850 | - $this->registerDeprecatedAlias('IntegrityCodeChecker', Checker::class); |
|
| 851 | - $this->registerService(Checker::class, function (ContainerInterface $c) { |
|
| 852 | - // IConfig requires a working database. This code |
|
| 853 | - // might however be called when Nextcloud is not yet setup. |
|
| 854 | - if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 855 | - $config = $c->get(\OCP\IConfig::class); |
|
| 856 | - $appConfig = $c->get(\OCP\IAppConfig::class); |
|
| 857 | - } else { |
|
| 858 | - $config = null; |
|
| 859 | - $appConfig = null; |
|
| 860 | - } |
|
| 861 | - |
|
| 862 | - return new Checker( |
|
| 863 | - $c->get(ServerVersion::class), |
|
| 864 | - $c->get(EnvironmentHelper::class), |
|
| 865 | - new FileAccessHelper(), |
|
| 866 | - new AppLocator(), |
|
| 867 | - $config, |
|
| 868 | - $appConfig, |
|
| 869 | - $c->get(ICacheFactory::class), |
|
| 870 | - $c->get(IAppManager::class), |
|
| 871 | - $c->get(IMimeTypeDetector::class) |
|
| 872 | - ); |
|
| 873 | - }); |
|
| 874 | - $this->registerService(Request::class, function (ContainerInterface $c) { |
|
| 875 | - if (isset($this['urlParams'])) { |
|
| 876 | - $urlParams = $this['urlParams']; |
|
| 877 | - } else { |
|
| 878 | - $urlParams = []; |
|
| 879 | - } |
|
| 880 | - |
|
| 881 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
| 882 | - && in_array('fakeinput', stream_get_wrappers()) |
|
| 883 | - ) { |
|
| 884 | - $stream = 'fakeinput://data'; |
|
| 885 | - } else { |
|
| 886 | - $stream = 'php://input'; |
|
| 887 | - } |
|
| 888 | - |
|
| 889 | - return new Request( |
|
| 890 | - [ |
|
| 891 | - 'get' => $_GET, |
|
| 892 | - 'post' => $_POST, |
|
| 893 | - 'files' => $_FILES, |
|
| 894 | - 'server' => $_SERVER, |
|
| 895 | - 'env' => $_ENV, |
|
| 896 | - 'cookies' => $_COOKIE, |
|
| 897 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 898 | - ? $_SERVER['REQUEST_METHOD'] |
|
| 899 | - : '', |
|
| 900 | - 'urlParams' => $urlParams, |
|
| 901 | - ], |
|
| 902 | - $this->get(IRequestId::class), |
|
| 903 | - $this->get(\OCP\IConfig::class), |
|
| 904 | - $this->get(CsrfTokenManager::class), |
|
| 905 | - $stream |
|
| 906 | - ); |
|
| 907 | - }); |
|
| 908 | - $this->registerAlias(\OCP\IRequest::class, Request::class); |
|
| 909 | - |
|
| 910 | - $this->registerService(IRequestId::class, function (ContainerInterface $c): IRequestId { |
|
| 911 | - return new RequestId( |
|
| 912 | - $_SERVER['UNIQUE_ID'] ?? '', |
|
| 913 | - $this->get(ISecureRandom::class) |
|
| 914 | - ); |
|
| 915 | - }); |
|
| 916 | - |
|
| 917 | - $this->registerService(IMailer::class, function (Server $c) { |
|
| 918 | - return new Mailer( |
|
| 919 | - $c->get(\OCP\IConfig::class), |
|
| 920 | - $c->get(LoggerInterface::class), |
|
| 921 | - $c->get(Defaults::class), |
|
| 922 | - $c->get(IURLGenerator::class), |
|
| 923 | - $c->getL10N('lib'), |
|
| 924 | - $c->get(IEventDispatcher::class), |
|
| 925 | - $c->get(IFactory::class) |
|
| 926 | - ); |
|
| 927 | - }); |
|
| 928 | - |
|
| 929 | - /** @since 30.0.0 */ |
|
| 930 | - $this->registerAlias(\OCP\Mail\Provider\IManager::class, \OC\Mail\Provider\Manager::class); |
|
| 931 | - |
|
| 932 | - $this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) { |
|
| 933 | - $config = $c->get(\OCP\IConfig::class); |
|
| 934 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
| 935 | - if (is_null($factoryClass) || !class_exists($factoryClass)) { |
|
| 936 | - return new NullLDAPProviderFactory($this); |
|
| 937 | - } |
|
| 938 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
| 939 | - return new $factoryClass($this); |
|
| 940 | - }); |
|
| 941 | - $this->registerService(ILDAPProvider::class, function (ContainerInterface $c) { |
|
| 942 | - $factory = $c->get(ILDAPProviderFactory::class); |
|
| 943 | - return $factory->getLDAPProvider(); |
|
| 944 | - }); |
|
| 945 | - $this->registerService(ILockingProvider::class, function (ContainerInterface $c) { |
|
| 946 | - $ini = $c->get(IniGetWrapper::class); |
|
| 947 | - $config = $c->get(\OCP\IConfig::class); |
|
| 948 | - $ttl = $config->getSystemValueInt('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
| 949 | - if ($config->getSystemValueBool('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 950 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
| 951 | - $memcacheFactory = $c->get(ICacheFactory::class); |
|
| 952 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
| 953 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
| 954 | - $timeFactory = $c->get(ITimeFactory::class); |
|
| 955 | - return new MemcacheLockingProvider($memcache, $timeFactory, $ttl); |
|
| 956 | - } |
|
| 957 | - return new DBLockingProvider( |
|
| 958 | - $c->get(IDBConnection::class), |
|
| 959 | - new TimeFactory(), |
|
| 960 | - $ttl, |
|
| 961 | - !\OC::$CLI |
|
| 962 | - ); |
|
| 963 | - } |
|
| 964 | - return new NoopLockingProvider(); |
|
| 965 | - }); |
|
| 966 | - |
|
| 967 | - $this->registerService(ILockManager::class, function (Server $c): LockManager { |
|
| 968 | - return new LockManager(); |
|
| 969 | - }); |
|
| 970 | - |
|
| 971 | - $this->registerAlias(ILockdownManager::class, 'LockdownManager'); |
|
| 972 | - $this->registerService(SetupManager::class, function ($c) { |
|
| 973 | - // create the setupmanager through the mount manager to resolve the cyclic dependency |
|
| 974 | - return $c->get(\OC\Files\Mount\Manager::class)->getSetupManager(); |
|
| 975 | - }); |
|
| 976 | - $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class); |
|
| 977 | - |
|
| 978 | - $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) { |
|
| 979 | - return new \OC\Files\Type\Detection( |
|
| 980 | - $c->get(IURLGenerator::class), |
|
| 981 | - $c->get(LoggerInterface::class), |
|
| 982 | - \OC::$configDir, |
|
| 983 | - \OC::$SERVERROOT . '/resources/config/' |
|
| 984 | - ); |
|
| 985 | - }); |
|
| 986 | - |
|
| 987 | - $this->registerAlias(IMimeTypeLoader::class, Loader::class); |
|
| 988 | - $this->registerService(BundleFetcher::class, function () { |
|
| 989 | - return new BundleFetcher($this->getL10N('lib')); |
|
| 990 | - }); |
|
| 991 | - $this->registerAlias(\OCP\Notification\IManager::class, Manager::class); |
|
| 992 | - |
|
| 993 | - $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) { |
|
| 994 | - $manager = new CapabilitiesManager($c->get(LoggerInterface::class)); |
|
| 995 | - $manager->registerCapability(function () use ($c) { |
|
| 996 | - return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class)); |
|
| 997 | - }); |
|
| 998 | - $manager->registerCapability(function () use ($c) { |
|
| 999 | - return $c->get(\OC\Security\Bruteforce\Capabilities::class); |
|
| 1000 | - }); |
|
| 1001 | - return $manager; |
|
| 1002 | - }); |
|
| 1003 | - |
|
| 1004 | - $this->registerService(ICommentsManager::class, function (Server $c) { |
|
| 1005 | - $config = $c->get(\OCP\IConfig::class); |
|
| 1006 | - $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
| 1007 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
| 1008 | - $factory = new $factoryClass($this); |
|
| 1009 | - $manager = $factory->getManager(); |
|
| 1010 | - |
|
| 1011 | - $manager->registerDisplayNameResolver('user', function ($id) use ($c) { |
|
| 1012 | - $manager = $c->get(IUserManager::class); |
|
| 1013 | - $userDisplayName = $manager->getDisplayName($id); |
|
| 1014 | - if ($userDisplayName === null) { |
|
| 1015 | - $l = $c->get(IFactory::class)->get('core'); |
|
| 1016 | - return $l->t('Unknown account'); |
|
| 1017 | - } |
|
| 1018 | - return $userDisplayName; |
|
| 1019 | - }); |
|
| 1020 | - |
|
| 1021 | - return $manager; |
|
| 1022 | - }); |
|
| 1023 | - |
|
| 1024 | - $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults'); |
|
| 1025 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
| 1026 | - try { |
|
| 1027 | - $classExists = class_exists('OCA\Theming\ThemingDefaults'); |
|
| 1028 | - } catch (\OCP\AutoloadNotAllowedException $e) { |
|
| 1029 | - // App disabled or in maintenance mode |
|
| 1030 | - $classExists = false; |
|
| 1031 | - } |
|
| 1032 | - |
|
| 1033 | - if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValueBool('installed', false) && $c->get(IAppManager::class)->isEnabledForAnyone('theming') && $c->get(TrustedDomainHelper::class)->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
| 1034 | - $backgroundService = new BackgroundService( |
|
| 1035 | - $c->get(IRootFolder::class), |
|
| 1036 | - $c->getAppDataDir('theming'), |
|
| 1037 | - $c->get(IAppConfig::class), |
|
| 1038 | - $c->get(\OCP\IConfig::class), |
|
| 1039 | - $c->get(ISession::class)->get('user_id'), |
|
| 1040 | - ); |
|
| 1041 | - $imageManager = new ImageManager( |
|
| 1042 | - $c->get(\OCP\IConfig::class), |
|
| 1043 | - $c->getAppDataDir('theming'), |
|
| 1044 | - $c->get(IURLGenerator::class), |
|
| 1045 | - $c->get(ICacheFactory::class), |
|
| 1046 | - $c->get(LoggerInterface::class), |
|
| 1047 | - $c->get(ITempManager::class), |
|
| 1048 | - $backgroundService, |
|
| 1049 | - ); |
|
| 1050 | - return new ThemingDefaults( |
|
| 1051 | - $c->get(\OCP\IConfig::class), |
|
| 1052 | - $c->get(\OCP\IAppConfig::class), |
|
| 1053 | - $c->getL10N('theming'), |
|
| 1054 | - $c->get(IUserSession::class), |
|
| 1055 | - $c->get(IURLGenerator::class), |
|
| 1056 | - $c->get(ICacheFactory::class), |
|
| 1057 | - new Util($c->get(ServerVersion::class), $c->get(\OCP\IConfig::class), $this->get(IAppManager::class), $c->getAppDataDir('theming'), $imageManager), |
|
| 1058 | - $imageManager, |
|
| 1059 | - $c->get(IAppManager::class), |
|
| 1060 | - $c->get(INavigationManager::class), |
|
| 1061 | - $backgroundService, |
|
| 1062 | - ); |
|
| 1063 | - } |
|
| 1064 | - return new \OC_Defaults(); |
|
| 1065 | - }); |
|
| 1066 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
| 1067 | - return new JSCombiner( |
|
| 1068 | - $c->getAppDataDir('js'), |
|
| 1069 | - $c->get(IURLGenerator::class), |
|
| 1070 | - $this->get(ICacheFactory::class), |
|
| 1071 | - $c->get(SystemConfig::class), |
|
| 1072 | - $c->get(LoggerInterface::class) |
|
| 1073 | - ); |
|
| 1074 | - }); |
|
| 1075 | - $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
|
| 1076 | - |
|
| 1077 | - $this->registerService('CryptoWrapper', function (ContainerInterface $c) { |
|
| 1078 | - // FIXME: Instantiated here due to cyclic dependency |
|
| 1079 | - $request = new Request( |
|
| 1080 | - [ |
|
| 1081 | - 'get' => $_GET, |
|
| 1082 | - 'post' => $_POST, |
|
| 1083 | - 'files' => $_FILES, |
|
| 1084 | - 'server' => $_SERVER, |
|
| 1085 | - 'env' => $_ENV, |
|
| 1086 | - 'cookies' => $_COOKIE, |
|
| 1087 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 1088 | - ? $_SERVER['REQUEST_METHOD'] |
|
| 1089 | - : null, |
|
| 1090 | - ], |
|
| 1091 | - $c->get(IRequestId::class), |
|
| 1092 | - $c->get(\OCP\IConfig::class) |
|
| 1093 | - ); |
|
| 1094 | - |
|
| 1095 | - return new CryptoWrapper( |
|
| 1096 | - $c->get(ICrypto::class), |
|
| 1097 | - $c->get(ISecureRandom::class), |
|
| 1098 | - $request |
|
| 1099 | - ); |
|
| 1100 | - }); |
|
| 1101 | - $this->registerService(SessionStorage::class, function (ContainerInterface $c) { |
|
| 1102 | - return new SessionStorage($c->get(ISession::class)); |
|
| 1103 | - }); |
|
| 1104 | - $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); |
|
| 1105 | - |
|
| 1106 | - $this->registerService(IProviderFactory::class, function (ContainerInterface $c) { |
|
| 1107 | - $config = $c->get(\OCP\IConfig::class); |
|
| 1108 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
| 1109 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
| 1110 | - return $c->get($factoryClass); |
|
| 1111 | - }); |
|
| 1112 | - |
|
| 1113 | - $this->registerAlias(\OCP\Share\IManager::class, \OC\Share20\Manager::class); |
|
| 1114 | - |
|
| 1115 | - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) { |
|
| 1116 | - $instance = new Collaboration\Collaborators\Search($c); |
|
| 1117 | - |
|
| 1118 | - // register default plugins |
|
| 1119 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
| 1120 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
| 1121 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
| 1122 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
| 1123 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
| 1124 | - |
|
| 1125 | - return $instance; |
|
| 1126 | - }); |
|
| 1127 | - $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
| 1128 | - |
|
| 1129 | - $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
| 1130 | - |
|
| 1131 | - $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class); |
|
| 1132 | - $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
| 1133 | - |
|
| 1134 | - $this->registerAlias(IReferenceManager::class, ReferenceManager::class); |
|
| 1135 | - $this->registerAlias(ITeamManager::class, TeamManager::class); |
|
| 1136 | - |
|
| 1137 | - $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class); |
|
| 1138 | - $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class); |
|
| 1139 | - $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) { |
|
| 1140 | - return new \OC\Files\AppData\Factory( |
|
| 1141 | - $c->get(IRootFolder::class), |
|
| 1142 | - $c->get(SystemConfig::class) |
|
| 1143 | - ); |
|
| 1144 | - }); |
|
| 1145 | - |
|
| 1146 | - $this->registerService('LockdownManager', function (ContainerInterface $c) { |
|
| 1147 | - return new LockdownManager(function () use ($c) { |
|
| 1148 | - return $c->get(ISession::class); |
|
| 1149 | - }); |
|
| 1150 | - }); |
|
| 1151 | - |
|
| 1152 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) { |
|
| 1153 | - return new DiscoveryService( |
|
| 1154 | - $c->get(ICacheFactory::class), |
|
| 1155 | - $c->get(IClientService::class) |
|
| 1156 | - ); |
|
| 1157 | - }); |
|
| 1158 | - $this->registerAlias(IOCMDiscoveryService::class, OCMDiscoveryService::class); |
|
| 1159 | - |
|
| 1160 | - $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) { |
|
| 1161 | - return new CloudIdManager( |
|
| 1162 | - $c->get(\OCP\Contacts\IManager::class), |
|
| 1163 | - $c->get(IURLGenerator::class), |
|
| 1164 | - $c->get(IUserManager::class), |
|
| 1165 | - $c->get(ICacheFactory::class), |
|
| 1166 | - $c->get(IEventDispatcher::class), |
|
| 1167 | - ); |
|
| 1168 | - }); |
|
| 1169 | - |
|
| 1170 | - $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class); |
|
| 1171 | - $this->registerAlias(ICloudFederationProviderManager::class, CloudFederationProviderManager::class); |
|
| 1172 | - $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
| 1173 | - return new CloudFederationFactory(); |
|
| 1174 | - }); |
|
| 252 | + /** @var string */ |
|
| 253 | + private $webRoot; |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * @param string $webRoot |
|
| 257 | + * @param \OC\Config $config |
|
| 258 | + */ |
|
| 259 | + public function __construct($webRoot, \OC\Config $config) { |
|
| 260 | + parent::__construct(); |
|
| 261 | + $this->webRoot = $webRoot; |
|
| 262 | + |
|
| 263 | + // To find out if we are running from CLI or not |
|
| 264 | + $this->registerParameter('isCLI', \OC::$CLI); |
|
| 265 | + $this->registerParameter('serverRoot', \OC::$SERVERROOT); |
|
| 266 | + |
|
| 267 | + $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
| 268 | + return $c; |
|
| 269 | + }); |
|
| 270 | + $this->registerDeprecatedAlias(\OCP\IServerContainer::class, ContainerInterface::class); |
|
| 271 | + |
|
| 272 | + $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
| 273 | + |
|
| 274 | + $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
| 275 | + |
|
| 276 | + $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
| 277 | + |
|
| 278 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
| 279 | + |
|
| 280 | + $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class); |
|
| 281 | + $this->registerAlias(ITemplateManager::class, TemplateManager::class); |
|
| 282 | + $this->registerAlias(\OCP\Template\ITemplateManager::class, \OC\Template\TemplateManager::class); |
|
| 283 | + |
|
| 284 | + $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
| 285 | + |
|
| 286 | + $this->registerService(View::class, function (Server $c) { |
|
| 287 | + return new View(); |
|
| 288 | + }, false); |
|
| 289 | + |
|
| 290 | + $this->registerService(IPreview::class, function (ContainerInterface $c) { |
|
| 291 | + return new PreviewManager( |
|
| 292 | + $c->get(\OCP\IConfig::class), |
|
| 293 | + $c->get(IRootFolder::class), |
|
| 294 | + new \OC\Preview\Storage\Root( |
|
| 295 | + $c->get(IRootFolder::class), |
|
| 296 | + $c->get(SystemConfig::class) |
|
| 297 | + ), |
|
| 298 | + $c->get(IEventDispatcher::class), |
|
| 299 | + $c->get(GeneratorHelper::class), |
|
| 300 | + $c->get(ISession::class)->get('user_id'), |
|
| 301 | + $c->get(Coordinator::class), |
|
| 302 | + $c->get(IServerContainer::class), |
|
| 303 | + $c->get(IBinaryFinder::class), |
|
| 304 | + $c->get(IMagickSupport::class) |
|
| 305 | + ); |
|
| 306 | + }); |
|
| 307 | + $this->registerAlias(IMimeIconProvider::class, MimeIconProvider::class); |
|
| 308 | + |
|
| 309 | + $this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) { |
|
| 310 | + return new \OC\Preview\Watcher( |
|
| 311 | + new \OC\Preview\Storage\Root( |
|
| 312 | + $c->get(IRootFolder::class), |
|
| 313 | + $c->get(SystemConfig::class) |
|
| 314 | + ) |
|
| 315 | + ); |
|
| 316 | + }); |
|
| 317 | + |
|
| 318 | + $this->registerService(IProfiler::class, function (Server $c) { |
|
| 319 | + return new Profiler($c->get(SystemConfig::class)); |
|
| 320 | + }); |
|
| 321 | + |
|
| 322 | + $this->registerService(Encryption\Manager::class, function (Server $c): Encryption\Manager { |
|
| 323 | + $view = new View(); |
|
| 324 | + $util = new Encryption\Util( |
|
| 325 | + $view, |
|
| 326 | + $c->get(IUserManager::class), |
|
| 327 | + $c->get(IGroupManager::class), |
|
| 328 | + $c->get(\OCP\IConfig::class) |
|
| 329 | + ); |
|
| 330 | + return new Encryption\Manager( |
|
| 331 | + $c->get(\OCP\IConfig::class), |
|
| 332 | + $c->get(LoggerInterface::class), |
|
| 333 | + $c->getL10N('core'), |
|
| 334 | + new View(), |
|
| 335 | + $util, |
|
| 336 | + new ArrayCache() |
|
| 337 | + ); |
|
| 338 | + }); |
|
| 339 | + $this->registerAlias(\OCP\Encryption\IManager::class, Encryption\Manager::class); |
|
| 340 | + |
|
| 341 | + $this->registerService(IFile::class, function (ContainerInterface $c) { |
|
| 342 | + $util = new Encryption\Util( |
|
| 343 | + new View(), |
|
| 344 | + $c->get(IUserManager::class), |
|
| 345 | + $c->get(IGroupManager::class), |
|
| 346 | + $c->get(\OCP\IConfig::class) |
|
| 347 | + ); |
|
| 348 | + return new Encryption\File( |
|
| 349 | + $util, |
|
| 350 | + $c->get(IRootFolder::class), |
|
| 351 | + $c->get(\OCP\Share\IManager::class) |
|
| 352 | + ); |
|
| 353 | + }); |
|
| 354 | + |
|
| 355 | + $this->registerService(IStorage::class, function (ContainerInterface $c) { |
|
| 356 | + $view = new View(); |
|
| 357 | + $util = new Encryption\Util( |
|
| 358 | + $view, |
|
| 359 | + $c->get(IUserManager::class), |
|
| 360 | + $c->get(IGroupManager::class), |
|
| 361 | + $c->get(\OCP\IConfig::class) |
|
| 362 | + ); |
|
| 363 | + |
|
| 364 | + return new Encryption\Keys\Storage( |
|
| 365 | + $view, |
|
| 366 | + $util, |
|
| 367 | + $c->get(ICrypto::class), |
|
| 368 | + $c->get(\OCP\IConfig::class) |
|
| 369 | + ); |
|
| 370 | + }); |
|
| 371 | + |
|
| 372 | + $this->registerAlias(\OCP\ITagManager::class, TagManager::class); |
|
| 373 | + |
|
| 374 | + $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) { |
|
| 375 | + /** @var \OCP\IConfig $config */ |
|
| 376 | + $config = $c->get(\OCP\IConfig::class); |
|
| 377 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
| 378 | + return new $factoryClass($this); |
|
| 379 | + }); |
|
| 380 | + $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) { |
|
| 381 | + return $c->get('SystemTagManagerFactory')->getManager(); |
|
| 382 | + }); |
|
| 383 | + /** @deprecated 19.0.0 */ |
|
| 384 | + $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); |
|
| 385 | + |
|
| 386 | + $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) { |
|
| 387 | + return $c->get('SystemTagManagerFactory')->getObjectMapper(); |
|
| 388 | + }); |
|
| 389 | + $this->registerAlias(IFileAccess::class, FileAccess::class); |
|
| 390 | + $this->registerService('RootFolder', function (ContainerInterface $c) { |
|
| 391 | + $manager = \OC\Files\Filesystem::getMountManager(); |
|
| 392 | + $view = new View(); |
|
| 393 | + /** @var IUserSession $userSession */ |
|
| 394 | + $userSession = $c->get(IUserSession::class); |
|
| 395 | + $root = new Root( |
|
| 396 | + $manager, |
|
| 397 | + $view, |
|
| 398 | + $userSession->getUser(), |
|
| 399 | + $c->get(IUserMountCache::class), |
|
| 400 | + $this->get(LoggerInterface::class), |
|
| 401 | + $this->get(IUserManager::class), |
|
| 402 | + $this->get(IEventDispatcher::class), |
|
| 403 | + $this->get(ICacheFactory::class), |
|
| 404 | + ); |
|
| 405 | + |
|
| 406 | + $previewConnector = new \OC\Preview\WatcherConnector( |
|
| 407 | + $root, |
|
| 408 | + $c->get(SystemConfig::class), |
|
| 409 | + $this->get(IEventDispatcher::class) |
|
| 410 | + ); |
|
| 411 | + $previewConnector->connectWatcher(); |
|
| 412 | + |
|
| 413 | + return $root; |
|
| 414 | + }); |
|
| 415 | + $this->registerService(HookConnector::class, function (ContainerInterface $c) { |
|
| 416 | + return new HookConnector( |
|
| 417 | + $c->get(IRootFolder::class), |
|
| 418 | + new View(), |
|
| 419 | + $c->get(IEventDispatcher::class), |
|
| 420 | + $c->get(LoggerInterface::class) |
|
| 421 | + ); |
|
| 422 | + }); |
|
| 423 | + |
|
| 424 | + $this->registerService(IRootFolder::class, function (ContainerInterface $c) { |
|
| 425 | + return new LazyRoot(function () use ($c) { |
|
| 426 | + return $c->get('RootFolder'); |
|
| 427 | + }); |
|
| 428 | + }); |
|
| 429 | + |
|
| 430 | + $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
| 431 | + |
|
| 432 | + $this->registerService(DisplayNameCache::class, function (ContainerInterface $c) { |
|
| 433 | + return $c->get(\OC\User\Manager::class)->getDisplayNameCache(); |
|
| 434 | + }); |
|
| 435 | + |
|
| 436 | + $this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) { |
|
| 437 | + $groupManager = new \OC\Group\Manager( |
|
| 438 | + $this->get(IUserManager::class), |
|
| 439 | + $this->get(IEventDispatcher::class), |
|
| 440 | + $this->get(LoggerInterface::class), |
|
| 441 | + $this->get(ICacheFactory::class), |
|
| 442 | + $this->get(IRemoteAddress::class), |
|
| 443 | + ); |
|
| 444 | + return $groupManager; |
|
| 445 | + }); |
|
| 446 | + |
|
| 447 | + $this->registerService(Store::class, function (ContainerInterface $c) { |
|
| 448 | + $session = $c->get(ISession::class); |
|
| 449 | + if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 450 | + $tokenProvider = $c->get(IProvider::class); |
|
| 451 | + } else { |
|
| 452 | + $tokenProvider = null; |
|
| 453 | + } |
|
| 454 | + $logger = $c->get(LoggerInterface::class); |
|
| 455 | + $crypto = $c->get(ICrypto::class); |
|
| 456 | + return new Store($session, $logger, $crypto, $tokenProvider); |
|
| 457 | + }); |
|
| 458 | + $this->registerAlias(IStore::class, Store::class); |
|
| 459 | + $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
| 460 | + $this->registerAlias(OCPIProvider::class, Authentication\Token\Manager::class); |
|
| 461 | + |
|
| 462 | + $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
| 463 | + $manager = $c->get(IUserManager::class); |
|
| 464 | + $session = new \OC\Session\Memory(); |
|
| 465 | + $timeFactory = new TimeFactory(); |
|
| 466 | + // Token providers might require a working database. This code |
|
| 467 | + // might however be called when Nextcloud is not yet setup. |
|
| 468 | + if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 469 | + $provider = $c->get(IProvider::class); |
|
| 470 | + } else { |
|
| 471 | + $provider = null; |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + $userSession = new \OC\User\Session( |
|
| 475 | + $manager, |
|
| 476 | + $session, |
|
| 477 | + $timeFactory, |
|
| 478 | + $provider, |
|
| 479 | + $c->get(\OCP\IConfig::class), |
|
| 480 | + $c->get(ISecureRandom::class), |
|
| 481 | + $c->get('LockdownManager'), |
|
| 482 | + $c->get(LoggerInterface::class), |
|
| 483 | + $c->get(IEventDispatcher::class), |
|
| 484 | + ); |
|
| 485 | + /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */ |
|
| 486 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
| 487 | + \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 488 | + }); |
|
| 489 | + /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */ |
|
| 490 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 491 | + /** @var \OC\User\User $user */ |
|
| 492 | + \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
|
| 493 | + }); |
|
| 494 | + /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */ |
|
| 495 | + $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
| 496 | + /** @var \OC\User\User $user */ |
|
| 497 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
|
| 498 | + }); |
|
| 499 | + /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ |
|
| 500 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 501 | + /** @var \OC\User\User $user */ |
|
| 502 | + \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
|
| 503 | + }); |
|
| 504 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 505 | + /** @var \OC\User\User $user */ |
|
| 506 | + \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 507 | + }); |
|
| 508 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 509 | + /** @var \OC\User\User $user */ |
|
| 510 | + \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 511 | + }); |
|
| 512 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 513 | + \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 514 | + |
|
| 515 | + /** @var IEventDispatcher $dispatcher */ |
|
| 516 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 517 | + $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); |
|
| 518 | + }); |
|
| 519 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) { |
|
| 520 | + /** @var \OC\User\User $user */ |
|
| 521 | + \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]); |
|
| 522 | + |
|
| 523 | + /** @var IEventDispatcher $dispatcher */ |
|
| 524 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 525 | + $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin)); |
|
| 526 | + }); |
|
| 527 | + $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { |
|
| 528 | + /** @var IEventDispatcher $dispatcher */ |
|
| 529 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 530 | + $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); |
|
| 531 | + }); |
|
| 532 | + $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
| 533 | + /** @var \OC\User\User $user */ |
|
| 534 | + \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
|
| 535 | + |
|
| 536 | + /** @var IEventDispatcher $dispatcher */ |
|
| 537 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 538 | + $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); |
|
| 539 | + }); |
|
| 540 | + $userSession->listen('\OC\User', 'logout', function ($user) { |
|
| 541 | + \OC_Hook::emit('OC_User', 'logout', []); |
|
| 542 | + |
|
| 543 | + /** @var IEventDispatcher $dispatcher */ |
|
| 544 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 545 | + $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); |
|
| 546 | + }); |
|
| 547 | + $userSession->listen('\OC\User', 'postLogout', function ($user) { |
|
| 548 | + /** @var IEventDispatcher $dispatcher */ |
|
| 549 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 550 | + $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); |
|
| 551 | + }); |
|
| 552 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
| 553 | + /** @var \OC\User\User $user */ |
|
| 554 | + \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); |
|
| 555 | + }); |
|
| 556 | + return $userSession; |
|
| 557 | + }); |
|
| 558 | + $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
| 559 | + |
|
| 560 | + $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
| 561 | + |
|
| 562 | + $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class); |
|
| 563 | + |
|
| 564 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
| 565 | + |
|
| 566 | + $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
| 567 | + return new \OC\SystemConfig($config); |
|
| 568 | + }); |
|
| 569 | + |
|
| 570 | + $this->registerAlias(IAppConfig::class, \OC\AppConfig::class); |
|
| 571 | + $this->registerAlias(IUserConfig::class, \OC\Config\UserConfig::class); |
|
| 572 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
| 573 | + |
|
| 574 | + $this->registerService(IFactory::class, function (Server $c) { |
|
| 575 | + return new \OC\L10N\Factory( |
|
| 576 | + $c->get(\OCP\IConfig::class), |
|
| 577 | + $c->getRequest(), |
|
| 578 | + $c->get(IUserSession::class), |
|
| 579 | + $c->get(ICacheFactory::class), |
|
| 580 | + \OC::$SERVERROOT, |
|
| 581 | + $c->get(IAppManager::class), |
|
| 582 | + ); |
|
| 583 | + }); |
|
| 584 | + |
|
| 585 | + $this->registerAlias(IURLGenerator::class, URLGenerator::class); |
|
| 586 | + |
|
| 587 | + $this->registerService(ICache::class, function ($c) { |
|
| 588 | + return new Cache\File(); |
|
| 589 | + }); |
|
| 590 | + |
|
| 591 | + $this->registerService(Factory::class, function (Server $c) { |
|
| 592 | + $profiler = $c->get(IProfiler::class); |
|
| 593 | + $arrayCacheFactory = new \OC\Memcache\Factory(fn () => '', $c->get(LoggerInterface::class), |
|
| 594 | + $profiler, |
|
| 595 | + ArrayCache::class, |
|
| 596 | + ArrayCache::class, |
|
| 597 | + ArrayCache::class |
|
| 598 | + ); |
|
| 599 | + /** @var SystemConfig $config */ |
|
| 600 | + $config = $c->get(SystemConfig::class); |
|
| 601 | + /** @var ServerVersion $serverVersion */ |
|
| 602 | + $serverVersion = $c->get(ServerVersion::class); |
|
| 603 | + |
|
| 604 | + if ($config->getValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 605 | + $logQuery = $config->getValue('log_query'); |
|
| 606 | + $prefixClosure = function () use ($logQuery, $serverVersion): ?string { |
|
| 607 | + if (!$logQuery) { |
|
| 608 | + try { |
|
| 609 | + $v = \OCP\Server::get(IAppConfig::class)->getAppInstalledVersions(true); |
|
| 610 | + } catch (\Doctrine\DBAL\Exception $e) { |
|
| 611 | + // Database service probably unavailable |
|
| 612 | + // Probably related to https://github.com/nextcloud/server/issues/37424 |
|
| 613 | + return null; |
|
| 614 | + } |
|
| 615 | + } else { |
|
| 616 | + // If the log_query is enabled, we can not get the app versions |
|
| 617 | + // as that does a query, which will be logged and the logging |
|
| 618 | + // depends on redis and here we are back again in the same function. |
|
| 619 | + $v = [ |
|
| 620 | + 'log_query' => 'enabled', |
|
| 621 | + ]; |
|
| 622 | + } |
|
| 623 | + $v['core'] = implode(',', $serverVersion->getVersion()); |
|
| 624 | + $version = implode(',', array_keys($v)) . implode(',', $v); |
|
| 625 | + $instanceId = \OC_Util::getInstanceId(); |
|
| 626 | + $path = \OC::$SERVERROOT; |
|
| 627 | + return md5($instanceId . '-' . $version . '-' . $path); |
|
| 628 | + }; |
|
| 629 | + return new \OC\Memcache\Factory($prefixClosure, |
|
| 630 | + $c->get(LoggerInterface::class), |
|
| 631 | + $profiler, |
|
| 632 | + /** @psalm-taint-escape callable */ |
|
| 633 | + $config->getValue('memcache.local', null), |
|
| 634 | + /** @psalm-taint-escape callable */ |
|
| 635 | + $config->getValue('memcache.distributed', null), |
|
| 636 | + /** @psalm-taint-escape callable */ |
|
| 637 | + $config->getValue('memcache.locking', null), |
|
| 638 | + /** @psalm-taint-escape callable */ |
|
| 639 | + $config->getValue('redis_log_file') |
|
| 640 | + ); |
|
| 641 | + } |
|
| 642 | + return $arrayCacheFactory; |
|
| 643 | + }); |
|
| 644 | + $this->registerAlias(ICacheFactory::class, Factory::class); |
|
| 645 | + |
|
| 646 | + $this->registerService('RedisFactory', function (Server $c) { |
|
| 647 | + $systemConfig = $c->get(SystemConfig::class); |
|
| 648 | + return new RedisFactory($systemConfig, $c->get(IEventLogger::class)); |
|
| 649 | + }); |
|
| 650 | + |
|
| 651 | + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 652 | + $l10n = $this->get(IFactory::class)->get('lib'); |
|
| 653 | + return new \OC\Activity\Manager( |
|
| 654 | + $c->getRequest(), |
|
| 655 | + $c->get(IUserSession::class), |
|
| 656 | + $c->get(\OCP\IConfig::class), |
|
| 657 | + $c->get(IValidator::class), |
|
| 658 | + $c->get(IRichTextFormatter::class), |
|
| 659 | + $l10n |
|
| 660 | + ); |
|
| 661 | + }); |
|
| 662 | + |
|
| 663 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 664 | + return new \OC\Activity\EventMerger( |
|
| 665 | + $c->getL10N('lib') |
|
| 666 | + ); |
|
| 667 | + }); |
|
| 668 | + $this->registerAlias(IValidator::class, Validator::class); |
|
| 669 | + |
|
| 670 | + $this->registerService(AvatarManager::class, function (Server $c) { |
|
| 671 | + return new AvatarManager( |
|
| 672 | + $c->get(IUserSession::class), |
|
| 673 | + $c->get(\OC\User\Manager::class), |
|
| 674 | + $c->getAppDataDir('avatar'), |
|
| 675 | + $c->getL10N('lib'), |
|
| 676 | + $c->get(LoggerInterface::class), |
|
| 677 | + $c->get(\OCP\IConfig::class), |
|
| 678 | + $c->get(IAccountManager::class), |
|
| 679 | + $c->get(KnownUserService::class) |
|
| 680 | + ); |
|
| 681 | + }); |
|
| 682 | + |
|
| 683 | + $this->registerAlias(IAvatarManager::class, AvatarManager::class); |
|
| 684 | + |
|
| 685 | + $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
| 686 | + $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
|
| 687 | + $this->registerAlias(\OCP\Support\Subscription\IAssertion::class, \OC\Support\Subscription\Assertion::class); |
|
| 688 | + |
|
| 689 | + /** Only used by the PsrLoggerAdapter should not be used by apps */ |
|
| 690 | + $this->registerService(\OC\Log::class, function (Server $c) { |
|
| 691 | + $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file'); |
|
| 692 | + $factory = new LogFactory($c, $this->get(SystemConfig::class)); |
|
| 693 | + $logger = $factory->get($logType); |
|
| 694 | + $registry = $c->get(\OCP\Support\CrashReport\IRegistry::class); |
|
| 695 | + |
|
| 696 | + return new Log($logger, $this->get(SystemConfig::class), crashReporters: $registry); |
|
| 697 | + }); |
|
| 698 | + // PSR-3 logger |
|
| 699 | + $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); |
|
| 700 | + |
|
| 701 | + $this->registerService(ILogFactory::class, function (Server $c) { |
|
| 702 | + return new LogFactory($c, $this->get(SystemConfig::class)); |
|
| 703 | + }); |
|
| 704 | + |
|
| 705 | + $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class); |
|
| 706 | + |
|
| 707 | + $this->registerService(Router::class, function (Server $c) { |
|
| 708 | + $cacheFactory = $c->get(ICacheFactory::class); |
|
| 709 | + if ($cacheFactory->isLocalCacheAvailable()) { |
|
| 710 | + $router = $c->resolve(CachingRouter::class); |
|
| 711 | + } else { |
|
| 712 | + $router = $c->resolve(Router::class); |
|
| 713 | + } |
|
| 714 | + return $router; |
|
| 715 | + }); |
|
| 716 | + $this->registerAlias(IRouter::class, Router::class); |
|
| 717 | + |
|
| 718 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
| 719 | + $config = $c->get(\OCP\IConfig::class); |
|
| 720 | + if (ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === \OC\Memcache\Redis::class) { |
|
| 721 | + $backend = new \OC\Security\RateLimiting\Backend\MemoryCacheBackend( |
|
| 722 | + $c->get(AllConfig::class), |
|
| 723 | + $this->get(ICacheFactory::class), |
|
| 724 | + new \OC\AppFramework\Utility\TimeFactory() |
|
| 725 | + ); |
|
| 726 | + } else { |
|
| 727 | + $backend = new \OC\Security\RateLimiting\Backend\DatabaseBackend( |
|
| 728 | + $c->get(AllConfig::class), |
|
| 729 | + $c->get(IDBConnection::class), |
|
| 730 | + new \OC\AppFramework\Utility\TimeFactory() |
|
| 731 | + ); |
|
| 732 | + } |
|
| 733 | + |
|
| 734 | + return $backend; |
|
| 735 | + }); |
|
| 736 | + |
|
| 737 | + $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class); |
|
| 738 | + $this->registerAlias(\OCP\Security\IRemoteHostValidator::class, \OC\Security\RemoteHostValidator::class); |
|
| 739 | + $this->registerAlias(IVerificationToken::class, VerificationToken::class); |
|
| 740 | + |
|
| 741 | + $this->registerAlias(ICrypto::class, Crypto::class); |
|
| 742 | + |
|
| 743 | + $this->registerAlias(IHasher::class, Hasher::class); |
|
| 744 | + |
|
| 745 | + $this->registerAlias(ICredentialsManager::class, CredentialsManager::class); |
|
| 746 | + |
|
| 747 | + $this->registerAlias(IDBConnection::class, ConnectionAdapter::class); |
|
| 748 | + $this->registerService(Connection::class, function (Server $c) { |
|
| 749 | + $systemConfig = $c->get(SystemConfig::class); |
|
| 750 | + $factory = new \OC\DB\ConnectionFactory($systemConfig, $c->get(ICacheFactory::class)); |
|
| 751 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
| 752 | + if (!$factory->isValidType($type)) { |
|
| 753 | + throw new \OC\DatabaseException('Invalid database type'); |
|
| 754 | + } |
|
| 755 | + $connection = $factory->getConnection($type, []); |
|
| 756 | + return $connection; |
|
| 757 | + }); |
|
| 758 | + |
|
| 759 | + $this->registerAlias(ICertificateManager::class, CertificateManager::class); |
|
| 760 | + $this->registerAlias(IClientService::class, ClientService::class); |
|
| 761 | + $this->registerService(NegativeDnsCache::class, function (ContainerInterface $c) { |
|
| 762 | + return new NegativeDnsCache( |
|
| 763 | + $c->get(ICacheFactory::class), |
|
| 764 | + ); |
|
| 765 | + }); |
|
| 766 | + $this->registerDeprecatedAlias('HttpClientService', IClientService::class); |
|
| 767 | + $this->registerService(IEventLogger::class, function (ContainerInterface $c) { |
|
| 768 | + return new EventLogger($c->get(SystemConfig::class), $c->get(LoggerInterface::class), $c->get(Log::class)); |
|
| 769 | + }); |
|
| 770 | + |
|
| 771 | + $this->registerService(IQueryLogger::class, function (ContainerInterface $c) { |
|
| 772 | + $queryLogger = new QueryLogger(); |
|
| 773 | + if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
|
| 774 | + // In debug mode, module is being activated by default |
|
| 775 | + $queryLogger->activate(); |
|
| 776 | + } |
|
| 777 | + return $queryLogger; |
|
| 778 | + }); |
|
| 779 | + |
|
| 780 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
| 781 | + $this->registerAlias(IDateTimeZone::class, DateTimeZone::class); |
|
| 782 | + |
|
| 783 | + $this->registerService(IDateTimeFormatter::class, function (Server $c) { |
|
| 784 | + $language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null); |
|
| 785 | + |
|
| 786 | + return new DateTimeFormatter( |
|
| 787 | + $c->get(IDateTimeZone::class)->getTimeZone(), |
|
| 788 | + $c->getL10N('lib', $language) |
|
| 789 | + ); |
|
| 790 | + }); |
|
| 791 | + |
|
| 792 | + $this->registerService(IUserMountCache::class, function (ContainerInterface $c) { |
|
| 793 | + $mountCache = $c->get(UserMountCache::class); |
|
| 794 | + $listener = new UserMountCacheListener($mountCache); |
|
| 795 | + $listener->listen($c->get(IUserManager::class)); |
|
| 796 | + return $mountCache; |
|
| 797 | + }); |
|
| 798 | + |
|
| 799 | + $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) { |
|
| 800 | + $loader = $c->get(IStorageFactory::class); |
|
| 801 | + $mountCache = $c->get(IUserMountCache::class); |
|
| 802 | + $eventLogger = $c->get(IEventLogger::class); |
|
| 803 | + $manager = new MountProviderCollection($loader, $mountCache, $eventLogger); |
|
| 804 | + |
|
| 805 | + // builtin providers |
|
| 806 | + |
|
| 807 | + $config = $c->get(\OCP\IConfig::class); |
|
| 808 | + $logger = $c->get(LoggerInterface::class); |
|
| 809 | + $objectStoreConfig = $c->get(PrimaryObjectStoreConfig::class); |
|
| 810 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
| 811 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
| 812 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($objectStoreConfig)); |
|
| 813 | + $manager->registerRootProvider(new RootMountProvider($objectStoreConfig, $config)); |
|
| 814 | + $manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config)); |
|
| 815 | + |
|
| 816 | + return $manager; |
|
| 817 | + }); |
|
| 818 | + |
|
| 819 | + $this->registerService(IBus::class, function (ContainerInterface $c) { |
|
| 820 | + $busClass = $c->get(\OCP\IConfig::class)->getSystemValueString('commandbus'); |
|
| 821 | + if ($busClass) { |
|
| 822 | + [$app, $class] = explode('::', $busClass, 2); |
|
| 823 | + if ($c->get(IAppManager::class)->isEnabledForUser($app)) { |
|
| 824 | + $c->get(IAppManager::class)->loadApp($app); |
|
| 825 | + return $c->get($class); |
|
| 826 | + } else { |
|
| 827 | + throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
| 828 | + } |
|
| 829 | + } else { |
|
| 830 | + $jobList = $c->get(IJobList::class); |
|
| 831 | + return new CronBus($jobList); |
|
| 832 | + } |
|
| 833 | + }); |
|
| 834 | + $this->registerDeprecatedAlias('AsyncCommandBus', IBus::class); |
|
| 835 | + $this->registerAlias(ITrustedDomainHelper::class, TrustedDomainHelper::class); |
|
| 836 | + $this->registerAlias(IThrottler::class, Throttler::class); |
|
| 837 | + |
|
| 838 | + $this->registerService(\OC\Security\Bruteforce\Backend\IBackend::class, function ($c) { |
|
| 839 | + $config = $c->get(\OCP\IConfig::class); |
|
| 840 | + if (!$config->getSystemValueBool('auth.bruteforce.protection.force.database', false) |
|
| 841 | + && ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === \OC\Memcache\Redis::class) { |
|
| 842 | + $backend = $c->get(\OC\Security\Bruteforce\Backend\MemoryCacheBackend::class); |
|
| 843 | + } else { |
|
| 844 | + $backend = $c->get(\OC\Security\Bruteforce\Backend\DatabaseBackend::class); |
|
| 845 | + } |
|
| 846 | + |
|
| 847 | + return $backend; |
|
| 848 | + }); |
|
| 849 | + |
|
| 850 | + $this->registerDeprecatedAlias('IntegrityCodeChecker', Checker::class); |
|
| 851 | + $this->registerService(Checker::class, function (ContainerInterface $c) { |
|
| 852 | + // IConfig requires a working database. This code |
|
| 853 | + // might however be called when Nextcloud is not yet setup. |
|
| 854 | + if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 855 | + $config = $c->get(\OCP\IConfig::class); |
|
| 856 | + $appConfig = $c->get(\OCP\IAppConfig::class); |
|
| 857 | + } else { |
|
| 858 | + $config = null; |
|
| 859 | + $appConfig = null; |
|
| 860 | + } |
|
| 861 | + |
|
| 862 | + return new Checker( |
|
| 863 | + $c->get(ServerVersion::class), |
|
| 864 | + $c->get(EnvironmentHelper::class), |
|
| 865 | + new FileAccessHelper(), |
|
| 866 | + new AppLocator(), |
|
| 867 | + $config, |
|
| 868 | + $appConfig, |
|
| 869 | + $c->get(ICacheFactory::class), |
|
| 870 | + $c->get(IAppManager::class), |
|
| 871 | + $c->get(IMimeTypeDetector::class) |
|
| 872 | + ); |
|
| 873 | + }); |
|
| 874 | + $this->registerService(Request::class, function (ContainerInterface $c) { |
|
| 875 | + if (isset($this['urlParams'])) { |
|
| 876 | + $urlParams = $this['urlParams']; |
|
| 877 | + } else { |
|
| 878 | + $urlParams = []; |
|
| 879 | + } |
|
| 880 | + |
|
| 881 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
| 882 | + && in_array('fakeinput', stream_get_wrappers()) |
|
| 883 | + ) { |
|
| 884 | + $stream = 'fakeinput://data'; |
|
| 885 | + } else { |
|
| 886 | + $stream = 'php://input'; |
|
| 887 | + } |
|
| 888 | + |
|
| 889 | + return new Request( |
|
| 890 | + [ |
|
| 891 | + 'get' => $_GET, |
|
| 892 | + 'post' => $_POST, |
|
| 893 | + 'files' => $_FILES, |
|
| 894 | + 'server' => $_SERVER, |
|
| 895 | + 'env' => $_ENV, |
|
| 896 | + 'cookies' => $_COOKIE, |
|
| 897 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 898 | + ? $_SERVER['REQUEST_METHOD'] |
|
| 899 | + : '', |
|
| 900 | + 'urlParams' => $urlParams, |
|
| 901 | + ], |
|
| 902 | + $this->get(IRequestId::class), |
|
| 903 | + $this->get(\OCP\IConfig::class), |
|
| 904 | + $this->get(CsrfTokenManager::class), |
|
| 905 | + $stream |
|
| 906 | + ); |
|
| 907 | + }); |
|
| 908 | + $this->registerAlias(\OCP\IRequest::class, Request::class); |
|
| 909 | + |
|
| 910 | + $this->registerService(IRequestId::class, function (ContainerInterface $c): IRequestId { |
|
| 911 | + return new RequestId( |
|
| 912 | + $_SERVER['UNIQUE_ID'] ?? '', |
|
| 913 | + $this->get(ISecureRandom::class) |
|
| 914 | + ); |
|
| 915 | + }); |
|
| 916 | + |
|
| 917 | + $this->registerService(IMailer::class, function (Server $c) { |
|
| 918 | + return new Mailer( |
|
| 919 | + $c->get(\OCP\IConfig::class), |
|
| 920 | + $c->get(LoggerInterface::class), |
|
| 921 | + $c->get(Defaults::class), |
|
| 922 | + $c->get(IURLGenerator::class), |
|
| 923 | + $c->getL10N('lib'), |
|
| 924 | + $c->get(IEventDispatcher::class), |
|
| 925 | + $c->get(IFactory::class) |
|
| 926 | + ); |
|
| 927 | + }); |
|
| 928 | + |
|
| 929 | + /** @since 30.0.0 */ |
|
| 930 | + $this->registerAlias(\OCP\Mail\Provider\IManager::class, \OC\Mail\Provider\Manager::class); |
|
| 931 | + |
|
| 932 | + $this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) { |
|
| 933 | + $config = $c->get(\OCP\IConfig::class); |
|
| 934 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
| 935 | + if (is_null($factoryClass) || !class_exists($factoryClass)) { |
|
| 936 | + return new NullLDAPProviderFactory($this); |
|
| 937 | + } |
|
| 938 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
| 939 | + return new $factoryClass($this); |
|
| 940 | + }); |
|
| 941 | + $this->registerService(ILDAPProvider::class, function (ContainerInterface $c) { |
|
| 942 | + $factory = $c->get(ILDAPProviderFactory::class); |
|
| 943 | + return $factory->getLDAPProvider(); |
|
| 944 | + }); |
|
| 945 | + $this->registerService(ILockingProvider::class, function (ContainerInterface $c) { |
|
| 946 | + $ini = $c->get(IniGetWrapper::class); |
|
| 947 | + $config = $c->get(\OCP\IConfig::class); |
|
| 948 | + $ttl = $config->getSystemValueInt('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
| 949 | + if ($config->getSystemValueBool('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 950 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
| 951 | + $memcacheFactory = $c->get(ICacheFactory::class); |
|
| 952 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
| 953 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
| 954 | + $timeFactory = $c->get(ITimeFactory::class); |
|
| 955 | + return new MemcacheLockingProvider($memcache, $timeFactory, $ttl); |
|
| 956 | + } |
|
| 957 | + return new DBLockingProvider( |
|
| 958 | + $c->get(IDBConnection::class), |
|
| 959 | + new TimeFactory(), |
|
| 960 | + $ttl, |
|
| 961 | + !\OC::$CLI |
|
| 962 | + ); |
|
| 963 | + } |
|
| 964 | + return new NoopLockingProvider(); |
|
| 965 | + }); |
|
| 966 | + |
|
| 967 | + $this->registerService(ILockManager::class, function (Server $c): LockManager { |
|
| 968 | + return new LockManager(); |
|
| 969 | + }); |
|
| 970 | + |
|
| 971 | + $this->registerAlias(ILockdownManager::class, 'LockdownManager'); |
|
| 972 | + $this->registerService(SetupManager::class, function ($c) { |
|
| 973 | + // create the setupmanager through the mount manager to resolve the cyclic dependency |
|
| 974 | + return $c->get(\OC\Files\Mount\Manager::class)->getSetupManager(); |
|
| 975 | + }); |
|
| 976 | + $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class); |
|
| 977 | + |
|
| 978 | + $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) { |
|
| 979 | + return new \OC\Files\Type\Detection( |
|
| 980 | + $c->get(IURLGenerator::class), |
|
| 981 | + $c->get(LoggerInterface::class), |
|
| 982 | + \OC::$configDir, |
|
| 983 | + \OC::$SERVERROOT . '/resources/config/' |
|
| 984 | + ); |
|
| 985 | + }); |
|
| 986 | + |
|
| 987 | + $this->registerAlias(IMimeTypeLoader::class, Loader::class); |
|
| 988 | + $this->registerService(BundleFetcher::class, function () { |
|
| 989 | + return new BundleFetcher($this->getL10N('lib')); |
|
| 990 | + }); |
|
| 991 | + $this->registerAlias(\OCP\Notification\IManager::class, Manager::class); |
|
| 992 | + |
|
| 993 | + $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) { |
|
| 994 | + $manager = new CapabilitiesManager($c->get(LoggerInterface::class)); |
|
| 995 | + $manager->registerCapability(function () use ($c) { |
|
| 996 | + return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class)); |
|
| 997 | + }); |
|
| 998 | + $manager->registerCapability(function () use ($c) { |
|
| 999 | + return $c->get(\OC\Security\Bruteforce\Capabilities::class); |
|
| 1000 | + }); |
|
| 1001 | + return $manager; |
|
| 1002 | + }); |
|
| 1003 | + |
|
| 1004 | + $this->registerService(ICommentsManager::class, function (Server $c) { |
|
| 1005 | + $config = $c->get(\OCP\IConfig::class); |
|
| 1006 | + $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
| 1007 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
| 1008 | + $factory = new $factoryClass($this); |
|
| 1009 | + $manager = $factory->getManager(); |
|
| 1010 | + |
|
| 1011 | + $manager->registerDisplayNameResolver('user', function ($id) use ($c) { |
|
| 1012 | + $manager = $c->get(IUserManager::class); |
|
| 1013 | + $userDisplayName = $manager->getDisplayName($id); |
|
| 1014 | + if ($userDisplayName === null) { |
|
| 1015 | + $l = $c->get(IFactory::class)->get('core'); |
|
| 1016 | + return $l->t('Unknown account'); |
|
| 1017 | + } |
|
| 1018 | + return $userDisplayName; |
|
| 1019 | + }); |
|
| 1020 | + |
|
| 1021 | + return $manager; |
|
| 1022 | + }); |
|
| 1023 | + |
|
| 1024 | + $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults'); |
|
| 1025 | + $this->registerService('ThemingDefaults', function (Server $c) { |
|
| 1026 | + try { |
|
| 1027 | + $classExists = class_exists('OCA\Theming\ThemingDefaults'); |
|
| 1028 | + } catch (\OCP\AutoloadNotAllowedException $e) { |
|
| 1029 | + // App disabled or in maintenance mode |
|
| 1030 | + $classExists = false; |
|
| 1031 | + } |
|
| 1032 | + |
|
| 1033 | + if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValueBool('installed', false) && $c->get(IAppManager::class)->isEnabledForAnyone('theming') && $c->get(TrustedDomainHelper::class)->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
| 1034 | + $backgroundService = new BackgroundService( |
|
| 1035 | + $c->get(IRootFolder::class), |
|
| 1036 | + $c->getAppDataDir('theming'), |
|
| 1037 | + $c->get(IAppConfig::class), |
|
| 1038 | + $c->get(\OCP\IConfig::class), |
|
| 1039 | + $c->get(ISession::class)->get('user_id'), |
|
| 1040 | + ); |
|
| 1041 | + $imageManager = new ImageManager( |
|
| 1042 | + $c->get(\OCP\IConfig::class), |
|
| 1043 | + $c->getAppDataDir('theming'), |
|
| 1044 | + $c->get(IURLGenerator::class), |
|
| 1045 | + $c->get(ICacheFactory::class), |
|
| 1046 | + $c->get(LoggerInterface::class), |
|
| 1047 | + $c->get(ITempManager::class), |
|
| 1048 | + $backgroundService, |
|
| 1049 | + ); |
|
| 1050 | + return new ThemingDefaults( |
|
| 1051 | + $c->get(\OCP\IConfig::class), |
|
| 1052 | + $c->get(\OCP\IAppConfig::class), |
|
| 1053 | + $c->getL10N('theming'), |
|
| 1054 | + $c->get(IUserSession::class), |
|
| 1055 | + $c->get(IURLGenerator::class), |
|
| 1056 | + $c->get(ICacheFactory::class), |
|
| 1057 | + new Util($c->get(ServerVersion::class), $c->get(\OCP\IConfig::class), $this->get(IAppManager::class), $c->getAppDataDir('theming'), $imageManager), |
|
| 1058 | + $imageManager, |
|
| 1059 | + $c->get(IAppManager::class), |
|
| 1060 | + $c->get(INavigationManager::class), |
|
| 1061 | + $backgroundService, |
|
| 1062 | + ); |
|
| 1063 | + } |
|
| 1064 | + return new \OC_Defaults(); |
|
| 1065 | + }); |
|
| 1066 | + $this->registerService(JSCombiner::class, function (Server $c) { |
|
| 1067 | + return new JSCombiner( |
|
| 1068 | + $c->getAppDataDir('js'), |
|
| 1069 | + $c->get(IURLGenerator::class), |
|
| 1070 | + $this->get(ICacheFactory::class), |
|
| 1071 | + $c->get(SystemConfig::class), |
|
| 1072 | + $c->get(LoggerInterface::class) |
|
| 1073 | + ); |
|
| 1074 | + }); |
|
| 1075 | + $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
|
| 1076 | + |
|
| 1077 | + $this->registerService('CryptoWrapper', function (ContainerInterface $c) { |
|
| 1078 | + // FIXME: Instantiated here due to cyclic dependency |
|
| 1079 | + $request = new Request( |
|
| 1080 | + [ |
|
| 1081 | + 'get' => $_GET, |
|
| 1082 | + 'post' => $_POST, |
|
| 1083 | + 'files' => $_FILES, |
|
| 1084 | + 'server' => $_SERVER, |
|
| 1085 | + 'env' => $_ENV, |
|
| 1086 | + 'cookies' => $_COOKIE, |
|
| 1087 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 1088 | + ? $_SERVER['REQUEST_METHOD'] |
|
| 1089 | + : null, |
|
| 1090 | + ], |
|
| 1091 | + $c->get(IRequestId::class), |
|
| 1092 | + $c->get(\OCP\IConfig::class) |
|
| 1093 | + ); |
|
| 1094 | + |
|
| 1095 | + return new CryptoWrapper( |
|
| 1096 | + $c->get(ICrypto::class), |
|
| 1097 | + $c->get(ISecureRandom::class), |
|
| 1098 | + $request |
|
| 1099 | + ); |
|
| 1100 | + }); |
|
| 1101 | + $this->registerService(SessionStorage::class, function (ContainerInterface $c) { |
|
| 1102 | + return new SessionStorage($c->get(ISession::class)); |
|
| 1103 | + }); |
|
| 1104 | + $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); |
|
| 1105 | + |
|
| 1106 | + $this->registerService(IProviderFactory::class, function (ContainerInterface $c) { |
|
| 1107 | + $config = $c->get(\OCP\IConfig::class); |
|
| 1108 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
| 1109 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
| 1110 | + return $c->get($factoryClass); |
|
| 1111 | + }); |
|
| 1112 | + |
|
| 1113 | + $this->registerAlias(\OCP\Share\IManager::class, \OC\Share20\Manager::class); |
|
| 1114 | + |
|
| 1115 | + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) { |
|
| 1116 | + $instance = new Collaboration\Collaborators\Search($c); |
|
| 1117 | + |
|
| 1118 | + // register default plugins |
|
| 1119 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
| 1120 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
| 1121 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
| 1122 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
| 1123 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
| 1124 | + |
|
| 1125 | + return $instance; |
|
| 1126 | + }); |
|
| 1127 | + $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
| 1128 | + |
|
| 1129 | + $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
| 1130 | + |
|
| 1131 | + $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class); |
|
| 1132 | + $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
| 1133 | + |
|
| 1134 | + $this->registerAlias(IReferenceManager::class, ReferenceManager::class); |
|
| 1135 | + $this->registerAlias(ITeamManager::class, TeamManager::class); |
|
| 1136 | + |
|
| 1137 | + $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class); |
|
| 1138 | + $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class); |
|
| 1139 | + $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) { |
|
| 1140 | + return new \OC\Files\AppData\Factory( |
|
| 1141 | + $c->get(IRootFolder::class), |
|
| 1142 | + $c->get(SystemConfig::class) |
|
| 1143 | + ); |
|
| 1144 | + }); |
|
| 1145 | + |
|
| 1146 | + $this->registerService('LockdownManager', function (ContainerInterface $c) { |
|
| 1147 | + return new LockdownManager(function () use ($c) { |
|
| 1148 | + return $c->get(ISession::class); |
|
| 1149 | + }); |
|
| 1150 | + }); |
|
| 1151 | + |
|
| 1152 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) { |
|
| 1153 | + return new DiscoveryService( |
|
| 1154 | + $c->get(ICacheFactory::class), |
|
| 1155 | + $c->get(IClientService::class) |
|
| 1156 | + ); |
|
| 1157 | + }); |
|
| 1158 | + $this->registerAlias(IOCMDiscoveryService::class, OCMDiscoveryService::class); |
|
| 1159 | + |
|
| 1160 | + $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) { |
|
| 1161 | + return new CloudIdManager( |
|
| 1162 | + $c->get(\OCP\Contacts\IManager::class), |
|
| 1163 | + $c->get(IURLGenerator::class), |
|
| 1164 | + $c->get(IUserManager::class), |
|
| 1165 | + $c->get(ICacheFactory::class), |
|
| 1166 | + $c->get(IEventDispatcher::class), |
|
| 1167 | + ); |
|
| 1168 | + }); |
|
| 1169 | + |
|
| 1170 | + $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class); |
|
| 1171 | + $this->registerAlias(ICloudFederationProviderManager::class, CloudFederationProviderManager::class); |
|
| 1172 | + $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
| 1173 | + return new CloudFederationFactory(); |
|
| 1174 | + }); |
|
| 1175 | 1175 | |
| 1176 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 1176 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 1177 | 1177 | |
| 1178 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 1179 | - $this->registerAlias(\Psr\Clock\ClockInterface::class, \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 1178 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 1179 | + $this->registerAlias(\Psr\Clock\ClockInterface::class, \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 1180 | 1180 | |
| 1181 | - $this->registerService(Defaults::class, function (Server $c) { |
|
| 1182 | - return new Defaults( |
|
| 1183 | - $c->get('ThemingDefaults') |
|
| 1184 | - ); |
|
| 1185 | - }); |
|
| 1181 | + $this->registerService(Defaults::class, function (Server $c) { |
|
| 1182 | + return new Defaults( |
|
| 1183 | + $c->get('ThemingDefaults') |
|
| 1184 | + ); |
|
| 1185 | + }); |
|
| 1186 | 1186 | |
| 1187 | - $this->registerService(\OCP\ISession::class, function (ContainerInterface $c) { |
|
| 1188 | - return $c->get(\OCP\IUserSession::class)->getSession(); |
|
| 1189 | - }, false); |
|
| 1187 | + $this->registerService(\OCP\ISession::class, function (ContainerInterface $c) { |
|
| 1188 | + return $c->get(\OCP\IUserSession::class)->getSession(); |
|
| 1189 | + }, false); |
|
| 1190 | 1190 | |
| 1191 | - $this->registerService(IShareHelper::class, function (ContainerInterface $c) { |
|
| 1192 | - return new ShareHelper( |
|
| 1193 | - $c->get(\OCP\Share\IManager::class) |
|
| 1194 | - ); |
|
| 1195 | - }); |
|
| 1191 | + $this->registerService(IShareHelper::class, function (ContainerInterface $c) { |
|
| 1192 | + return new ShareHelper( |
|
| 1193 | + $c->get(\OCP\Share\IManager::class) |
|
| 1194 | + ); |
|
| 1195 | + }); |
|
| 1196 | 1196 | |
| 1197 | - $this->registerService(Installer::class, function (ContainerInterface $c) { |
|
| 1198 | - return new Installer( |
|
| 1199 | - $c->get(AppFetcher::class), |
|
| 1200 | - $c->get(IClientService::class), |
|
| 1201 | - $c->get(ITempManager::class), |
|
| 1202 | - $c->get(LoggerInterface::class), |
|
| 1203 | - $c->get(\OCP\IConfig::class), |
|
| 1204 | - \OC::$CLI |
|
| 1205 | - ); |
|
| 1206 | - }); |
|
| 1197 | + $this->registerService(Installer::class, function (ContainerInterface $c) { |
|
| 1198 | + return new Installer( |
|
| 1199 | + $c->get(AppFetcher::class), |
|
| 1200 | + $c->get(IClientService::class), |
|
| 1201 | + $c->get(ITempManager::class), |
|
| 1202 | + $c->get(LoggerInterface::class), |
|
| 1203 | + $c->get(\OCP\IConfig::class), |
|
| 1204 | + \OC::$CLI |
|
| 1205 | + ); |
|
| 1206 | + }); |
|
| 1207 | 1207 | |
| 1208 | - $this->registerService(IApiFactory::class, function (ContainerInterface $c) { |
|
| 1209 | - return new ApiFactory($c->get(IClientService::class)); |
|
| 1210 | - }); |
|
| 1208 | + $this->registerService(IApiFactory::class, function (ContainerInterface $c) { |
|
| 1209 | + return new ApiFactory($c->get(IClientService::class)); |
|
| 1210 | + }); |
|
| 1211 | 1211 | |
| 1212 | - $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) { |
|
| 1213 | - $memcacheFactory = $c->get(ICacheFactory::class); |
|
| 1214 | - return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class)); |
|
| 1215 | - }); |
|
| 1212 | + $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) { |
|
| 1213 | + $memcacheFactory = $c->get(ICacheFactory::class); |
|
| 1214 | + return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class)); |
|
| 1215 | + }); |
|
| 1216 | 1216 | |
| 1217 | - $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
| 1218 | - $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
| 1217 | + $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
| 1218 | + $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
| 1219 | 1219 | |
| 1220 | - $this->registerAlias(IStorageFactory::class, StorageFactory::class); |
|
| 1220 | + $this->registerAlias(IStorageFactory::class, StorageFactory::class); |
|
| 1221 | 1221 | |
| 1222 | - $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class); |
|
| 1222 | + $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class); |
|
| 1223 | 1223 | |
| 1224 | - $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
| 1225 | - $this->registerAlias(IFilesMetadataManager::class, FilesMetadataManager::class); |
|
| 1224 | + $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
| 1225 | + $this->registerAlias(IFilesMetadataManager::class, FilesMetadataManager::class); |
|
| 1226 | 1226 | |
| 1227 | - $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
| 1227 | + $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
| 1228 | 1228 | |
| 1229 | - $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
| 1229 | + $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
| 1230 | 1230 | |
| 1231 | - $this->registerAlias(\OCP\IEmojiHelper::class, \OC\EmojiHelper::class); |
|
| 1231 | + $this->registerAlias(\OCP\IEmojiHelper::class, \OC\EmojiHelper::class); |
|
| 1232 | 1232 | |
| 1233 | - $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class); |
|
| 1233 | + $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class); |
|
| 1234 | 1234 | |
| 1235 | - $this->registerAlias(IBroker::class, Broker::class); |
|
| 1235 | + $this->registerAlias(IBroker::class, Broker::class); |
|
| 1236 | 1236 | |
| 1237 | - $this->registerAlias(\OCP\Files\AppData\IAppDataFactory::class, \OC\Files\AppData\Factory::class); |
|
| 1237 | + $this->registerAlias(\OCP\Files\AppData\IAppDataFactory::class, \OC\Files\AppData\Factory::class); |
|
| 1238 | 1238 | |
| 1239 | - $this->registerAlias(\OCP\Files\IFilenameValidator::class, \OC\Files\FilenameValidator::class); |
|
| 1239 | + $this->registerAlias(\OCP\Files\IFilenameValidator::class, \OC\Files\FilenameValidator::class); |
|
| 1240 | 1240 | |
| 1241 | - $this->registerAlias(IBinaryFinder::class, BinaryFinder::class); |
|
| 1241 | + $this->registerAlias(IBinaryFinder::class, BinaryFinder::class); |
|
| 1242 | 1242 | |
| 1243 | - $this->registerAlias(\OCP\Share\IPublicShareTemplateFactory::class, \OC\Share20\PublicShareTemplateFactory::class); |
|
| 1243 | + $this->registerAlias(\OCP\Share\IPublicShareTemplateFactory::class, \OC\Share20\PublicShareTemplateFactory::class); |
|
| 1244 | 1244 | |
| 1245 | - $this->registerAlias(ITranslationManager::class, TranslationManager::class); |
|
| 1245 | + $this->registerAlias(ITranslationManager::class, TranslationManager::class); |
|
| 1246 | 1246 | |
| 1247 | - $this->registerAlias(IConversionManager::class, ConversionManager::class); |
|
| 1247 | + $this->registerAlias(IConversionManager::class, ConversionManager::class); |
|
| 1248 | 1248 | |
| 1249 | - $this->registerAlias(ISpeechToTextManager::class, SpeechToTextManager::class); |
|
| 1249 | + $this->registerAlias(ISpeechToTextManager::class, SpeechToTextManager::class); |
|
| 1250 | 1250 | |
| 1251 | - $this->registerAlias(IEventSourceFactory::class, EventSourceFactory::class); |
|
| 1251 | + $this->registerAlias(IEventSourceFactory::class, EventSourceFactory::class); |
|
| 1252 | 1252 | |
| 1253 | - $this->registerAlias(\OCP\TextProcessing\IManager::class, \OC\TextProcessing\Manager::class); |
|
| 1253 | + $this->registerAlias(\OCP\TextProcessing\IManager::class, \OC\TextProcessing\Manager::class); |
|
| 1254 | 1254 | |
| 1255 | - $this->registerAlias(\OCP\TextToImage\IManager::class, \OC\TextToImage\Manager::class); |
|
| 1255 | + $this->registerAlias(\OCP\TextToImage\IManager::class, \OC\TextToImage\Manager::class); |
|
| 1256 | 1256 | |
| 1257 | - $this->registerAlias(ILimiter::class, Limiter::class); |
|
| 1257 | + $this->registerAlias(ILimiter::class, Limiter::class); |
|
| 1258 | 1258 | |
| 1259 | - $this->registerAlias(IPhoneNumberUtil::class, PhoneNumberUtil::class); |
|
| 1259 | + $this->registerAlias(IPhoneNumberUtil::class, PhoneNumberUtil::class); |
|
| 1260 | 1260 | |
| 1261 | - $this->registerAlias(ICapabilityAwareOCMProvider::class, OCMProvider::class); |
|
| 1262 | - $this->registerDeprecatedAlias(IOCMProvider::class, OCMProvider::class); |
|
| 1261 | + $this->registerAlias(ICapabilityAwareOCMProvider::class, OCMProvider::class); |
|
| 1262 | + $this->registerDeprecatedAlias(IOCMProvider::class, OCMProvider::class); |
|
| 1263 | 1263 | |
| 1264 | - $this->registerAlias(ISetupCheckManager::class, SetupCheckManager::class); |
|
| 1264 | + $this->registerAlias(ISetupCheckManager::class, SetupCheckManager::class); |
|
| 1265 | 1265 | |
| 1266 | - $this->registerAlias(IProfileManager::class, ProfileManager::class); |
|
| 1266 | + $this->registerAlias(IProfileManager::class, ProfileManager::class); |
|
| 1267 | 1267 | |
| 1268 | - $this->registerAlias(IAvailabilityCoordinator::class, AvailabilityCoordinator::class); |
|
| 1268 | + $this->registerAlias(IAvailabilityCoordinator::class, AvailabilityCoordinator::class); |
|
| 1269 | 1269 | |
| 1270 | - $this->registerAlias(IDeclarativeManager::class, DeclarativeManager::class); |
|
| 1270 | + $this->registerAlias(IDeclarativeManager::class, DeclarativeManager::class); |
|
| 1271 | 1271 | |
| 1272 | - $this->registerAlias(\OCP\TaskProcessing\IManager::class, \OC\TaskProcessing\Manager::class); |
|
| 1272 | + $this->registerAlias(\OCP\TaskProcessing\IManager::class, \OC\TaskProcessing\Manager::class); |
|
| 1273 | 1273 | |
| 1274 | - $this->registerAlias(IRemoteAddress::class, RemoteAddress::class); |
|
| 1274 | + $this->registerAlias(IRemoteAddress::class, RemoteAddress::class); |
|
| 1275 | 1275 | |
| 1276 | - $this->registerAlias(\OCP\Security\Ip\IFactory::class, \OC\Security\Ip\Factory::class); |
|
| 1277 | - |
|
| 1278 | - $this->registerAlias(IRichTextFormatter::class, \OC\RichObjectStrings\RichTextFormatter::class); |
|
| 1279 | - |
|
| 1280 | - $this->registerAlias(ISignatureManager::class, SignatureManager::class); |
|
| 1281 | - |
|
| 1282 | - $this->connectDispatcher(); |
|
| 1283 | - } |
|
| 1284 | - |
|
| 1285 | - public function boot() { |
|
| 1286 | - /** @var HookConnector $hookConnector */ |
|
| 1287 | - $hookConnector = $this->get(HookConnector::class); |
|
| 1288 | - $hookConnector->viewToNode(); |
|
| 1289 | - } |
|
| 1290 | - |
|
| 1291 | - private function connectDispatcher(): void { |
|
| 1292 | - /** @var IEventDispatcher $eventDispatcher */ |
|
| 1293 | - $eventDispatcher = $this->get(IEventDispatcher::class); |
|
| 1294 | - $eventDispatcher->addServiceListener(LoginFailed::class, LoginFailedListener::class); |
|
| 1295 | - $eventDispatcher->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class); |
|
| 1296 | - $eventDispatcher->addServiceListener(UserChangedEvent::class, UserChangedListener::class); |
|
| 1297 | - $eventDispatcher->addServiceListener(BeforeUserDeletedEvent::class, BeforeUserDeletedListener::class); |
|
| 1298 | - |
|
| 1299 | - FilesMetadataManager::loadListeners($eventDispatcher); |
|
| 1300 | - GenerateBlurhashMetadata::loadListeners($eventDispatcher); |
|
| 1301 | - } |
|
| 1302 | - |
|
| 1303 | - /** |
|
| 1304 | - * @return \OCP\Contacts\IManager |
|
| 1305 | - * @deprecated 20.0.0 |
|
| 1306 | - */ |
|
| 1307 | - public function getContactsManager() { |
|
| 1308 | - return $this->get(\OCP\Contacts\IManager::class); |
|
| 1309 | - } |
|
| 1310 | - |
|
| 1311 | - /** |
|
| 1312 | - * @return \OC\Encryption\Manager |
|
| 1313 | - * @deprecated 20.0.0 |
|
| 1314 | - */ |
|
| 1315 | - public function getEncryptionManager() { |
|
| 1316 | - return $this->get(\OCP\Encryption\IManager::class); |
|
| 1317 | - } |
|
| 1318 | - |
|
| 1319 | - /** |
|
| 1320 | - * @return \OC\Encryption\File |
|
| 1321 | - * @deprecated 20.0.0 |
|
| 1322 | - */ |
|
| 1323 | - public function getEncryptionFilesHelper() { |
|
| 1324 | - return $this->get(IFile::class); |
|
| 1325 | - } |
|
| 1326 | - |
|
| 1327 | - /** |
|
| 1328 | - * The current request object holding all information about the request |
|
| 1329 | - * currently being processed is returned from this method. |
|
| 1330 | - * In case the current execution was not initiated by a web request null is returned |
|
| 1331 | - * |
|
| 1332 | - * @return \OCP\IRequest |
|
| 1333 | - * @deprecated 20.0.0 |
|
| 1334 | - */ |
|
| 1335 | - public function getRequest() { |
|
| 1336 | - return $this->get(IRequest::class); |
|
| 1337 | - } |
|
| 1338 | - |
|
| 1339 | - /** |
|
| 1340 | - * Returns the root folder of ownCloud's data directory |
|
| 1341 | - * |
|
| 1342 | - * @return IRootFolder |
|
| 1343 | - * @deprecated 20.0.0 |
|
| 1344 | - */ |
|
| 1345 | - public function getRootFolder() { |
|
| 1346 | - return $this->get(IRootFolder::class); |
|
| 1347 | - } |
|
| 1348 | - |
|
| 1349 | - /** |
|
| 1350 | - * Returns the root folder of ownCloud's data directory |
|
| 1351 | - * This is the lazy variant so this gets only initialized once it |
|
| 1352 | - * is actually used. |
|
| 1353 | - * |
|
| 1354 | - * @return IRootFolder |
|
| 1355 | - * @deprecated 20.0.0 |
|
| 1356 | - */ |
|
| 1357 | - public function getLazyRootFolder() { |
|
| 1358 | - return $this->get(IRootFolder::class); |
|
| 1359 | - } |
|
| 1360 | - |
|
| 1361 | - /** |
|
| 1362 | - * Returns a view to ownCloud's files folder |
|
| 1363 | - * |
|
| 1364 | - * @param string $userId user ID |
|
| 1365 | - * @return \OCP\Files\Folder|null |
|
| 1366 | - * @deprecated 20.0.0 |
|
| 1367 | - */ |
|
| 1368 | - public function getUserFolder($userId = null) { |
|
| 1369 | - if ($userId === null) { |
|
| 1370 | - $user = $this->get(IUserSession::class)->getUser(); |
|
| 1371 | - if (!$user) { |
|
| 1372 | - return null; |
|
| 1373 | - } |
|
| 1374 | - $userId = $user->getUID(); |
|
| 1375 | - } |
|
| 1376 | - $root = $this->get(IRootFolder::class); |
|
| 1377 | - return $root->getUserFolder($userId); |
|
| 1378 | - } |
|
| 1379 | - |
|
| 1380 | - /** |
|
| 1381 | - * @return \OC\User\Manager |
|
| 1382 | - * @deprecated 20.0.0 |
|
| 1383 | - */ |
|
| 1384 | - public function getUserManager() { |
|
| 1385 | - return $this->get(IUserManager::class); |
|
| 1386 | - } |
|
| 1387 | - |
|
| 1388 | - /** |
|
| 1389 | - * @return \OC\Group\Manager |
|
| 1390 | - * @deprecated 20.0.0 |
|
| 1391 | - */ |
|
| 1392 | - public function getGroupManager() { |
|
| 1393 | - return $this->get(IGroupManager::class); |
|
| 1394 | - } |
|
| 1395 | - |
|
| 1396 | - /** |
|
| 1397 | - * @return \OC\User\Session |
|
| 1398 | - * @deprecated 20.0.0 |
|
| 1399 | - */ |
|
| 1400 | - public function getUserSession() { |
|
| 1401 | - return $this->get(IUserSession::class); |
|
| 1402 | - } |
|
| 1403 | - |
|
| 1404 | - /** |
|
| 1405 | - * @return \OCP\ISession |
|
| 1406 | - * @deprecated 20.0.0 |
|
| 1407 | - */ |
|
| 1408 | - public function getSession() { |
|
| 1409 | - return $this->get(Session::class)->getSession(); |
|
| 1410 | - } |
|
| 1411 | - |
|
| 1412 | - /** |
|
| 1413 | - * @param \OCP\ISession $session |
|
| 1414 | - * @return void |
|
| 1415 | - */ |
|
| 1416 | - public function setSession(\OCP\ISession $session) { |
|
| 1417 | - $this->get(SessionStorage::class)->setSession($session); |
|
| 1418 | - $this->get(Session::class)->setSession($session); |
|
| 1419 | - $this->get(Store::class)->setSession($session); |
|
| 1420 | - } |
|
| 1421 | - |
|
| 1422 | - /** |
|
| 1423 | - * @return \OCP\IConfig |
|
| 1424 | - * @deprecated 20.0.0 |
|
| 1425 | - */ |
|
| 1426 | - public function getConfig() { |
|
| 1427 | - return $this->get(AllConfig::class); |
|
| 1428 | - } |
|
| 1429 | - |
|
| 1430 | - /** |
|
| 1431 | - * @return \OC\SystemConfig |
|
| 1432 | - * @deprecated 20.0.0 |
|
| 1433 | - */ |
|
| 1434 | - public function getSystemConfig() { |
|
| 1435 | - return $this->get(SystemConfig::class); |
|
| 1436 | - } |
|
| 1437 | - |
|
| 1438 | - /** |
|
| 1439 | - * @return IFactory |
|
| 1440 | - * @deprecated 20.0.0 |
|
| 1441 | - */ |
|
| 1442 | - public function getL10NFactory() { |
|
| 1443 | - return $this->get(IFactory::class); |
|
| 1444 | - } |
|
| 1445 | - |
|
| 1446 | - /** |
|
| 1447 | - * get an L10N instance |
|
| 1448 | - * |
|
| 1449 | - * @param string $app appid |
|
| 1450 | - * @param string $lang |
|
| 1451 | - * @return IL10N |
|
| 1452 | - * @deprecated 20.0.0 use DI of {@see IL10N} or {@see IFactory} instead, or {@see \OCP\Util::getL10N()} as a last resort |
|
| 1453 | - */ |
|
| 1454 | - public function getL10N($app, $lang = null) { |
|
| 1455 | - return $this->get(IFactory::class)->get($app, $lang); |
|
| 1456 | - } |
|
| 1457 | - |
|
| 1458 | - /** |
|
| 1459 | - * @return IURLGenerator |
|
| 1460 | - * @deprecated 20.0.0 |
|
| 1461 | - */ |
|
| 1462 | - public function getURLGenerator() { |
|
| 1463 | - return $this->get(IURLGenerator::class); |
|
| 1464 | - } |
|
| 1465 | - |
|
| 1466 | - /** |
|
| 1467 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
| 1468 | - * getMemCacheFactory() instead. |
|
| 1469 | - * |
|
| 1470 | - * @return ICache |
|
| 1471 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
| 1472 | - */ |
|
| 1473 | - public function getCache() { |
|
| 1474 | - return $this->get(ICache::class); |
|
| 1475 | - } |
|
| 1476 | - |
|
| 1477 | - /** |
|
| 1478 | - * Returns an \OCP\CacheFactory instance |
|
| 1479 | - * |
|
| 1480 | - * @return \OCP\ICacheFactory |
|
| 1481 | - * @deprecated 20.0.0 |
|
| 1482 | - */ |
|
| 1483 | - public function getMemCacheFactory() { |
|
| 1484 | - return $this->get(ICacheFactory::class); |
|
| 1485 | - } |
|
| 1486 | - |
|
| 1487 | - /** |
|
| 1488 | - * Returns the current session |
|
| 1489 | - * |
|
| 1490 | - * @return \OCP\IDBConnection |
|
| 1491 | - * @deprecated 20.0.0 |
|
| 1492 | - */ |
|
| 1493 | - public function getDatabaseConnection() { |
|
| 1494 | - return $this->get(IDBConnection::class); |
|
| 1495 | - } |
|
| 1496 | - |
|
| 1497 | - /** |
|
| 1498 | - * Returns the activity manager |
|
| 1499 | - * |
|
| 1500 | - * @return \OCP\Activity\IManager |
|
| 1501 | - * @deprecated 20.0.0 |
|
| 1502 | - */ |
|
| 1503 | - public function getActivityManager() { |
|
| 1504 | - return $this->get(\OCP\Activity\IManager::class); |
|
| 1505 | - } |
|
| 1506 | - |
|
| 1507 | - /** |
|
| 1508 | - * Returns an job list for controlling background jobs |
|
| 1509 | - * |
|
| 1510 | - * @return IJobList |
|
| 1511 | - * @deprecated 20.0.0 |
|
| 1512 | - */ |
|
| 1513 | - public function getJobList() { |
|
| 1514 | - return $this->get(IJobList::class); |
|
| 1515 | - } |
|
| 1516 | - |
|
| 1517 | - /** |
|
| 1518 | - * Returns a SecureRandom instance |
|
| 1519 | - * |
|
| 1520 | - * @return \OCP\Security\ISecureRandom |
|
| 1521 | - * @deprecated 20.0.0 |
|
| 1522 | - */ |
|
| 1523 | - public function getSecureRandom() { |
|
| 1524 | - return $this->get(ISecureRandom::class); |
|
| 1525 | - } |
|
| 1526 | - |
|
| 1527 | - /** |
|
| 1528 | - * Returns a Crypto instance |
|
| 1529 | - * |
|
| 1530 | - * @return ICrypto |
|
| 1531 | - * @deprecated 20.0.0 |
|
| 1532 | - */ |
|
| 1533 | - public function getCrypto() { |
|
| 1534 | - return $this->get(ICrypto::class); |
|
| 1535 | - } |
|
| 1536 | - |
|
| 1537 | - /** |
|
| 1538 | - * Returns a Hasher instance |
|
| 1539 | - * |
|
| 1540 | - * @return IHasher |
|
| 1541 | - * @deprecated 20.0.0 |
|
| 1542 | - */ |
|
| 1543 | - public function getHasher() { |
|
| 1544 | - return $this->get(IHasher::class); |
|
| 1545 | - } |
|
| 1546 | - |
|
| 1547 | - /** |
|
| 1548 | - * Get the certificate manager |
|
| 1549 | - * |
|
| 1550 | - * @return \OCP\ICertificateManager |
|
| 1551 | - */ |
|
| 1552 | - public function getCertificateManager() { |
|
| 1553 | - return $this->get(ICertificateManager::class); |
|
| 1554 | - } |
|
| 1555 | - |
|
| 1556 | - /** |
|
| 1557 | - * Get the manager for temporary files and folders |
|
| 1558 | - * |
|
| 1559 | - * @return \OCP\ITempManager |
|
| 1560 | - * @deprecated 20.0.0 |
|
| 1561 | - */ |
|
| 1562 | - public function getTempManager() { |
|
| 1563 | - return $this->get(ITempManager::class); |
|
| 1564 | - } |
|
| 1565 | - |
|
| 1566 | - /** |
|
| 1567 | - * Get the app manager |
|
| 1568 | - * |
|
| 1569 | - * @return \OCP\App\IAppManager |
|
| 1570 | - * @deprecated 20.0.0 |
|
| 1571 | - */ |
|
| 1572 | - public function getAppManager() { |
|
| 1573 | - return $this->get(IAppManager::class); |
|
| 1574 | - } |
|
| 1575 | - |
|
| 1576 | - /** |
|
| 1577 | - * Creates a new mailer |
|
| 1578 | - * |
|
| 1579 | - * @return IMailer |
|
| 1580 | - * @deprecated 20.0.0 |
|
| 1581 | - */ |
|
| 1582 | - public function getMailer() { |
|
| 1583 | - return $this->get(IMailer::class); |
|
| 1584 | - } |
|
| 1585 | - |
|
| 1586 | - /** |
|
| 1587 | - * Get the webroot |
|
| 1588 | - * |
|
| 1589 | - * @return string |
|
| 1590 | - * @deprecated 20.0.0 |
|
| 1591 | - */ |
|
| 1592 | - public function getWebRoot() { |
|
| 1593 | - return $this->webRoot; |
|
| 1594 | - } |
|
| 1595 | - |
|
| 1596 | - /** |
|
| 1597 | - * Get the locking provider |
|
| 1598 | - * |
|
| 1599 | - * @return ILockingProvider |
|
| 1600 | - * @since 8.1.0 |
|
| 1601 | - * @deprecated 20.0.0 |
|
| 1602 | - */ |
|
| 1603 | - public function getLockingProvider() { |
|
| 1604 | - return $this->get(ILockingProvider::class); |
|
| 1605 | - } |
|
| 1606 | - |
|
| 1607 | - /** |
|
| 1608 | - * Get the MimeTypeDetector |
|
| 1609 | - * |
|
| 1610 | - * @return IMimeTypeDetector |
|
| 1611 | - * @deprecated 20.0.0 |
|
| 1612 | - */ |
|
| 1613 | - public function getMimeTypeDetector() { |
|
| 1614 | - return $this->get(IMimeTypeDetector::class); |
|
| 1615 | - } |
|
| 1616 | - |
|
| 1617 | - /** |
|
| 1618 | - * Get the MimeTypeLoader |
|
| 1619 | - * |
|
| 1620 | - * @return IMimeTypeLoader |
|
| 1621 | - * @deprecated 20.0.0 |
|
| 1622 | - */ |
|
| 1623 | - public function getMimeTypeLoader() { |
|
| 1624 | - return $this->get(IMimeTypeLoader::class); |
|
| 1625 | - } |
|
| 1626 | - |
|
| 1627 | - /** |
|
| 1628 | - * Get the Notification Manager |
|
| 1629 | - * |
|
| 1630 | - * @return \OCP\Notification\IManager |
|
| 1631 | - * @since 8.2.0 |
|
| 1632 | - * @deprecated 20.0.0 |
|
| 1633 | - */ |
|
| 1634 | - public function getNotificationManager() { |
|
| 1635 | - return $this->get(\OCP\Notification\IManager::class); |
|
| 1636 | - } |
|
| 1637 | - |
|
| 1638 | - /** |
|
| 1639 | - * @return \OCA\Theming\ThemingDefaults |
|
| 1640 | - * @deprecated 20.0.0 |
|
| 1641 | - */ |
|
| 1642 | - public function getThemingDefaults() { |
|
| 1643 | - return $this->get('ThemingDefaults'); |
|
| 1644 | - } |
|
| 1645 | - |
|
| 1646 | - /** |
|
| 1647 | - * @return \OC\IntegrityCheck\Checker |
|
| 1648 | - * @deprecated 20.0.0 |
|
| 1649 | - */ |
|
| 1650 | - public function getIntegrityCodeChecker() { |
|
| 1651 | - return $this->get('IntegrityCodeChecker'); |
|
| 1652 | - } |
|
| 1653 | - |
|
| 1654 | - /** |
|
| 1655 | - * @return CsrfTokenManager |
|
| 1656 | - * @deprecated 20.0.0 |
|
| 1657 | - */ |
|
| 1658 | - public function getCsrfTokenManager() { |
|
| 1659 | - return $this->get(CsrfTokenManager::class); |
|
| 1660 | - } |
|
| 1661 | - |
|
| 1662 | - /** |
|
| 1663 | - * @return ContentSecurityPolicyNonceManager |
|
| 1664 | - * @deprecated 20.0.0 |
|
| 1665 | - */ |
|
| 1666 | - public function getContentSecurityPolicyNonceManager() { |
|
| 1667 | - return $this->get(ContentSecurityPolicyNonceManager::class); |
|
| 1668 | - } |
|
| 1669 | - |
|
| 1670 | - /** |
|
| 1671 | - * @return \OCP\Settings\IManager |
|
| 1672 | - * @deprecated 20.0.0 |
|
| 1673 | - */ |
|
| 1674 | - public function getSettingsManager() { |
|
| 1675 | - return $this->get(\OC\Settings\Manager::class); |
|
| 1676 | - } |
|
| 1677 | - |
|
| 1678 | - /** |
|
| 1679 | - * @return \OCP\Files\IAppData |
|
| 1680 | - * @deprecated 20.0.0 Use get(\OCP\Files\AppData\IAppDataFactory::class)->get($app) instead |
|
| 1681 | - */ |
|
| 1682 | - public function getAppDataDir($app) { |
|
| 1683 | - $factory = $this->get(\OC\Files\AppData\Factory::class); |
|
| 1684 | - return $factory->get($app); |
|
| 1685 | - } |
|
| 1686 | - |
|
| 1687 | - /** |
|
| 1688 | - * @return \OCP\Federation\ICloudIdManager |
|
| 1689 | - * @deprecated 20.0.0 |
|
| 1690 | - */ |
|
| 1691 | - public function getCloudIdManager() { |
|
| 1692 | - return $this->get(ICloudIdManager::class); |
|
| 1693 | - } |
|
| 1276 | + $this->registerAlias(\OCP\Security\Ip\IFactory::class, \OC\Security\Ip\Factory::class); |
|
| 1277 | + |
|
| 1278 | + $this->registerAlias(IRichTextFormatter::class, \OC\RichObjectStrings\RichTextFormatter::class); |
|
| 1279 | + |
|
| 1280 | + $this->registerAlias(ISignatureManager::class, SignatureManager::class); |
|
| 1281 | + |
|
| 1282 | + $this->connectDispatcher(); |
|
| 1283 | + } |
|
| 1284 | + |
|
| 1285 | + public function boot() { |
|
| 1286 | + /** @var HookConnector $hookConnector */ |
|
| 1287 | + $hookConnector = $this->get(HookConnector::class); |
|
| 1288 | + $hookConnector->viewToNode(); |
|
| 1289 | + } |
|
| 1290 | + |
|
| 1291 | + private function connectDispatcher(): void { |
|
| 1292 | + /** @var IEventDispatcher $eventDispatcher */ |
|
| 1293 | + $eventDispatcher = $this->get(IEventDispatcher::class); |
|
| 1294 | + $eventDispatcher->addServiceListener(LoginFailed::class, LoginFailedListener::class); |
|
| 1295 | + $eventDispatcher->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class); |
|
| 1296 | + $eventDispatcher->addServiceListener(UserChangedEvent::class, UserChangedListener::class); |
|
| 1297 | + $eventDispatcher->addServiceListener(BeforeUserDeletedEvent::class, BeforeUserDeletedListener::class); |
|
| 1298 | + |
|
| 1299 | + FilesMetadataManager::loadListeners($eventDispatcher); |
|
| 1300 | + GenerateBlurhashMetadata::loadListeners($eventDispatcher); |
|
| 1301 | + } |
|
| 1302 | + |
|
| 1303 | + /** |
|
| 1304 | + * @return \OCP\Contacts\IManager |
|
| 1305 | + * @deprecated 20.0.0 |
|
| 1306 | + */ |
|
| 1307 | + public function getContactsManager() { |
|
| 1308 | + return $this->get(\OCP\Contacts\IManager::class); |
|
| 1309 | + } |
|
| 1310 | + |
|
| 1311 | + /** |
|
| 1312 | + * @return \OC\Encryption\Manager |
|
| 1313 | + * @deprecated 20.0.0 |
|
| 1314 | + */ |
|
| 1315 | + public function getEncryptionManager() { |
|
| 1316 | + return $this->get(\OCP\Encryption\IManager::class); |
|
| 1317 | + } |
|
| 1318 | + |
|
| 1319 | + /** |
|
| 1320 | + * @return \OC\Encryption\File |
|
| 1321 | + * @deprecated 20.0.0 |
|
| 1322 | + */ |
|
| 1323 | + public function getEncryptionFilesHelper() { |
|
| 1324 | + return $this->get(IFile::class); |
|
| 1325 | + } |
|
| 1326 | + |
|
| 1327 | + /** |
|
| 1328 | + * The current request object holding all information about the request |
|
| 1329 | + * currently being processed is returned from this method. |
|
| 1330 | + * In case the current execution was not initiated by a web request null is returned |
|
| 1331 | + * |
|
| 1332 | + * @return \OCP\IRequest |
|
| 1333 | + * @deprecated 20.0.0 |
|
| 1334 | + */ |
|
| 1335 | + public function getRequest() { |
|
| 1336 | + return $this->get(IRequest::class); |
|
| 1337 | + } |
|
| 1338 | + |
|
| 1339 | + /** |
|
| 1340 | + * Returns the root folder of ownCloud's data directory |
|
| 1341 | + * |
|
| 1342 | + * @return IRootFolder |
|
| 1343 | + * @deprecated 20.0.0 |
|
| 1344 | + */ |
|
| 1345 | + public function getRootFolder() { |
|
| 1346 | + return $this->get(IRootFolder::class); |
|
| 1347 | + } |
|
| 1348 | + |
|
| 1349 | + /** |
|
| 1350 | + * Returns the root folder of ownCloud's data directory |
|
| 1351 | + * This is the lazy variant so this gets only initialized once it |
|
| 1352 | + * is actually used. |
|
| 1353 | + * |
|
| 1354 | + * @return IRootFolder |
|
| 1355 | + * @deprecated 20.0.0 |
|
| 1356 | + */ |
|
| 1357 | + public function getLazyRootFolder() { |
|
| 1358 | + return $this->get(IRootFolder::class); |
|
| 1359 | + } |
|
| 1360 | + |
|
| 1361 | + /** |
|
| 1362 | + * Returns a view to ownCloud's files folder |
|
| 1363 | + * |
|
| 1364 | + * @param string $userId user ID |
|
| 1365 | + * @return \OCP\Files\Folder|null |
|
| 1366 | + * @deprecated 20.0.0 |
|
| 1367 | + */ |
|
| 1368 | + public function getUserFolder($userId = null) { |
|
| 1369 | + if ($userId === null) { |
|
| 1370 | + $user = $this->get(IUserSession::class)->getUser(); |
|
| 1371 | + if (!$user) { |
|
| 1372 | + return null; |
|
| 1373 | + } |
|
| 1374 | + $userId = $user->getUID(); |
|
| 1375 | + } |
|
| 1376 | + $root = $this->get(IRootFolder::class); |
|
| 1377 | + return $root->getUserFolder($userId); |
|
| 1378 | + } |
|
| 1379 | + |
|
| 1380 | + /** |
|
| 1381 | + * @return \OC\User\Manager |
|
| 1382 | + * @deprecated 20.0.0 |
|
| 1383 | + */ |
|
| 1384 | + public function getUserManager() { |
|
| 1385 | + return $this->get(IUserManager::class); |
|
| 1386 | + } |
|
| 1387 | + |
|
| 1388 | + /** |
|
| 1389 | + * @return \OC\Group\Manager |
|
| 1390 | + * @deprecated 20.0.0 |
|
| 1391 | + */ |
|
| 1392 | + public function getGroupManager() { |
|
| 1393 | + return $this->get(IGroupManager::class); |
|
| 1394 | + } |
|
| 1395 | + |
|
| 1396 | + /** |
|
| 1397 | + * @return \OC\User\Session |
|
| 1398 | + * @deprecated 20.0.0 |
|
| 1399 | + */ |
|
| 1400 | + public function getUserSession() { |
|
| 1401 | + return $this->get(IUserSession::class); |
|
| 1402 | + } |
|
| 1403 | + |
|
| 1404 | + /** |
|
| 1405 | + * @return \OCP\ISession |
|
| 1406 | + * @deprecated 20.0.0 |
|
| 1407 | + */ |
|
| 1408 | + public function getSession() { |
|
| 1409 | + return $this->get(Session::class)->getSession(); |
|
| 1410 | + } |
|
| 1411 | + |
|
| 1412 | + /** |
|
| 1413 | + * @param \OCP\ISession $session |
|
| 1414 | + * @return void |
|
| 1415 | + */ |
|
| 1416 | + public function setSession(\OCP\ISession $session) { |
|
| 1417 | + $this->get(SessionStorage::class)->setSession($session); |
|
| 1418 | + $this->get(Session::class)->setSession($session); |
|
| 1419 | + $this->get(Store::class)->setSession($session); |
|
| 1420 | + } |
|
| 1421 | + |
|
| 1422 | + /** |
|
| 1423 | + * @return \OCP\IConfig |
|
| 1424 | + * @deprecated 20.0.0 |
|
| 1425 | + */ |
|
| 1426 | + public function getConfig() { |
|
| 1427 | + return $this->get(AllConfig::class); |
|
| 1428 | + } |
|
| 1429 | + |
|
| 1430 | + /** |
|
| 1431 | + * @return \OC\SystemConfig |
|
| 1432 | + * @deprecated 20.0.0 |
|
| 1433 | + */ |
|
| 1434 | + public function getSystemConfig() { |
|
| 1435 | + return $this->get(SystemConfig::class); |
|
| 1436 | + } |
|
| 1437 | + |
|
| 1438 | + /** |
|
| 1439 | + * @return IFactory |
|
| 1440 | + * @deprecated 20.0.0 |
|
| 1441 | + */ |
|
| 1442 | + public function getL10NFactory() { |
|
| 1443 | + return $this->get(IFactory::class); |
|
| 1444 | + } |
|
| 1445 | + |
|
| 1446 | + /** |
|
| 1447 | + * get an L10N instance |
|
| 1448 | + * |
|
| 1449 | + * @param string $app appid |
|
| 1450 | + * @param string $lang |
|
| 1451 | + * @return IL10N |
|
| 1452 | + * @deprecated 20.0.0 use DI of {@see IL10N} or {@see IFactory} instead, or {@see \OCP\Util::getL10N()} as a last resort |
|
| 1453 | + */ |
|
| 1454 | + public function getL10N($app, $lang = null) { |
|
| 1455 | + return $this->get(IFactory::class)->get($app, $lang); |
|
| 1456 | + } |
|
| 1457 | + |
|
| 1458 | + /** |
|
| 1459 | + * @return IURLGenerator |
|
| 1460 | + * @deprecated 20.0.0 |
|
| 1461 | + */ |
|
| 1462 | + public function getURLGenerator() { |
|
| 1463 | + return $this->get(IURLGenerator::class); |
|
| 1464 | + } |
|
| 1465 | + |
|
| 1466 | + /** |
|
| 1467 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
| 1468 | + * getMemCacheFactory() instead. |
|
| 1469 | + * |
|
| 1470 | + * @return ICache |
|
| 1471 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
| 1472 | + */ |
|
| 1473 | + public function getCache() { |
|
| 1474 | + return $this->get(ICache::class); |
|
| 1475 | + } |
|
| 1476 | + |
|
| 1477 | + /** |
|
| 1478 | + * Returns an \OCP\CacheFactory instance |
|
| 1479 | + * |
|
| 1480 | + * @return \OCP\ICacheFactory |
|
| 1481 | + * @deprecated 20.0.0 |
|
| 1482 | + */ |
|
| 1483 | + public function getMemCacheFactory() { |
|
| 1484 | + return $this->get(ICacheFactory::class); |
|
| 1485 | + } |
|
| 1486 | + |
|
| 1487 | + /** |
|
| 1488 | + * Returns the current session |
|
| 1489 | + * |
|
| 1490 | + * @return \OCP\IDBConnection |
|
| 1491 | + * @deprecated 20.0.0 |
|
| 1492 | + */ |
|
| 1493 | + public function getDatabaseConnection() { |
|
| 1494 | + return $this->get(IDBConnection::class); |
|
| 1495 | + } |
|
| 1496 | + |
|
| 1497 | + /** |
|
| 1498 | + * Returns the activity manager |
|
| 1499 | + * |
|
| 1500 | + * @return \OCP\Activity\IManager |
|
| 1501 | + * @deprecated 20.0.0 |
|
| 1502 | + */ |
|
| 1503 | + public function getActivityManager() { |
|
| 1504 | + return $this->get(\OCP\Activity\IManager::class); |
|
| 1505 | + } |
|
| 1506 | + |
|
| 1507 | + /** |
|
| 1508 | + * Returns an job list for controlling background jobs |
|
| 1509 | + * |
|
| 1510 | + * @return IJobList |
|
| 1511 | + * @deprecated 20.0.0 |
|
| 1512 | + */ |
|
| 1513 | + public function getJobList() { |
|
| 1514 | + return $this->get(IJobList::class); |
|
| 1515 | + } |
|
| 1516 | + |
|
| 1517 | + /** |
|
| 1518 | + * Returns a SecureRandom instance |
|
| 1519 | + * |
|
| 1520 | + * @return \OCP\Security\ISecureRandom |
|
| 1521 | + * @deprecated 20.0.0 |
|
| 1522 | + */ |
|
| 1523 | + public function getSecureRandom() { |
|
| 1524 | + return $this->get(ISecureRandom::class); |
|
| 1525 | + } |
|
| 1526 | + |
|
| 1527 | + /** |
|
| 1528 | + * Returns a Crypto instance |
|
| 1529 | + * |
|
| 1530 | + * @return ICrypto |
|
| 1531 | + * @deprecated 20.0.0 |
|
| 1532 | + */ |
|
| 1533 | + public function getCrypto() { |
|
| 1534 | + return $this->get(ICrypto::class); |
|
| 1535 | + } |
|
| 1536 | + |
|
| 1537 | + /** |
|
| 1538 | + * Returns a Hasher instance |
|
| 1539 | + * |
|
| 1540 | + * @return IHasher |
|
| 1541 | + * @deprecated 20.0.0 |
|
| 1542 | + */ |
|
| 1543 | + public function getHasher() { |
|
| 1544 | + return $this->get(IHasher::class); |
|
| 1545 | + } |
|
| 1546 | + |
|
| 1547 | + /** |
|
| 1548 | + * Get the certificate manager |
|
| 1549 | + * |
|
| 1550 | + * @return \OCP\ICertificateManager |
|
| 1551 | + */ |
|
| 1552 | + public function getCertificateManager() { |
|
| 1553 | + return $this->get(ICertificateManager::class); |
|
| 1554 | + } |
|
| 1555 | + |
|
| 1556 | + /** |
|
| 1557 | + * Get the manager for temporary files and folders |
|
| 1558 | + * |
|
| 1559 | + * @return \OCP\ITempManager |
|
| 1560 | + * @deprecated 20.0.0 |
|
| 1561 | + */ |
|
| 1562 | + public function getTempManager() { |
|
| 1563 | + return $this->get(ITempManager::class); |
|
| 1564 | + } |
|
| 1565 | + |
|
| 1566 | + /** |
|
| 1567 | + * Get the app manager |
|
| 1568 | + * |
|
| 1569 | + * @return \OCP\App\IAppManager |
|
| 1570 | + * @deprecated 20.0.0 |
|
| 1571 | + */ |
|
| 1572 | + public function getAppManager() { |
|
| 1573 | + return $this->get(IAppManager::class); |
|
| 1574 | + } |
|
| 1575 | + |
|
| 1576 | + /** |
|
| 1577 | + * Creates a new mailer |
|
| 1578 | + * |
|
| 1579 | + * @return IMailer |
|
| 1580 | + * @deprecated 20.0.0 |
|
| 1581 | + */ |
|
| 1582 | + public function getMailer() { |
|
| 1583 | + return $this->get(IMailer::class); |
|
| 1584 | + } |
|
| 1585 | + |
|
| 1586 | + /** |
|
| 1587 | + * Get the webroot |
|
| 1588 | + * |
|
| 1589 | + * @return string |
|
| 1590 | + * @deprecated 20.0.0 |
|
| 1591 | + */ |
|
| 1592 | + public function getWebRoot() { |
|
| 1593 | + return $this->webRoot; |
|
| 1594 | + } |
|
| 1595 | + |
|
| 1596 | + /** |
|
| 1597 | + * Get the locking provider |
|
| 1598 | + * |
|
| 1599 | + * @return ILockingProvider |
|
| 1600 | + * @since 8.1.0 |
|
| 1601 | + * @deprecated 20.0.0 |
|
| 1602 | + */ |
|
| 1603 | + public function getLockingProvider() { |
|
| 1604 | + return $this->get(ILockingProvider::class); |
|
| 1605 | + } |
|
| 1606 | + |
|
| 1607 | + /** |
|
| 1608 | + * Get the MimeTypeDetector |
|
| 1609 | + * |
|
| 1610 | + * @return IMimeTypeDetector |
|
| 1611 | + * @deprecated 20.0.0 |
|
| 1612 | + */ |
|
| 1613 | + public function getMimeTypeDetector() { |
|
| 1614 | + return $this->get(IMimeTypeDetector::class); |
|
| 1615 | + } |
|
| 1616 | + |
|
| 1617 | + /** |
|
| 1618 | + * Get the MimeTypeLoader |
|
| 1619 | + * |
|
| 1620 | + * @return IMimeTypeLoader |
|
| 1621 | + * @deprecated 20.0.0 |
|
| 1622 | + */ |
|
| 1623 | + public function getMimeTypeLoader() { |
|
| 1624 | + return $this->get(IMimeTypeLoader::class); |
|
| 1625 | + } |
|
| 1626 | + |
|
| 1627 | + /** |
|
| 1628 | + * Get the Notification Manager |
|
| 1629 | + * |
|
| 1630 | + * @return \OCP\Notification\IManager |
|
| 1631 | + * @since 8.2.0 |
|
| 1632 | + * @deprecated 20.0.0 |
|
| 1633 | + */ |
|
| 1634 | + public function getNotificationManager() { |
|
| 1635 | + return $this->get(\OCP\Notification\IManager::class); |
|
| 1636 | + } |
|
| 1637 | + |
|
| 1638 | + /** |
|
| 1639 | + * @return \OCA\Theming\ThemingDefaults |
|
| 1640 | + * @deprecated 20.0.0 |
|
| 1641 | + */ |
|
| 1642 | + public function getThemingDefaults() { |
|
| 1643 | + return $this->get('ThemingDefaults'); |
|
| 1644 | + } |
|
| 1645 | + |
|
| 1646 | + /** |
|
| 1647 | + * @return \OC\IntegrityCheck\Checker |
|
| 1648 | + * @deprecated 20.0.0 |
|
| 1649 | + */ |
|
| 1650 | + public function getIntegrityCodeChecker() { |
|
| 1651 | + return $this->get('IntegrityCodeChecker'); |
|
| 1652 | + } |
|
| 1653 | + |
|
| 1654 | + /** |
|
| 1655 | + * @return CsrfTokenManager |
|
| 1656 | + * @deprecated 20.0.0 |
|
| 1657 | + */ |
|
| 1658 | + public function getCsrfTokenManager() { |
|
| 1659 | + return $this->get(CsrfTokenManager::class); |
|
| 1660 | + } |
|
| 1661 | + |
|
| 1662 | + /** |
|
| 1663 | + * @return ContentSecurityPolicyNonceManager |
|
| 1664 | + * @deprecated 20.0.0 |
|
| 1665 | + */ |
|
| 1666 | + public function getContentSecurityPolicyNonceManager() { |
|
| 1667 | + return $this->get(ContentSecurityPolicyNonceManager::class); |
|
| 1668 | + } |
|
| 1669 | + |
|
| 1670 | + /** |
|
| 1671 | + * @return \OCP\Settings\IManager |
|
| 1672 | + * @deprecated 20.0.0 |
|
| 1673 | + */ |
|
| 1674 | + public function getSettingsManager() { |
|
| 1675 | + return $this->get(\OC\Settings\Manager::class); |
|
| 1676 | + } |
|
| 1677 | + |
|
| 1678 | + /** |
|
| 1679 | + * @return \OCP\Files\IAppData |
|
| 1680 | + * @deprecated 20.0.0 Use get(\OCP\Files\AppData\IAppDataFactory::class)->get($app) instead |
|
| 1681 | + */ |
|
| 1682 | + public function getAppDataDir($app) { |
|
| 1683 | + $factory = $this->get(\OC\Files\AppData\Factory::class); |
|
| 1684 | + return $factory->get($app); |
|
| 1685 | + } |
|
| 1686 | + |
|
| 1687 | + /** |
|
| 1688 | + * @return \OCP\Federation\ICloudIdManager |
|
| 1689 | + * @deprecated 20.0.0 |
|
| 1690 | + */ |
|
| 1691 | + public function getCloudIdManager() { |
|
| 1692 | + return $this->get(ICloudIdManager::class); |
|
| 1693 | + } |
|
| 1694 | 1694 | } |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | $this->registerParameter('isCLI', \OC::$CLI); |
| 265 | 265 | $this->registerParameter('serverRoot', \OC::$SERVERROOT); |
| 266 | 266 | |
| 267 | - $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
| 267 | + $this->registerService(ContainerInterface::class, function(ContainerInterface $c) { |
|
| 268 | 268 | return $c; |
| 269 | 269 | }); |
| 270 | 270 | $this->registerDeprecatedAlias(\OCP\IServerContainer::class, ContainerInterface::class); |
@@ -283,11 +283,11 @@ discard block |
||
| 283 | 283 | |
| 284 | 284 | $this->registerAlias(IActionFactory::class, ActionFactory::class); |
| 285 | 285 | |
| 286 | - $this->registerService(View::class, function (Server $c) { |
|
| 286 | + $this->registerService(View::class, function(Server $c) { |
|
| 287 | 287 | return new View(); |
| 288 | 288 | }, false); |
| 289 | 289 | |
| 290 | - $this->registerService(IPreview::class, function (ContainerInterface $c) { |
|
| 290 | + $this->registerService(IPreview::class, function(ContainerInterface $c) { |
|
| 291 | 291 | return new PreviewManager( |
| 292 | 292 | $c->get(\OCP\IConfig::class), |
| 293 | 293 | $c->get(IRootFolder::class), |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | }); |
| 307 | 307 | $this->registerAlias(IMimeIconProvider::class, MimeIconProvider::class); |
| 308 | 308 | |
| 309 | - $this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) { |
|
| 309 | + $this->registerService(\OC\Preview\Watcher::class, function(ContainerInterface $c) { |
|
| 310 | 310 | return new \OC\Preview\Watcher( |
| 311 | 311 | new \OC\Preview\Storage\Root( |
| 312 | 312 | $c->get(IRootFolder::class), |
@@ -315,11 +315,11 @@ discard block |
||
| 315 | 315 | ); |
| 316 | 316 | }); |
| 317 | 317 | |
| 318 | - $this->registerService(IProfiler::class, function (Server $c) { |
|
| 318 | + $this->registerService(IProfiler::class, function(Server $c) { |
|
| 319 | 319 | return new Profiler($c->get(SystemConfig::class)); |
| 320 | 320 | }); |
| 321 | 321 | |
| 322 | - $this->registerService(Encryption\Manager::class, function (Server $c): Encryption\Manager { |
|
| 322 | + $this->registerService(Encryption\Manager::class, function(Server $c): Encryption\Manager { |
|
| 323 | 323 | $view = new View(); |
| 324 | 324 | $util = new Encryption\Util( |
| 325 | 325 | $view, |
@@ -338,7 +338,7 @@ discard block |
||
| 338 | 338 | }); |
| 339 | 339 | $this->registerAlias(\OCP\Encryption\IManager::class, Encryption\Manager::class); |
| 340 | 340 | |
| 341 | - $this->registerService(IFile::class, function (ContainerInterface $c) { |
|
| 341 | + $this->registerService(IFile::class, function(ContainerInterface $c) { |
|
| 342 | 342 | $util = new Encryption\Util( |
| 343 | 343 | new View(), |
| 344 | 344 | $c->get(IUserManager::class), |
@@ -352,7 +352,7 @@ discard block |
||
| 352 | 352 | ); |
| 353 | 353 | }); |
| 354 | 354 | |
| 355 | - $this->registerService(IStorage::class, function (ContainerInterface $c) { |
|
| 355 | + $this->registerService(IStorage::class, function(ContainerInterface $c) { |
|
| 356 | 356 | $view = new View(); |
| 357 | 357 | $util = new Encryption\Util( |
| 358 | 358 | $view, |
@@ -371,23 +371,23 @@ discard block |
||
| 371 | 371 | |
| 372 | 372 | $this->registerAlias(\OCP\ITagManager::class, TagManager::class); |
| 373 | 373 | |
| 374 | - $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) { |
|
| 374 | + $this->registerService('SystemTagManagerFactory', function(ContainerInterface $c) { |
|
| 375 | 375 | /** @var \OCP\IConfig $config */ |
| 376 | 376 | $config = $c->get(\OCP\IConfig::class); |
| 377 | 377 | $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
| 378 | 378 | return new $factoryClass($this); |
| 379 | 379 | }); |
| 380 | - $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) { |
|
| 380 | + $this->registerService(ISystemTagManager::class, function(ContainerInterface $c) { |
|
| 381 | 381 | return $c->get('SystemTagManagerFactory')->getManager(); |
| 382 | 382 | }); |
| 383 | 383 | /** @deprecated 19.0.0 */ |
| 384 | 384 | $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); |
| 385 | 385 | |
| 386 | - $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) { |
|
| 386 | + $this->registerService(ISystemTagObjectMapper::class, function(ContainerInterface $c) { |
|
| 387 | 387 | return $c->get('SystemTagManagerFactory')->getObjectMapper(); |
| 388 | 388 | }); |
| 389 | 389 | $this->registerAlias(IFileAccess::class, FileAccess::class); |
| 390 | - $this->registerService('RootFolder', function (ContainerInterface $c) { |
|
| 390 | + $this->registerService('RootFolder', function(ContainerInterface $c) { |
|
| 391 | 391 | $manager = \OC\Files\Filesystem::getMountManager(); |
| 392 | 392 | $view = new View(); |
| 393 | 393 | /** @var IUserSession $userSession */ |
@@ -412,7 +412,7 @@ discard block |
||
| 412 | 412 | |
| 413 | 413 | return $root; |
| 414 | 414 | }); |
| 415 | - $this->registerService(HookConnector::class, function (ContainerInterface $c) { |
|
| 415 | + $this->registerService(HookConnector::class, function(ContainerInterface $c) { |
|
| 416 | 416 | return new HookConnector( |
| 417 | 417 | $c->get(IRootFolder::class), |
| 418 | 418 | new View(), |
@@ -421,19 +421,19 @@ discard block |
||
| 421 | 421 | ); |
| 422 | 422 | }); |
| 423 | 423 | |
| 424 | - $this->registerService(IRootFolder::class, function (ContainerInterface $c) { |
|
| 425 | - return new LazyRoot(function () use ($c) { |
|
| 424 | + $this->registerService(IRootFolder::class, function(ContainerInterface $c) { |
|
| 425 | + return new LazyRoot(function() use ($c) { |
|
| 426 | 426 | return $c->get('RootFolder'); |
| 427 | 427 | }); |
| 428 | 428 | }); |
| 429 | 429 | |
| 430 | 430 | $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
| 431 | 431 | |
| 432 | - $this->registerService(DisplayNameCache::class, function (ContainerInterface $c) { |
|
| 432 | + $this->registerService(DisplayNameCache::class, function(ContainerInterface $c) { |
|
| 433 | 433 | return $c->get(\OC\User\Manager::class)->getDisplayNameCache(); |
| 434 | 434 | }); |
| 435 | 435 | |
| 436 | - $this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) { |
|
| 436 | + $this->registerService(\OCP\IGroupManager::class, function(ContainerInterface $c) { |
|
| 437 | 437 | $groupManager = new \OC\Group\Manager( |
| 438 | 438 | $this->get(IUserManager::class), |
| 439 | 439 | $this->get(IEventDispatcher::class), |
@@ -444,7 +444,7 @@ discard block |
||
| 444 | 444 | return $groupManager; |
| 445 | 445 | }); |
| 446 | 446 | |
| 447 | - $this->registerService(Store::class, function (ContainerInterface $c) { |
|
| 447 | + $this->registerService(Store::class, function(ContainerInterface $c) { |
|
| 448 | 448 | $session = $c->get(ISession::class); |
| 449 | 449 | if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
| 450 | 450 | $tokenProvider = $c->get(IProvider::class); |
@@ -459,7 +459,7 @@ discard block |
||
| 459 | 459 | $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
| 460 | 460 | $this->registerAlias(OCPIProvider::class, Authentication\Token\Manager::class); |
| 461 | 461 | |
| 462 | - $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
| 462 | + $this->registerService(\OC\User\Session::class, function(Server $c) { |
|
| 463 | 463 | $manager = $c->get(IUserManager::class); |
| 464 | 464 | $session = new \OC\Session\Memory(); |
| 465 | 465 | $timeFactory = new TimeFactory(); |
@@ -483,40 +483,40 @@ discard block |
||
| 483 | 483 | $c->get(IEventDispatcher::class), |
| 484 | 484 | ); |
| 485 | 485 | /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */ |
| 486 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
| 486 | + $userSession->listen('\OC\User', 'preCreateUser', function($uid, $password) { |
|
| 487 | 487 | \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
| 488 | 488 | }); |
| 489 | 489 | /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */ |
| 490 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 490 | + $userSession->listen('\OC\User', 'postCreateUser', function($user, $password) { |
|
| 491 | 491 | /** @var \OC\User\User $user */ |
| 492 | 492 | \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
| 493 | 493 | }); |
| 494 | 494 | /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */ |
| 495 | - $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
| 495 | + $userSession->listen('\OC\User', 'preDelete', function($user) { |
|
| 496 | 496 | /** @var \OC\User\User $user */ |
| 497 | 497 | \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
| 498 | 498 | }); |
| 499 | 499 | /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ |
| 500 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 500 | + $userSession->listen('\OC\User', 'postDelete', function($user) { |
|
| 501 | 501 | /** @var \OC\User\User $user */ |
| 502 | 502 | \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
| 503 | 503 | }); |
| 504 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 504 | + $userSession->listen('\OC\User', 'preSetPassword', function($user, $password, $recoveryPassword) { |
|
| 505 | 505 | /** @var \OC\User\User $user */ |
| 506 | 506 | \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
| 507 | 507 | }); |
| 508 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 508 | + $userSession->listen('\OC\User', 'postSetPassword', function($user, $password, $recoveryPassword) { |
|
| 509 | 509 | /** @var \OC\User\User $user */ |
| 510 | 510 | \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
| 511 | 511 | }); |
| 512 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 512 | + $userSession->listen('\OC\User', 'preLogin', function($uid, $password) { |
|
| 513 | 513 | \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
| 514 | 514 | |
| 515 | 515 | /** @var IEventDispatcher $dispatcher */ |
| 516 | 516 | $dispatcher = $this->get(IEventDispatcher::class); |
| 517 | 517 | $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); |
| 518 | 518 | }); |
| 519 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) { |
|
| 519 | + $userSession->listen('\OC\User', 'postLogin', function($user, $loginName, $password, $isTokenLogin) { |
|
| 520 | 520 | /** @var \OC\User\User $user */ |
| 521 | 521 | \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]); |
| 522 | 522 | |
@@ -524,12 +524,12 @@ discard block |
||
| 524 | 524 | $dispatcher = $this->get(IEventDispatcher::class); |
| 525 | 525 | $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin)); |
| 526 | 526 | }); |
| 527 | - $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { |
|
| 527 | + $userSession->listen('\OC\User', 'preRememberedLogin', function($uid) { |
|
| 528 | 528 | /** @var IEventDispatcher $dispatcher */ |
| 529 | 529 | $dispatcher = $this->get(IEventDispatcher::class); |
| 530 | 530 | $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); |
| 531 | 531 | }); |
| 532 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
| 532 | + $userSession->listen('\OC\User', 'postRememberedLogin', function($user, $password) { |
|
| 533 | 533 | /** @var \OC\User\User $user */ |
| 534 | 534 | \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
| 535 | 535 | |
@@ -537,19 +537,19 @@ discard block |
||
| 537 | 537 | $dispatcher = $this->get(IEventDispatcher::class); |
| 538 | 538 | $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); |
| 539 | 539 | }); |
| 540 | - $userSession->listen('\OC\User', 'logout', function ($user) { |
|
| 540 | + $userSession->listen('\OC\User', 'logout', function($user) { |
|
| 541 | 541 | \OC_Hook::emit('OC_User', 'logout', []); |
| 542 | 542 | |
| 543 | 543 | /** @var IEventDispatcher $dispatcher */ |
| 544 | 544 | $dispatcher = $this->get(IEventDispatcher::class); |
| 545 | 545 | $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); |
| 546 | 546 | }); |
| 547 | - $userSession->listen('\OC\User', 'postLogout', function ($user) { |
|
| 547 | + $userSession->listen('\OC\User', 'postLogout', function($user) { |
|
| 548 | 548 | /** @var IEventDispatcher $dispatcher */ |
| 549 | 549 | $dispatcher = $this->get(IEventDispatcher::class); |
| 550 | 550 | $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); |
| 551 | 551 | }); |
| 552 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
| 552 | + $userSession->listen('\OC\User', 'changeUser', function($user, $feature, $value, $oldValue) { |
|
| 553 | 553 | /** @var \OC\User\User $user */ |
| 554 | 554 | \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); |
| 555 | 555 | }); |
@@ -563,7 +563,7 @@ discard block |
||
| 563 | 563 | |
| 564 | 564 | $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
| 565 | 565 | |
| 566 | - $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
| 566 | + $this->registerService(\OC\SystemConfig::class, function($c) use ($config) { |
|
| 567 | 567 | return new \OC\SystemConfig($config); |
| 568 | 568 | }); |
| 569 | 569 | |
@@ -571,7 +571,7 @@ discard block |
||
| 571 | 571 | $this->registerAlias(IUserConfig::class, \OC\Config\UserConfig::class); |
| 572 | 572 | $this->registerAlias(IAppManager::class, AppManager::class); |
| 573 | 573 | |
| 574 | - $this->registerService(IFactory::class, function (Server $c) { |
|
| 574 | + $this->registerService(IFactory::class, function(Server $c) { |
|
| 575 | 575 | return new \OC\L10N\Factory( |
| 576 | 576 | $c->get(\OCP\IConfig::class), |
| 577 | 577 | $c->getRequest(), |
@@ -584,11 +584,11 @@ discard block |
||
| 584 | 584 | |
| 585 | 585 | $this->registerAlias(IURLGenerator::class, URLGenerator::class); |
| 586 | 586 | |
| 587 | - $this->registerService(ICache::class, function ($c) { |
|
| 587 | + $this->registerService(ICache::class, function($c) { |
|
| 588 | 588 | return new Cache\File(); |
| 589 | 589 | }); |
| 590 | 590 | |
| 591 | - $this->registerService(Factory::class, function (Server $c) { |
|
| 591 | + $this->registerService(Factory::class, function(Server $c) { |
|
| 592 | 592 | $profiler = $c->get(IProfiler::class); |
| 593 | 593 | $arrayCacheFactory = new \OC\Memcache\Factory(fn () => '', $c->get(LoggerInterface::class), |
| 594 | 594 | $profiler, |
@@ -603,7 +603,7 @@ discard block |
||
| 603 | 603 | |
| 604 | 604 | if ($config->getValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
| 605 | 605 | $logQuery = $config->getValue('log_query'); |
| 606 | - $prefixClosure = function () use ($logQuery, $serverVersion): ?string { |
|
| 606 | + $prefixClosure = function() use ($logQuery, $serverVersion): ?string { |
|
| 607 | 607 | if (!$logQuery) { |
| 608 | 608 | try { |
| 609 | 609 | $v = \OCP\Server::get(IAppConfig::class)->getAppInstalledVersions(true); |
@@ -621,10 +621,10 @@ discard block |
||
| 621 | 621 | ]; |
| 622 | 622 | } |
| 623 | 623 | $v['core'] = implode(',', $serverVersion->getVersion()); |
| 624 | - $version = implode(',', array_keys($v)) . implode(',', $v); |
|
| 624 | + $version = implode(',', array_keys($v)).implode(',', $v); |
|
| 625 | 625 | $instanceId = \OC_Util::getInstanceId(); |
| 626 | 626 | $path = \OC::$SERVERROOT; |
| 627 | - return md5($instanceId . '-' . $version . '-' . $path); |
|
| 627 | + return md5($instanceId.'-'.$version.'-'.$path); |
|
| 628 | 628 | }; |
| 629 | 629 | return new \OC\Memcache\Factory($prefixClosure, |
| 630 | 630 | $c->get(LoggerInterface::class), |
@@ -643,12 +643,12 @@ discard block |
||
| 643 | 643 | }); |
| 644 | 644 | $this->registerAlias(ICacheFactory::class, Factory::class); |
| 645 | 645 | |
| 646 | - $this->registerService('RedisFactory', function (Server $c) { |
|
| 646 | + $this->registerService('RedisFactory', function(Server $c) { |
|
| 647 | 647 | $systemConfig = $c->get(SystemConfig::class); |
| 648 | 648 | return new RedisFactory($systemConfig, $c->get(IEventLogger::class)); |
| 649 | 649 | }); |
| 650 | 650 | |
| 651 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 651 | + $this->registerService(\OCP\Activity\IManager::class, function(Server $c) { |
|
| 652 | 652 | $l10n = $this->get(IFactory::class)->get('lib'); |
| 653 | 653 | return new \OC\Activity\Manager( |
| 654 | 654 | $c->getRequest(), |
@@ -660,14 +660,14 @@ discard block |
||
| 660 | 660 | ); |
| 661 | 661 | }); |
| 662 | 662 | |
| 663 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 663 | + $this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) { |
|
| 664 | 664 | return new \OC\Activity\EventMerger( |
| 665 | 665 | $c->getL10N('lib') |
| 666 | 666 | ); |
| 667 | 667 | }); |
| 668 | 668 | $this->registerAlias(IValidator::class, Validator::class); |
| 669 | 669 | |
| 670 | - $this->registerService(AvatarManager::class, function (Server $c) { |
|
| 670 | + $this->registerService(AvatarManager::class, function(Server $c) { |
|
| 671 | 671 | return new AvatarManager( |
| 672 | 672 | $c->get(IUserSession::class), |
| 673 | 673 | $c->get(\OC\User\Manager::class), |
@@ -687,7 +687,7 @@ discard block |
||
| 687 | 687 | $this->registerAlias(\OCP\Support\Subscription\IAssertion::class, \OC\Support\Subscription\Assertion::class); |
| 688 | 688 | |
| 689 | 689 | /** Only used by the PsrLoggerAdapter should not be used by apps */ |
| 690 | - $this->registerService(\OC\Log::class, function (Server $c) { |
|
| 690 | + $this->registerService(\OC\Log::class, function(Server $c) { |
|
| 691 | 691 | $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file'); |
| 692 | 692 | $factory = new LogFactory($c, $this->get(SystemConfig::class)); |
| 693 | 693 | $logger = $factory->get($logType); |
@@ -698,13 +698,13 @@ discard block |
||
| 698 | 698 | // PSR-3 logger |
| 699 | 699 | $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); |
| 700 | 700 | |
| 701 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
| 701 | + $this->registerService(ILogFactory::class, function(Server $c) { |
|
| 702 | 702 | return new LogFactory($c, $this->get(SystemConfig::class)); |
| 703 | 703 | }); |
| 704 | 704 | |
| 705 | 705 | $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class); |
| 706 | 706 | |
| 707 | - $this->registerService(Router::class, function (Server $c) { |
|
| 707 | + $this->registerService(Router::class, function(Server $c) { |
|
| 708 | 708 | $cacheFactory = $c->get(ICacheFactory::class); |
| 709 | 709 | if ($cacheFactory->isLocalCacheAvailable()) { |
| 710 | 710 | $router = $c->resolve(CachingRouter::class); |
@@ -715,7 +715,7 @@ discard block |
||
| 715 | 715 | }); |
| 716 | 716 | $this->registerAlias(IRouter::class, Router::class); |
| 717 | 717 | |
| 718 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
| 718 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) { |
|
| 719 | 719 | $config = $c->get(\OCP\IConfig::class); |
| 720 | 720 | if (ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === \OC\Memcache\Redis::class) { |
| 721 | 721 | $backend = new \OC\Security\RateLimiting\Backend\MemoryCacheBackend( |
@@ -745,7 +745,7 @@ discard block |
||
| 745 | 745 | $this->registerAlias(ICredentialsManager::class, CredentialsManager::class); |
| 746 | 746 | |
| 747 | 747 | $this->registerAlias(IDBConnection::class, ConnectionAdapter::class); |
| 748 | - $this->registerService(Connection::class, function (Server $c) { |
|
| 748 | + $this->registerService(Connection::class, function(Server $c) { |
|
| 749 | 749 | $systemConfig = $c->get(SystemConfig::class); |
| 750 | 750 | $factory = new \OC\DB\ConnectionFactory($systemConfig, $c->get(ICacheFactory::class)); |
| 751 | 751 | $type = $systemConfig->getValue('dbtype', 'sqlite'); |
@@ -758,17 +758,17 @@ discard block |
||
| 758 | 758 | |
| 759 | 759 | $this->registerAlias(ICertificateManager::class, CertificateManager::class); |
| 760 | 760 | $this->registerAlias(IClientService::class, ClientService::class); |
| 761 | - $this->registerService(NegativeDnsCache::class, function (ContainerInterface $c) { |
|
| 761 | + $this->registerService(NegativeDnsCache::class, function(ContainerInterface $c) { |
|
| 762 | 762 | return new NegativeDnsCache( |
| 763 | 763 | $c->get(ICacheFactory::class), |
| 764 | 764 | ); |
| 765 | 765 | }); |
| 766 | 766 | $this->registerDeprecatedAlias('HttpClientService', IClientService::class); |
| 767 | - $this->registerService(IEventLogger::class, function (ContainerInterface $c) { |
|
| 767 | + $this->registerService(IEventLogger::class, function(ContainerInterface $c) { |
|
| 768 | 768 | return new EventLogger($c->get(SystemConfig::class), $c->get(LoggerInterface::class), $c->get(Log::class)); |
| 769 | 769 | }); |
| 770 | 770 | |
| 771 | - $this->registerService(IQueryLogger::class, function (ContainerInterface $c) { |
|
| 771 | + $this->registerService(IQueryLogger::class, function(ContainerInterface $c) { |
|
| 772 | 772 | $queryLogger = new QueryLogger(); |
| 773 | 773 | if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
| 774 | 774 | // In debug mode, module is being activated by default |
@@ -780,7 +780,7 @@ discard block |
||
| 780 | 780 | $this->registerAlias(ITempManager::class, TempManager::class); |
| 781 | 781 | $this->registerAlias(IDateTimeZone::class, DateTimeZone::class); |
| 782 | 782 | |
| 783 | - $this->registerService(IDateTimeFormatter::class, function (Server $c) { |
|
| 783 | + $this->registerService(IDateTimeFormatter::class, function(Server $c) { |
|
| 784 | 784 | $language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null); |
| 785 | 785 | |
| 786 | 786 | return new DateTimeFormatter( |
@@ -789,14 +789,14 @@ discard block |
||
| 789 | 789 | ); |
| 790 | 790 | }); |
| 791 | 791 | |
| 792 | - $this->registerService(IUserMountCache::class, function (ContainerInterface $c) { |
|
| 792 | + $this->registerService(IUserMountCache::class, function(ContainerInterface $c) { |
|
| 793 | 793 | $mountCache = $c->get(UserMountCache::class); |
| 794 | 794 | $listener = new UserMountCacheListener($mountCache); |
| 795 | 795 | $listener->listen($c->get(IUserManager::class)); |
| 796 | 796 | return $mountCache; |
| 797 | 797 | }); |
| 798 | 798 | |
| 799 | - $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) { |
|
| 799 | + $this->registerService(IMountProviderCollection::class, function(ContainerInterface $c) { |
|
| 800 | 800 | $loader = $c->get(IStorageFactory::class); |
| 801 | 801 | $mountCache = $c->get(IUserMountCache::class); |
| 802 | 802 | $eventLogger = $c->get(IEventLogger::class); |
@@ -816,7 +816,7 @@ discard block |
||
| 816 | 816 | return $manager; |
| 817 | 817 | }); |
| 818 | 818 | |
| 819 | - $this->registerService(IBus::class, function (ContainerInterface $c) { |
|
| 819 | + $this->registerService(IBus::class, function(ContainerInterface $c) { |
|
| 820 | 820 | $busClass = $c->get(\OCP\IConfig::class)->getSystemValueString('commandbus'); |
| 821 | 821 | if ($busClass) { |
| 822 | 822 | [$app, $class] = explode('::', $busClass, 2); |
@@ -835,7 +835,7 @@ discard block |
||
| 835 | 835 | $this->registerAlias(ITrustedDomainHelper::class, TrustedDomainHelper::class); |
| 836 | 836 | $this->registerAlias(IThrottler::class, Throttler::class); |
| 837 | 837 | |
| 838 | - $this->registerService(\OC\Security\Bruteforce\Backend\IBackend::class, function ($c) { |
|
| 838 | + $this->registerService(\OC\Security\Bruteforce\Backend\IBackend::class, function($c) { |
|
| 839 | 839 | $config = $c->get(\OCP\IConfig::class); |
| 840 | 840 | if (!$config->getSystemValueBool('auth.bruteforce.protection.force.database', false) |
| 841 | 841 | && ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === \OC\Memcache\Redis::class) { |
@@ -848,7 +848,7 @@ discard block |
||
| 848 | 848 | }); |
| 849 | 849 | |
| 850 | 850 | $this->registerDeprecatedAlias('IntegrityCodeChecker', Checker::class); |
| 851 | - $this->registerService(Checker::class, function (ContainerInterface $c) { |
|
| 851 | + $this->registerService(Checker::class, function(ContainerInterface $c) { |
|
| 852 | 852 | // IConfig requires a working database. This code |
| 853 | 853 | // might however be called when Nextcloud is not yet setup. |
| 854 | 854 | if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
@@ -871,7 +871,7 @@ discard block |
||
| 871 | 871 | $c->get(IMimeTypeDetector::class) |
| 872 | 872 | ); |
| 873 | 873 | }); |
| 874 | - $this->registerService(Request::class, function (ContainerInterface $c) { |
|
| 874 | + $this->registerService(Request::class, function(ContainerInterface $c) { |
|
| 875 | 875 | if (isset($this['urlParams'])) { |
| 876 | 876 | $urlParams = $this['urlParams']; |
| 877 | 877 | } else { |
@@ -907,14 +907,14 @@ discard block |
||
| 907 | 907 | }); |
| 908 | 908 | $this->registerAlias(\OCP\IRequest::class, Request::class); |
| 909 | 909 | |
| 910 | - $this->registerService(IRequestId::class, function (ContainerInterface $c): IRequestId { |
|
| 910 | + $this->registerService(IRequestId::class, function(ContainerInterface $c): IRequestId { |
|
| 911 | 911 | return new RequestId( |
| 912 | 912 | $_SERVER['UNIQUE_ID'] ?? '', |
| 913 | 913 | $this->get(ISecureRandom::class) |
| 914 | 914 | ); |
| 915 | 915 | }); |
| 916 | 916 | |
| 917 | - $this->registerService(IMailer::class, function (Server $c) { |
|
| 917 | + $this->registerService(IMailer::class, function(Server $c) { |
|
| 918 | 918 | return new Mailer( |
| 919 | 919 | $c->get(\OCP\IConfig::class), |
| 920 | 920 | $c->get(LoggerInterface::class), |
@@ -929,7 +929,7 @@ discard block |
||
| 929 | 929 | /** @since 30.0.0 */ |
| 930 | 930 | $this->registerAlias(\OCP\Mail\Provider\IManager::class, \OC\Mail\Provider\Manager::class); |
| 931 | 931 | |
| 932 | - $this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) { |
|
| 932 | + $this->registerService(ILDAPProviderFactory::class, function(ContainerInterface $c) { |
|
| 933 | 933 | $config = $c->get(\OCP\IConfig::class); |
| 934 | 934 | $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
| 935 | 935 | if (is_null($factoryClass) || !class_exists($factoryClass)) { |
@@ -938,11 +938,11 @@ discard block |
||
| 938 | 938 | /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
| 939 | 939 | return new $factoryClass($this); |
| 940 | 940 | }); |
| 941 | - $this->registerService(ILDAPProvider::class, function (ContainerInterface $c) { |
|
| 941 | + $this->registerService(ILDAPProvider::class, function(ContainerInterface $c) { |
|
| 942 | 942 | $factory = $c->get(ILDAPProviderFactory::class); |
| 943 | 943 | return $factory->getLDAPProvider(); |
| 944 | 944 | }); |
| 945 | - $this->registerService(ILockingProvider::class, function (ContainerInterface $c) { |
|
| 945 | + $this->registerService(ILockingProvider::class, function(ContainerInterface $c) { |
|
| 946 | 946 | $ini = $c->get(IniGetWrapper::class); |
| 947 | 947 | $config = $c->get(\OCP\IConfig::class); |
| 948 | 948 | $ttl = $config->getSystemValueInt('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
@@ -964,51 +964,51 @@ discard block |
||
| 964 | 964 | return new NoopLockingProvider(); |
| 965 | 965 | }); |
| 966 | 966 | |
| 967 | - $this->registerService(ILockManager::class, function (Server $c): LockManager { |
|
| 967 | + $this->registerService(ILockManager::class, function(Server $c): LockManager { |
|
| 968 | 968 | return new LockManager(); |
| 969 | 969 | }); |
| 970 | 970 | |
| 971 | 971 | $this->registerAlias(ILockdownManager::class, 'LockdownManager'); |
| 972 | - $this->registerService(SetupManager::class, function ($c) { |
|
| 972 | + $this->registerService(SetupManager::class, function($c) { |
|
| 973 | 973 | // create the setupmanager through the mount manager to resolve the cyclic dependency |
| 974 | 974 | return $c->get(\OC\Files\Mount\Manager::class)->getSetupManager(); |
| 975 | 975 | }); |
| 976 | 976 | $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class); |
| 977 | 977 | |
| 978 | - $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) { |
|
| 978 | + $this->registerService(IMimeTypeDetector::class, function(ContainerInterface $c) { |
|
| 979 | 979 | return new \OC\Files\Type\Detection( |
| 980 | 980 | $c->get(IURLGenerator::class), |
| 981 | 981 | $c->get(LoggerInterface::class), |
| 982 | 982 | \OC::$configDir, |
| 983 | - \OC::$SERVERROOT . '/resources/config/' |
|
| 983 | + \OC::$SERVERROOT.'/resources/config/' |
|
| 984 | 984 | ); |
| 985 | 985 | }); |
| 986 | 986 | |
| 987 | 987 | $this->registerAlias(IMimeTypeLoader::class, Loader::class); |
| 988 | - $this->registerService(BundleFetcher::class, function () { |
|
| 988 | + $this->registerService(BundleFetcher::class, function() { |
|
| 989 | 989 | return new BundleFetcher($this->getL10N('lib')); |
| 990 | 990 | }); |
| 991 | 991 | $this->registerAlias(\OCP\Notification\IManager::class, Manager::class); |
| 992 | 992 | |
| 993 | - $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) { |
|
| 993 | + $this->registerService(CapabilitiesManager::class, function(ContainerInterface $c) { |
|
| 994 | 994 | $manager = new CapabilitiesManager($c->get(LoggerInterface::class)); |
| 995 | - $manager->registerCapability(function () use ($c) { |
|
| 995 | + $manager->registerCapability(function() use ($c) { |
|
| 996 | 996 | return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class)); |
| 997 | 997 | }); |
| 998 | - $manager->registerCapability(function () use ($c) { |
|
| 998 | + $manager->registerCapability(function() use ($c) { |
|
| 999 | 999 | return $c->get(\OC\Security\Bruteforce\Capabilities::class); |
| 1000 | 1000 | }); |
| 1001 | 1001 | return $manager; |
| 1002 | 1002 | }); |
| 1003 | 1003 | |
| 1004 | - $this->registerService(ICommentsManager::class, function (Server $c) { |
|
| 1004 | + $this->registerService(ICommentsManager::class, function(Server $c) { |
|
| 1005 | 1005 | $config = $c->get(\OCP\IConfig::class); |
| 1006 | 1006 | $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
| 1007 | 1007 | /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
| 1008 | 1008 | $factory = new $factoryClass($this); |
| 1009 | 1009 | $manager = $factory->getManager(); |
| 1010 | 1010 | |
| 1011 | - $manager->registerDisplayNameResolver('user', function ($id) use ($c) { |
|
| 1011 | + $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
|
| 1012 | 1012 | $manager = $c->get(IUserManager::class); |
| 1013 | 1013 | $userDisplayName = $manager->getDisplayName($id); |
| 1014 | 1014 | if ($userDisplayName === null) { |
@@ -1022,7 +1022,7 @@ discard block |
||
| 1022 | 1022 | }); |
| 1023 | 1023 | |
| 1024 | 1024 | $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults'); |
| 1025 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
| 1025 | + $this->registerService('ThemingDefaults', function(Server $c) { |
|
| 1026 | 1026 | try { |
| 1027 | 1027 | $classExists = class_exists('OCA\Theming\ThemingDefaults'); |
| 1028 | 1028 | } catch (\OCP\AutoloadNotAllowedException $e) { |
@@ -1063,7 +1063,7 @@ discard block |
||
| 1063 | 1063 | } |
| 1064 | 1064 | return new \OC_Defaults(); |
| 1065 | 1065 | }); |
| 1066 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
| 1066 | + $this->registerService(JSCombiner::class, function(Server $c) { |
|
| 1067 | 1067 | return new JSCombiner( |
| 1068 | 1068 | $c->getAppDataDir('js'), |
| 1069 | 1069 | $c->get(IURLGenerator::class), |
@@ -1074,7 +1074,7 @@ discard block |
||
| 1074 | 1074 | }); |
| 1075 | 1075 | $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
| 1076 | 1076 | |
| 1077 | - $this->registerService('CryptoWrapper', function (ContainerInterface $c) { |
|
| 1077 | + $this->registerService('CryptoWrapper', function(ContainerInterface $c) { |
|
| 1078 | 1078 | // FIXME: Instantiated here due to cyclic dependency |
| 1079 | 1079 | $request = new Request( |
| 1080 | 1080 | [ |
@@ -1098,12 +1098,12 @@ discard block |
||
| 1098 | 1098 | $request |
| 1099 | 1099 | ); |
| 1100 | 1100 | }); |
| 1101 | - $this->registerService(SessionStorage::class, function (ContainerInterface $c) { |
|
| 1101 | + $this->registerService(SessionStorage::class, function(ContainerInterface $c) { |
|
| 1102 | 1102 | return new SessionStorage($c->get(ISession::class)); |
| 1103 | 1103 | }); |
| 1104 | 1104 | $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); |
| 1105 | 1105 | |
| 1106 | - $this->registerService(IProviderFactory::class, function (ContainerInterface $c) { |
|
| 1106 | + $this->registerService(IProviderFactory::class, function(ContainerInterface $c) { |
|
| 1107 | 1107 | $config = $c->get(\OCP\IConfig::class); |
| 1108 | 1108 | $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
| 1109 | 1109 | /** @var \OCP\Share\IProviderFactory $factory */ |
@@ -1112,7 +1112,7 @@ discard block |
||
| 1112 | 1112 | |
| 1113 | 1113 | $this->registerAlias(\OCP\Share\IManager::class, \OC\Share20\Manager::class); |
| 1114 | 1114 | |
| 1115 | - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) { |
|
| 1115 | + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
|
| 1116 | 1116 | $instance = new Collaboration\Collaborators\Search($c); |
| 1117 | 1117 | |
| 1118 | 1118 | // register default plugins |
@@ -1136,20 +1136,20 @@ discard block |
||
| 1136 | 1136 | |
| 1137 | 1137 | $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class); |
| 1138 | 1138 | $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class); |
| 1139 | - $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) { |
|
| 1139 | + $this->registerService(\OC\Files\AppData\Factory::class, function(ContainerInterface $c) { |
|
| 1140 | 1140 | return new \OC\Files\AppData\Factory( |
| 1141 | 1141 | $c->get(IRootFolder::class), |
| 1142 | 1142 | $c->get(SystemConfig::class) |
| 1143 | 1143 | ); |
| 1144 | 1144 | }); |
| 1145 | 1145 | |
| 1146 | - $this->registerService('LockdownManager', function (ContainerInterface $c) { |
|
| 1147 | - return new LockdownManager(function () use ($c) { |
|
| 1146 | + $this->registerService('LockdownManager', function(ContainerInterface $c) { |
|
| 1147 | + return new LockdownManager(function() use ($c) { |
|
| 1148 | 1148 | return $c->get(ISession::class); |
| 1149 | 1149 | }); |
| 1150 | 1150 | }); |
| 1151 | 1151 | |
| 1152 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) { |
|
| 1152 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function(ContainerInterface $c) { |
|
| 1153 | 1153 | return new DiscoveryService( |
| 1154 | 1154 | $c->get(ICacheFactory::class), |
| 1155 | 1155 | $c->get(IClientService::class) |
@@ -1157,7 +1157,7 @@ discard block |
||
| 1157 | 1157 | }); |
| 1158 | 1158 | $this->registerAlias(IOCMDiscoveryService::class, OCMDiscoveryService::class); |
| 1159 | 1159 | |
| 1160 | - $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) { |
|
| 1160 | + $this->registerService(ICloudIdManager::class, function(ContainerInterface $c) { |
|
| 1161 | 1161 | return new CloudIdManager( |
| 1162 | 1162 | $c->get(\OCP\Contacts\IManager::class), |
| 1163 | 1163 | $c->get(IURLGenerator::class), |
@@ -1169,7 +1169,7 @@ discard block |
||
| 1169 | 1169 | |
| 1170 | 1170 | $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class); |
| 1171 | 1171 | $this->registerAlias(ICloudFederationProviderManager::class, CloudFederationProviderManager::class); |
| 1172 | - $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
| 1172 | + $this->registerService(ICloudFederationFactory::class, function(Server $c) { |
|
| 1173 | 1173 | return new CloudFederationFactory(); |
| 1174 | 1174 | }); |
| 1175 | 1175 | |
@@ -1178,23 +1178,23 @@ discard block |
||
| 1178 | 1178 | $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
| 1179 | 1179 | $this->registerAlias(\Psr\Clock\ClockInterface::class, \OCP\AppFramework\Utility\ITimeFactory::class); |
| 1180 | 1180 | |
| 1181 | - $this->registerService(Defaults::class, function (Server $c) { |
|
| 1181 | + $this->registerService(Defaults::class, function(Server $c) { |
|
| 1182 | 1182 | return new Defaults( |
| 1183 | 1183 | $c->get('ThemingDefaults') |
| 1184 | 1184 | ); |
| 1185 | 1185 | }); |
| 1186 | 1186 | |
| 1187 | - $this->registerService(\OCP\ISession::class, function (ContainerInterface $c) { |
|
| 1187 | + $this->registerService(\OCP\ISession::class, function(ContainerInterface $c) { |
|
| 1188 | 1188 | return $c->get(\OCP\IUserSession::class)->getSession(); |
| 1189 | 1189 | }, false); |
| 1190 | 1190 | |
| 1191 | - $this->registerService(IShareHelper::class, function (ContainerInterface $c) { |
|
| 1191 | + $this->registerService(IShareHelper::class, function(ContainerInterface $c) { |
|
| 1192 | 1192 | return new ShareHelper( |
| 1193 | 1193 | $c->get(\OCP\Share\IManager::class) |
| 1194 | 1194 | ); |
| 1195 | 1195 | }); |
| 1196 | 1196 | |
| 1197 | - $this->registerService(Installer::class, function (ContainerInterface $c) { |
|
| 1197 | + $this->registerService(Installer::class, function(ContainerInterface $c) { |
|
| 1198 | 1198 | return new Installer( |
| 1199 | 1199 | $c->get(AppFetcher::class), |
| 1200 | 1200 | $c->get(IClientService::class), |
@@ -1205,11 +1205,11 @@ discard block |
||
| 1205 | 1205 | ); |
| 1206 | 1206 | }); |
| 1207 | 1207 | |
| 1208 | - $this->registerService(IApiFactory::class, function (ContainerInterface $c) { |
|
| 1208 | + $this->registerService(IApiFactory::class, function(ContainerInterface $c) { |
|
| 1209 | 1209 | return new ApiFactory($c->get(IClientService::class)); |
| 1210 | 1210 | }); |
| 1211 | 1211 | |
| 1212 | - $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) { |
|
| 1212 | + $this->registerService(IInstanceFactory::class, function(ContainerInterface $c) { |
|
| 1213 | 1213 | $memcacheFactory = $c->get(ICacheFactory::class); |
| 1214 | 1214 | return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class)); |
| 1215 | 1215 | }); |
@@ -21,100 +21,100 @@ |
||
| 21 | 21 | use function array_shift; |
| 22 | 22 | |
| 23 | 23 | class Registry implements IRegistry { |
| 24 | - /** @var string[] */ |
|
| 25 | - private $lazyReporters = []; |
|
| 26 | - |
|
| 27 | - /** @var IReporter[] */ |
|
| 28 | - private $reporters = []; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Register a reporter instance |
|
| 32 | - */ |
|
| 33 | - public function register(IReporter $reporter): void { |
|
| 34 | - $this->reporters[] = $reporter; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - public function registerLazy(string $class): void { |
|
| 38 | - $this->lazyReporters[] = $class; |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Delegate breadcrumb collection to all registered reporters |
|
| 43 | - * |
|
| 44 | - * @since 15.0.0 |
|
| 45 | - */ |
|
| 46 | - public function delegateBreadcrumb(string $message, string $category, array $context = []): void { |
|
| 47 | - $this->loadLazyProviders(); |
|
| 48 | - |
|
| 49 | - foreach ($this->reporters as $reporter) { |
|
| 50 | - if ($reporter instanceof ICollectBreadcrumbs) { |
|
| 51 | - $reporter->collect($message, $category, $context); |
|
| 52 | - } |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Delegate crash reporting to all registered reporters |
|
| 58 | - * |
|
| 59 | - * @param Exception|Throwable $exception |
|
| 60 | - */ |
|
| 61 | - public function delegateReport($exception, array $context = []): void { |
|
| 62 | - $this->loadLazyProviders(); |
|
| 63 | - |
|
| 64 | - foreach ($this->reporters as $reporter) { |
|
| 65 | - $reporter->report($exception, $context); |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Delegate a message to all reporters that implement IMessageReporter |
|
| 71 | - * |
|
| 72 | - * @return void |
|
| 73 | - */ |
|
| 74 | - public function delegateMessage(string $message, array $context = []): void { |
|
| 75 | - $this->loadLazyProviders(); |
|
| 76 | - |
|
| 77 | - foreach ($this->reporters as $reporter) { |
|
| 78 | - if ($reporter instanceof IMessageReporter) { |
|
| 79 | - $reporter->reportMessage($message, $context); |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - private function loadLazyProviders(): void { |
|
| 85 | - while (($class = array_shift($this->lazyReporters)) !== null) { |
|
| 86 | - try { |
|
| 87 | - /** @var IReporter $reporter */ |
|
| 88 | - $reporter = Server::get($class); |
|
| 89 | - } catch (QueryException $e) { |
|
| 90 | - /* |
|
| 24 | + /** @var string[] */ |
|
| 25 | + private $lazyReporters = []; |
|
| 26 | + |
|
| 27 | + /** @var IReporter[] */ |
|
| 28 | + private $reporters = []; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Register a reporter instance |
|
| 32 | + */ |
|
| 33 | + public function register(IReporter $reporter): void { |
|
| 34 | + $this->reporters[] = $reporter; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + public function registerLazy(string $class): void { |
|
| 38 | + $this->lazyReporters[] = $class; |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Delegate breadcrumb collection to all registered reporters |
|
| 43 | + * |
|
| 44 | + * @since 15.0.0 |
|
| 45 | + */ |
|
| 46 | + public function delegateBreadcrumb(string $message, string $category, array $context = []): void { |
|
| 47 | + $this->loadLazyProviders(); |
|
| 48 | + |
|
| 49 | + foreach ($this->reporters as $reporter) { |
|
| 50 | + if ($reporter instanceof ICollectBreadcrumbs) { |
|
| 51 | + $reporter->collect($message, $category, $context); |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Delegate crash reporting to all registered reporters |
|
| 58 | + * |
|
| 59 | + * @param Exception|Throwable $exception |
|
| 60 | + */ |
|
| 61 | + public function delegateReport($exception, array $context = []): void { |
|
| 62 | + $this->loadLazyProviders(); |
|
| 63 | + |
|
| 64 | + foreach ($this->reporters as $reporter) { |
|
| 65 | + $reporter->report($exception, $context); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Delegate a message to all reporters that implement IMessageReporter |
|
| 71 | + * |
|
| 72 | + * @return void |
|
| 73 | + */ |
|
| 74 | + public function delegateMessage(string $message, array $context = []): void { |
|
| 75 | + $this->loadLazyProviders(); |
|
| 76 | + |
|
| 77 | + foreach ($this->reporters as $reporter) { |
|
| 78 | + if ($reporter instanceof IMessageReporter) { |
|
| 79 | + $reporter->reportMessage($message, $context); |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + private function loadLazyProviders(): void { |
|
| 85 | + while (($class = array_shift($this->lazyReporters)) !== null) { |
|
| 86 | + try { |
|
| 87 | + /** @var IReporter $reporter */ |
|
| 88 | + $reporter = Server::get($class); |
|
| 89 | + } catch (QueryException $e) { |
|
| 90 | + /* |
|
| 91 | 91 | * There is a circular dependency between the logger and the registry, so |
| 92 | 92 | * we can not inject it. Thus the static call. |
| 93 | 93 | */ |
| 94 | - Server::get(LoggerInterface::class)->critical('Could not load lazy crash reporter: ' . $e->getMessage(), [ |
|
| 95 | - 'exception' => $e, |
|
| 96 | - ]); |
|
| 97 | - return; |
|
| 98 | - } |
|
| 99 | - /** |
|
| 100 | - * Try to register the loaded reporter. Theoretically it could be of a wrong |
|
| 101 | - * type, so we might get a TypeError here that we should catch. |
|
| 102 | - */ |
|
| 103 | - try { |
|
| 104 | - $this->register($reporter); |
|
| 105 | - } catch (Throwable $e) { |
|
| 106 | - /* |
|
| 94 | + Server::get(LoggerInterface::class)->critical('Could not load lazy crash reporter: ' . $e->getMessage(), [ |
|
| 95 | + 'exception' => $e, |
|
| 96 | + ]); |
|
| 97 | + return; |
|
| 98 | + } |
|
| 99 | + /** |
|
| 100 | + * Try to register the loaded reporter. Theoretically it could be of a wrong |
|
| 101 | + * type, so we might get a TypeError here that we should catch. |
|
| 102 | + */ |
|
| 103 | + try { |
|
| 104 | + $this->register($reporter); |
|
| 105 | + } catch (Throwable $e) { |
|
| 106 | + /* |
|
| 107 | 107 | * There is a circular dependency between the logger and the registry, so |
| 108 | 108 | * we can not inject it. Thus the static call. |
| 109 | 109 | */ |
| 110 | - Server::get(LoggerInterface::class)->critical('Could not register lazy crash reporter: ' . $e->getMessage(), [ |
|
| 111 | - 'exception' => $e, |
|
| 112 | - ]); |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - public function hasReporters(): bool { |
|
| 118 | - return !empty($this->lazyReporters) || !empty($this->reporters); |
|
| 119 | - } |
|
| 110 | + Server::get(LoggerInterface::class)->critical('Could not register lazy crash reporter: ' . $e->getMessage(), [ |
|
| 111 | + 'exception' => $e, |
|
| 112 | + ]); |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + public function hasReporters(): bool { |
|
| 118 | + return !empty($this->lazyReporters) || !empty($this->reporters); |
|
| 119 | + } |
|
| 120 | 120 | } |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | * There is a circular dependency between the logger and the registry, so |
| 92 | 92 | * we can not inject it. Thus the static call. |
| 93 | 93 | */ |
| 94 | - Server::get(LoggerInterface::class)->critical('Could not load lazy crash reporter: ' . $e->getMessage(), [ |
|
| 94 | + Server::get(LoggerInterface::class)->critical('Could not load lazy crash reporter: '.$e->getMessage(), [ |
|
| 95 | 95 | 'exception' => $e, |
| 96 | 96 | ]); |
| 97 | 97 | return; |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | * There is a circular dependency between the logger and the registry, so |
| 108 | 108 | * we can not inject it. Thus the static call. |
| 109 | 109 | */ |
| 110 | - Server::get(LoggerInterface::class)->critical('Could not register lazy crash reporter: ' . $e->getMessage(), [ |
|
| 110 | + Server::get(LoggerInterface::class)->critical('Could not register lazy crash reporter: '.$e->getMessage(), [ |
|
| 111 | 111 | 'exception' => $e, |
| 112 | 112 | ]); |
| 113 | 113 | } |
@@ -63,301 +63,301 @@ |
||
| 63 | 63 | use Psr\Log\LoggerInterface; |
| 64 | 64 | |
| 65 | 65 | class DIContainer extends SimpleContainer implements IAppContainer { |
| 66 | - private string $appName; |
|
| 67 | - private array $middleWares = []; |
|
| 68 | - private ServerContainer $server; |
|
| 69 | - |
|
| 70 | - public function __construct(string $appName, array $urlParams = [], ?ServerContainer $server = null) { |
|
| 71 | - parent::__construct(); |
|
| 72 | - $this->appName = $appName; |
|
| 73 | - $this->registerParameter('appName', $appName); |
|
| 74 | - $this->registerParameter('urlParams', $urlParams); |
|
| 75 | - |
|
| 76 | - /** @deprecated 32.0.0 */ |
|
| 77 | - $this->registerDeprecatedAlias('Request', IRequest::class); |
|
| 78 | - |
|
| 79 | - if ($server === null) { |
|
| 80 | - $server = \OC::$server; |
|
| 81 | - } |
|
| 82 | - $this->server = $server; |
|
| 83 | - $this->server->registerAppContainer($appName, $this); |
|
| 84 | - |
|
| 85 | - // aliases |
|
| 86 | - /** @deprecated 26.0.0 inject $appName */ |
|
| 87 | - $this->registerDeprecatedAlias('AppName', 'appName'); |
|
| 88 | - /** @deprecated 26.0.0 inject $webRoot*/ |
|
| 89 | - $this->registerDeprecatedAlias('WebRoot', 'webRoot'); |
|
| 90 | - /** @deprecated 26.0.0 inject $userId */ |
|
| 91 | - $this->registerDeprecatedAlias('UserId', 'userId'); |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Core services |
|
| 95 | - */ |
|
| 96 | - /* Cannot be an alias because Output is not in OCA */ |
|
| 97 | - $this->registerService(IOutput::class, fn (ContainerInterface $c): IOutput => new Output($c->get('webRoot'))); |
|
| 98 | - |
|
| 99 | - $this->registerService(Folder::class, function () { |
|
| 100 | - return $this->getServer()->getUserFolder(); |
|
| 101 | - }); |
|
| 102 | - |
|
| 103 | - $this->registerService(IAppData::class, function (ContainerInterface $c): IAppData { |
|
| 104 | - return $c->get(IAppDataFactory::class)->get($c->get('appName')); |
|
| 105 | - }); |
|
| 106 | - |
|
| 107 | - $this->registerService(IL10N::class, function (ContainerInterface $c) { |
|
| 108 | - return $this->getServer()->getL10N($c->get('appName')); |
|
| 109 | - }); |
|
| 110 | - |
|
| 111 | - // Log wrappers |
|
| 112 | - $this->registerService(LoggerInterface::class, function (ContainerInterface $c) { |
|
| 113 | - /* Cannot be an alias because it uses LoggerInterface so it would infinite loop */ |
|
| 114 | - return new ScopedPsrLogger( |
|
| 115 | - $c->get(PsrLoggerAdapter::class), |
|
| 116 | - $c->get('appName') |
|
| 117 | - ); |
|
| 118 | - }); |
|
| 119 | - |
|
| 120 | - $this->registerService(IServerContainer::class, function () { |
|
| 121 | - return $this->getServer(); |
|
| 122 | - }); |
|
| 123 | - /** @deprecated 32.0.0 */ |
|
| 124 | - $this->registerDeprecatedAlias('ServerContainer', IServerContainer::class); |
|
| 125 | - |
|
| 126 | - $this->registerAlias(\OCP\WorkflowEngine\IManager::class, Manager::class); |
|
| 127 | - |
|
| 128 | - $this->registerService(ContainerInterface::class, fn (ContainerInterface $c) => $c); |
|
| 129 | - $this->registerDeprecatedAlias(IAppContainer::class, ContainerInterface::class); |
|
| 130 | - |
|
| 131 | - // commonly used attributes |
|
| 132 | - $this->registerService('userId', function (ContainerInterface $c): ?string { |
|
| 133 | - return $c->get(ISession::class)->get('user_id'); |
|
| 134 | - }); |
|
| 135 | - |
|
| 136 | - $this->registerService('webRoot', function (ContainerInterface $c): string { |
|
| 137 | - return $c->get(IServerContainer::class)->getWebRoot(); |
|
| 138 | - }); |
|
| 139 | - |
|
| 140 | - $this->registerService('OC_Defaults', function (ContainerInterface $c): object { |
|
| 141 | - return $c->get(IServerContainer::class)->get('ThemingDefaults'); |
|
| 142 | - }); |
|
| 143 | - |
|
| 144 | - /** @deprecated 32.0.0 */ |
|
| 145 | - $this->registerDeprecatedAlias('Protocol', Http::class); |
|
| 146 | - $this->registerService(Http::class, function (ContainerInterface $c) { |
|
| 147 | - $protocol = $c->get(IRequest::class)->getHttpProtocol(); |
|
| 148 | - return new Http($_SERVER, $protocol); |
|
| 149 | - }); |
|
| 150 | - |
|
| 151 | - /** @deprecated 32.0.0 */ |
|
| 152 | - $this->registerDeprecatedAlias('Dispatcher', Dispatcher::class); |
|
| 153 | - $this->registerService(Dispatcher::class, function (ContainerInterface $c) { |
|
| 154 | - return new Dispatcher( |
|
| 155 | - $c->get('Protocol'), |
|
| 156 | - $c->get(MiddlewareDispatcher::class), |
|
| 157 | - $c->get(IControllerMethodReflector::class), |
|
| 158 | - $c->get(IRequest::class), |
|
| 159 | - $c->get(IConfig::class), |
|
| 160 | - $c->get(IDBConnection::class), |
|
| 161 | - $c->get(LoggerInterface::class), |
|
| 162 | - $c->get(EventLogger::class), |
|
| 163 | - $c, |
|
| 164 | - ); |
|
| 165 | - }); |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * App Framework default arguments |
|
| 169 | - */ |
|
| 170 | - $this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH'); |
|
| 171 | - $this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept'); |
|
| 172 | - $this->registerParameter('corsMaxAge', 1728000); |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * Middleware |
|
| 176 | - */ |
|
| 177 | - /** @deprecated 32.0.0 */ |
|
| 178 | - $this->registerDeprecatedAlias('MiddlewareDispatcher', MiddlewareDispatcher::class); |
|
| 179 | - $this->registerService(MiddlewareDispatcher::class, function (ContainerInterface $c) { |
|
| 180 | - $server = $this->getServer(); |
|
| 181 | - |
|
| 182 | - $dispatcher = new MiddlewareDispatcher(); |
|
| 183 | - |
|
| 184 | - $dispatcher->registerMiddleware($c->get(CompressionMiddleware::class)); |
|
| 185 | - $dispatcher->registerMiddleware($c->get(NotModifiedMiddleware::class)); |
|
| 186 | - $dispatcher->registerMiddleware($c->get(ReloadExecutionMiddleware::class)); |
|
| 187 | - $dispatcher->registerMiddleware($c->get(SameSiteCookieMiddleware::class)); |
|
| 188 | - $dispatcher->registerMiddleware($c->get(CORSMiddleware::class)); |
|
| 189 | - $dispatcher->registerMiddleware($c->get(OCSMiddleware::class)); |
|
| 190 | - |
|
| 191 | - $dispatcher->registerMiddleware($c->get(FlowV2EphemeralSessionsMiddleware::class)); |
|
| 192 | - |
|
| 193 | - $securityMiddleware = new SecurityMiddleware( |
|
| 194 | - $c->get(IRequest::class), |
|
| 195 | - $c->get(IControllerMethodReflector::class), |
|
| 196 | - $c->get(INavigationManager::class), |
|
| 197 | - $c->get(IURLGenerator::class), |
|
| 198 | - $c->get(LoggerInterface::class), |
|
| 199 | - $c->get('appName'), |
|
| 200 | - $server->getUserSession()->isLoggedIn(), |
|
| 201 | - $c->get(IGroupManager::class), |
|
| 202 | - $c->get(ISubAdmin::class), |
|
| 203 | - $server->getAppManager(), |
|
| 204 | - $server->getL10N('lib'), |
|
| 205 | - $c->get(AuthorizedGroupMapper::class), |
|
| 206 | - $c->get(IUserSession::class), |
|
| 207 | - $c->get(IRemoteAddress::class), |
|
| 208 | - ); |
|
| 209 | - $dispatcher->registerMiddleware($securityMiddleware); |
|
| 210 | - $dispatcher->registerMiddleware($c->get(CSPMiddleware::class)); |
|
| 211 | - $dispatcher->registerMiddleware($c->get(FeaturePolicyMiddleware::class)); |
|
| 212 | - $dispatcher->registerMiddleware($c->get(PasswordConfirmationMiddleware::class)); |
|
| 213 | - $dispatcher->registerMiddleware($c->get(TwoFactorMiddleware::class)); |
|
| 214 | - $dispatcher->registerMiddleware($c->get(BruteForceMiddleware::class)); |
|
| 215 | - $dispatcher->registerMiddleware($c->get(RateLimitingMiddleware::class)); |
|
| 216 | - $dispatcher->registerMiddleware($c->get(PublicShareMiddleware::class)); |
|
| 217 | - $dispatcher->registerMiddleware($c->get(AdditionalScriptsMiddleware::class)); |
|
| 218 | - |
|
| 219 | - $coordinator = $c->get(\OC\AppFramework\Bootstrap\Coordinator::class); |
|
| 220 | - $registrationContext = $coordinator->getRegistrationContext(); |
|
| 221 | - if ($registrationContext !== null) { |
|
| 222 | - $appId = $this->get('appName'); |
|
| 223 | - foreach ($registrationContext->getMiddlewareRegistrations() as $middlewareRegistration) { |
|
| 224 | - if ($middlewareRegistration->getAppId() === $appId |
|
| 225 | - || $middlewareRegistration->isGlobal()) { |
|
| 226 | - $dispatcher->registerMiddleware($c->get($middlewareRegistration->getService())); |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - foreach ($this->middleWares as $middleWare) { |
|
| 231 | - $dispatcher->registerMiddleware($c->get($middleWare)); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - $dispatcher->registerMiddleware($c->get(SessionMiddleware::class)); |
|
| 235 | - return $dispatcher; |
|
| 236 | - }); |
|
| 237 | - |
|
| 238 | - $this->registerAlias(IAppConfig::class, \OC\AppFramework\Services\AppConfig::class); |
|
| 239 | - $this->registerAlias(IInitialState::class, \OC\AppFramework\Services\InitialState::class); |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * @return \OCP\IServerContainer |
|
| 244 | - */ |
|
| 245 | - public function getServer() { |
|
| 246 | - return $this->server; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * @param string $middleWare |
|
| 251 | - */ |
|
| 252 | - public function registerMiddleWare($middleWare): bool { |
|
| 253 | - if (in_array($middleWare, $this->middleWares, true) !== false) { |
|
| 254 | - return false; |
|
| 255 | - } |
|
| 256 | - $this->middleWares[] = $middleWare; |
|
| 257 | - return true; |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * used to return the appname of the set application |
|
| 262 | - * @return string the name of your application |
|
| 263 | - */ |
|
| 264 | - public function getAppName() { |
|
| 265 | - return $this->query('appName'); |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * @deprecated 12.0.0 use IUserSession->isLoggedIn() |
|
| 270 | - * @return boolean |
|
| 271 | - */ |
|
| 272 | - public function isLoggedIn() { |
|
| 273 | - return \OC::$server->getUserSession()->isLoggedIn(); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * @deprecated 12.0.0 use IGroupManager->isAdmin($userId) |
|
| 278 | - * @return boolean |
|
| 279 | - */ |
|
| 280 | - public function isAdminUser() { |
|
| 281 | - $uid = $this->getUserId(); |
|
| 282 | - return \OC_User::isAdminUser($uid); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - private function getUserId(): string { |
|
| 286 | - return $this->getServer()->getSession()->get('user_id'); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * Register a capability |
|
| 291 | - * |
|
| 292 | - * @param string $serviceName e.g. 'OCA\Files\Capabilities' |
|
| 293 | - */ |
|
| 294 | - public function registerCapability($serviceName) { |
|
| 295 | - $this->query('OC\CapabilitiesManager')->registerCapability(function () use ($serviceName) { |
|
| 296 | - return $this->query($serviceName); |
|
| 297 | - }); |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - public function has($id): bool { |
|
| 301 | - if (parent::has($id)) { |
|
| 302 | - return true; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - if ($this->server->has($id, true)) { |
|
| 306 | - return true; |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - return false; |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - public function query(string $name, bool $autoload = true) { |
|
| 313 | - if ($name === 'AppName' || $name === 'appName') { |
|
| 314 | - return $this->appName; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - $isServerClass = str_starts_with($name, 'OCP\\') || str_starts_with($name, 'OC\\'); |
|
| 318 | - if ($isServerClass && !$this->has($name)) { |
|
| 319 | - return $this->getServer()->query($name, $autoload); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - try { |
|
| 323 | - return $this->queryNoFallback($name); |
|
| 324 | - } catch (QueryException $firstException) { |
|
| 325 | - try { |
|
| 326 | - return $this->getServer()->query($name, $autoload); |
|
| 327 | - } catch (QueryException $secondException) { |
|
| 328 | - if ($firstException->getCode() === 1) { |
|
| 329 | - throw $secondException; |
|
| 330 | - } |
|
| 331 | - throw $firstException; |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * @param string $name |
|
| 338 | - * @return mixed |
|
| 339 | - * @throws QueryException if the query could not be resolved |
|
| 340 | - */ |
|
| 341 | - public function queryNoFallback($name) { |
|
| 342 | - $name = $this->sanitizeName($name); |
|
| 343 | - |
|
| 344 | - if ($this->offsetExists($name)) { |
|
| 345 | - return parent::query($name); |
|
| 346 | - } elseif ($this->appName === 'settings' && str_starts_with($name, 'OC\\Settings\\')) { |
|
| 347 | - return parent::query($name); |
|
| 348 | - } elseif ($this->appName === 'core' && str_starts_with($name, 'OC\\Core\\')) { |
|
| 349 | - return parent::query($name); |
|
| 350 | - } elseif (str_starts_with($name, \OC\AppFramework\App::buildAppNamespace($this->appName) . '\\')) { |
|
| 351 | - return parent::query($name); |
|
| 352 | - } elseif ( |
|
| 353 | - str_starts_with($name, 'OC\\AppFramework\\Services\\') |
|
| 354 | - || str_starts_with($name, 'OC\\AppFramework\\Middleware\\') |
|
| 355 | - ) { |
|
| 356 | - /* AppFramework services are scoped to the application */ |
|
| 357 | - return parent::query($name); |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - throw new QueryException('Could not resolve ' . $name . '!' |
|
| 361 | - . ' Class can not be instantiated', 1); |
|
| 362 | - } |
|
| 66 | + private string $appName; |
|
| 67 | + private array $middleWares = []; |
|
| 68 | + private ServerContainer $server; |
|
| 69 | + |
|
| 70 | + public function __construct(string $appName, array $urlParams = [], ?ServerContainer $server = null) { |
|
| 71 | + parent::__construct(); |
|
| 72 | + $this->appName = $appName; |
|
| 73 | + $this->registerParameter('appName', $appName); |
|
| 74 | + $this->registerParameter('urlParams', $urlParams); |
|
| 75 | + |
|
| 76 | + /** @deprecated 32.0.0 */ |
|
| 77 | + $this->registerDeprecatedAlias('Request', IRequest::class); |
|
| 78 | + |
|
| 79 | + if ($server === null) { |
|
| 80 | + $server = \OC::$server; |
|
| 81 | + } |
|
| 82 | + $this->server = $server; |
|
| 83 | + $this->server->registerAppContainer($appName, $this); |
|
| 84 | + |
|
| 85 | + // aliases |
|
| 86 | + /** @deprecated 26.0.0 inject $appName */ |
|
| 87 | + $this->registerDeprecatedAlias('AppName', 'appName'); |
|
| 88 | + /** @deprecated 26.0.0 inject $webRoot*/ |
|
| 89 | + $this->registerDeprecatedAlias('WebRoot', 'webRoot'); |
|
| 90 | + /** @deprecated 26.0.0 inject $userId */ |
|
| 91 | + $this->registerDeprecatedAlias('UserId', 'userId'); |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Core services |
|
| 95 | + */ |
|
| 96 | + /* Cannot be an alias because Output is not in OCA */ |
|
| 97 | + $this->registerService(IOutput::class, fn (ContainerInterface $c): IOutput => new Output($c->get('webRoot'))); |
|
| 98 | + |
|
| 99 | + $this->registerService(Folder::class, function () { |
|
| 100 | + return $this->getServer()->getUserFolder(); |
|
| 101 | + }); |
|
| 102 | + |
|
| 103 | + $this->registerService(IAppData::class, function (ContainerInterface $c): IAppData { |
|
| 104 | + return $c->get(IAppDataFactory::class)->get($c->get('appName')); |
|
| 105 | + }); |
|
| 106 | + |
|
| 107 | + $this->registerService(IL10N::class, function (ContainerInterface $c) { |
|
| 108 | + return $this->getServer()->getL10N($c->get('appName')); |
|
| 109 | + }); |
|
| 110 | + |
|
| 111 | + // Log wrappers |
|
| 112 | + $this->registerService(LoggerInterface::class, function (ContainerInterface $c) { |
|
| 113 | + /* Cannot be an alias because it uses LoggerInterface so it would infinite loop */ |
|
| 114 | + return new ScopedPsrLogger( |
|
| 115 | + $c->get(PsrLoggerAdapter::class), |
|
| 116 | + $c->get('appName') |
|
| 117 | + ); |
|
| 118 | + }); |
|
| 119 | + |
|
| 120 | + $this->registerService(IServerContainer::class, function () { |
|
| 121 | + return $this->getServer(); |
|
| 122 | + }); |
|
| 123 | + /** @deprecated 32.0.0 */ |
|
| 124 | + $this->registerDeprecatedAlias('ServerContainer', IServerContainer::class); |
|
| 125 | + |
|
| 126 | + $this->registerAlias(\OCP\WorkflowEngine\IManager::class, Manager::class); |
|
| 127 | + |
|
| 128 | + $this->registerService(ContainerInterface::class, fn (ContainerInterface $c) => $c); |
|
| 129 | + $this->registerDeprecatedAlias(IAppContainer::class, ContainerInterface::class); |
|
| 130 | + |
|
| 131 | + // commonly used attributes |
|
| 132 | + $this->registerService('userId', function (ContainerInterface $c): ?string { |
|
| 133 | + return $c->get(ISession::class)->get('user_id'); |
|
| 134 | + }); |
|
| 135 | + |
|
| 136 | + $this->registerService('webRoot', function (ContainerInterface $c): string { |
|
| 137 | + return $c->get(IServerContainer::class)->getWebRoot(); |
|
| 138 | + }); |
|
| 139 | + |
|
| 140 | + $this->registerService('OC_Defaults', function (ContainerInterface $c): object { |
|
| 141 | + return $c->get(IServerContainer::class)->get('ThemingDefaults'); |
|
| 142 | + }); |
|
| 143 | + |
|
| 144 | + /** @deprecated 32.0.0 */ |
|
| 145 | + $this->registerDeprecatedAlias('Protocol', Http::class); |
|
| 146 | + $this->registerService(Http::class, function (ContainerInterface $c) { |
|
| 147 | + $protocol = $c->get(IRequest::class)->getHttpProtocol(); |
|
| 148 | + return new Http($_SERVER, $protocol); |
|
| 149 | + }); |
|
| 150 | + |
|
| 151 | + /** @deprecated 32.0.0 */ |
|
| 152 | + $this->registerDeprecatedAlias('Dispatcher', Dispatcher::class); |
|
| 153 | + $this->registerService(Dispatcher::class, function (ContainerInterface $c) { |
|
| 154 | + return new Dispatcher( |
|
| 155 | + $c->get('Protocol'), |
|
| 156 | + $c->get(MiddlewareDispatcher::class), |
|
| 157 | + $c->get(IControllerMethodReflector::class), |
|
| 158 | + $c->get(IRequest::class), |
|
| 159 | + $c->get(IConfig::class), |
|
| 160 | + $c->get(IDBConnection::class), |
|
| 161 | + $c->get(LoggerInterface::class), |
|
| 162 | + $c->get(EventLogger::class), |
|
| 163 | + $c, |
|
| 164 | + ); |
|
| 165 | + }); |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * App Framework default arguments |
|
| 169 | + */ |
|
| 170 | + $this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH'); |
|
| 171 | + $this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept'); |
|
| 172 | + $this->registerParameter('corsMaxAge', 1728000); |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * Middleware |
|
| 176 | + */ |
|
| 177 | + /** @deprecated 32.0.0 */ |
|
| 178 | + $this->registerDeprecatedAlias('MiddlewareDispatcher', MiddlewareDispatcher::class); |
|
| 179 | + $this->registerService(MiddlewareDispatcher::class, function (ContainerInterface $c) { |
|
| 180 | + $server = $this->getServer(); |
|
| 181 | + |
|
| 182 | + $dispatcher = new MiddlewareDispatcher(); |
|
| 183 | + |
|
| 184 | + $dispatcher->registerMiddleware($c->get(CompressionMiddleware::class)); |
|
| 185 | + $dispatcher->registerMiddleware($c->get(NotModifiedMiddleware::class)); |
|
| 186 | + $dispatcher->registerMiddleware($c->get(ReloadExecutionMiddleware::class)); |
|
| 187 | + $dispatcher->registerMiddleware($c->get(SameSiteCookieMiddleware::class)); |
|
| 188 | + $dispatcher->registerMiddleware($c->get(CORSMiddleware::class)); |
|
| 189 | + $dispatcher->registerMiddleware($c->get(OCSMiddleware::class)); |
|
| 190 | + |
|
| 191 | + $dispatcher->registerMiddleware($c->get(FlowV2EphemeralSessionsMiddleware::class)); |
|
| 192 | + |
|
| 193 | + $securityMiddleware = new SecurityMiddleware( |
|
| 194 | + $c->get(IRequest::class), |
|
| 195 | + $c->get(IControllerMethodReflector::class), |
|
| 196 | + $c->get(INavigationManager::class), |
|
| 197 | + $c->get(IURLGenerator::class), |
|
| 198 | + $c->get(LoggerInterface::class), |
|
| 199 | + $c->get('appName'), |
|
| 200 | + $server->getUserSession()->isLoggedIn(), |
|
| 201 | + $c->get(IGroupManager::class), |
|
| 202 | + $c->get(ISubAdmin::class), |
|
| 203 | + $server->getAppManager(), |
|
| 204 | + $server->getL10N('lib'), |
|
| 205 | + $c->get(AuthorizedGroupMapper::class), |
|
| 206 | + $c->get(IUserSession::class), |
|
| 207 | + $c->get(IRemoteAddress::class), |
|
| 208 | + ); |
|
| 209 | + $dispatcher->registerMiddleware($securityMiddleware); |
|
| 210 | + $dispatcher->registerMiddleware($c->get(CSPMiddleware::class)); |
|
| 211 | + $dispatcher->registerMiddleware($c->get(FeaturePolicyMiddleware::class)); |
|
| 212 | + $dispatcher->registerMiddleware($c->get(PasswordConfirmationMiddleware::class)); |
|
| 213 | + $dispatcher->registerMiddleware($c->get(TwoFactorMiddleware::class)); |
|
| 214 | + $dispatcher->registerMiddleware($c->get(BruteForceMiddleware::class)); |
|
| 215 | + $dispatcher->registerMiddleware($c->get(RateLimitingMiddleware::class)); |
|
| 216 | + $dispatcher->registerMiddleware($c->get(PublicShareMiddleware::class)); |
|
| 217 | + $dispatcher->registerMiddleware($c->get(AdditionalScriptsMiddleware::class)); |
|
| 218 | + |
|
| 219 | + $coordinator = $c->get(\OC\AppFramework\Bootstrap\Coordinator::class); |
|
| 220 | + $registrationContext = $coordinator->getRegistrationContext(); |
|
| 221 | + if ($registrationContext !== null) { |
|
| 222 | + $appId = $this->get('appName'); |
|
| 223 | + foreach ($registrationContext->getMiddlewareRegistrations() as $middlewareRegistration) { |
|
| 224 | + if ($middlewareRegistration->getAppId() === $appId |
|
| 225 | + || $middlewareRegistration->isGlobal()) { |
|
| 226 | + $dispatcher->registerMiddleware($c->get($middlewareRegistration->getService())); |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + foreach ($this->middleWares as $middleWare) { |
|
| 231 | + $dispatcher->registerMiddleware($c->get($middleWare)); |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + $dispatcher->registerMiddleware($c->get(SessionMiddleware::class)); |
|
| 235 | + return $dispatcher; |
|
| 236 | + }); |
|
| 237 | + |
|
| 238 | + $this->registerAlias(IAppConfig::class, \OC\AppFramework\Services\AppConfig::class); |
|
| 239 | + $this->registerAlias(IInitialState::class, \OC\AppFramework\Services\InitialState::class); |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * @return \OCP\IServerContainer |
|
| 244 | + */ |
|
| 245 | + public function getServer() { |
|
| 246 | + return $this->server; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * @param string $middleWare |
|
| 251 | + */ |
|
| 252 | + public function registerMiddleWare($middleWare): bool { |
|
| 253 | + if (in_array($middleWare, $this->middleWares, true) !== false) { |
|
| 254 | + return false; |
|
| 255 | + } |
|
| 256 | + $this->middleWares[] = $middleWare; |
|
| 257 | + return true; |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * used to return the appname of the set application |
|
| 262 | + * @return string the name of your application |
|
| 263 | + */ |
|
| 264 | + public function getAppName() { |
|
| 265 | + return $this->query('appName'); |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * @deprecated 12.0.0 use IUserSession->isLoggedIn() |
|
| 270 | + * @return boolean |
|
| 271 | + */ |
|
| 272 | + public function isLoggedIn() { |
|
| 273 | + return \OC::$server->getUserSession()->isLoggedIn(); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * @deprecated 12.0.0 use IGroupManager->isAdmin($userId) |
|
| 278 | + * @return boolean |
|
| 279 | + */ |
|
| 280 | + public function isAdminUser() { |
|
| 281 | + $uid = $this->getUserId(); |
|
| 282 | + return \OC_User::isAdminUser($uid); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + private function getUserId(): string { |
|
| 286 | + return $this->getServer()->getSession()->get('user_id'); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * Register a capability |
|
| 291 | + * |
|
| 292 | + * @param string $serviceName e.g. 'OCA\Files\Capabilities' |
|
| 293 | + */ |
|
| 294 | + public function registerCapability($serviceName) { |
|
| 295 | + $this->query('OC\CapabilitiesManager')->registerCapability(function () use ($serviceName) { |
|
| 296 | + return $this->query($serviceName); |
|
| 297 | + }); |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + public function has($id): bool { |
|
| 301 | + if (parent::has($id)) { |
|
| 302 | + return true; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + if ($this->server->has($id, true)) { |
|
| 306 | + return true; |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + return false; |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + public function query(string $name, bool $autoload = true) { |
|
| 313 | + if ($name === 'AppName' || $name === 'appName') { |
|
| 314 | + return $this->appName; |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + $isServerClass = str_starts_with($name, 'OCP\\') || str_starts_with($name, 'OC\\'); |
|
| 318 | + if ($isServerClass && !$this->has($name)) { |
|
| 319 | + return $this->getServer()->query($name, $autoload); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + try { |
|
| 323 | + return $this->queryNoFallback($name); |
|
| 324 | + } catch (QueryException $firstException) { |
|
| 325 | + try { |
|
| 326 | + return $this->getServer()->query($name, $autoload); |
|
| 327 | + } catch (QueryException $secondException) { |
|
| 328 | + if ($firstException->getCode() === 1) { |
|
| 329 | + throw $secondException; |
|
| 330 | + } |
|
| 331 | + throw $firstException; |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * @param string $name |
|
| 338 | + * @return mixed |
|
| 339 | + * @throws QueryException if the query could not be resolved |
|
| 340 | + */ |
|
| 341 | + public function queryNoFallback($name) { |
|
| 342 | + $name = $this->sanitizeName($name); |
|
| 343 | + |
|
| 344 | + if ($this->offsetExists($name)) { |
|
| 345 | + return parent::query($name); |
|
| 346 | + } elseif ($this->appName === 'settings' && str_starts_with($name, 'OC\\Settings\\')) { |
|
| 347 | + return parent::query($name); |
|
| 348 | + } elseif ($this->appName === 'core' && str_starts_with($name, 'OC\\Core\\')) { |
|
| 349 | + return parent::query($name); |
|
| 350 | + } elseif (str_starts_with($name, \OC\AppFramework\App::buildAppNamespace($this->appName) . '\\')) { |
|
| 351 | + return parent::query($name); |
|
| 352 | + } elseif ( |
|
| 353 | + str_starts_with($name, 'OC\\AppFramework\\Services\\') |
|
| 354 | + || str_starts_with($name, 'OC\\AppFramework\\Middleware\\') |
|
| 355 | + ) { |
|
| 356 | + /* AppFramework services are scoped to the application */ |
|
| 357 | + return parent::query($name); |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + throw new QueryException('Could not resolve ' . $name . '!' |
|
| 361 | + . ' Class can not be instantiated', 1); |
|
| 362 | + } |
|
| 363 | 363 | } |
@@ -96,20 +96,20 @@ discard block |
||
| 96 | 96 | /* Cannot be an alias because Output is not in OCA */ |
| 97 | 97 | $this->registerService(IOutput::class, fn (ContainerInterface $c): IOutput => new Output($c->get('webRoot'))); |
| 98 | 98 | |
| 99 | - $this->registerService(Folder::class, function () { |
|
| 99 | + $this->registerService(Folder::class, function() { |
|
| 100 | 100 | return $this->getServer()->getUserFolder(); |
| 101 | 101 | }); |
| 102 | 102 | |
| 103 | - $this->registerService(IAppData::class, function (ContainerInterface $c): IAppData { |
|
| 103 | + $this->registerService(IAppData::class, function(ContainerInterface $c): IAppData { |
|
| 104 | 104 | return $c->get(IAppDataFactory::class)->get($c->get('appName')); |
| 105 | 105 | }); |
| 106 | 106 | |
| 107 | - $this->registerService(IL10N::class, function (ContainerInterface $c) { |
|
| 107 | + $this->registerService(IL10N::class, function(ContainerInterface $c) { |
|
| 108 | 108 | return $this->getServer()->getL10N($c->get('appName')); |
| 109 | 109 | }); |
| 110 | 110 | |
| 111 | 111 | // Log wrappers |
| 112 | - $this->registerService(LoggerInterface::class, function (ContainerInterface $c) { |
|
| 112 | + $this->registerService(LoggerInterface::class, function(ContainerInterface $c) { |
|
| 113 | 113 | /* Cannot be an alias because it uses LoggerInterface so it would infinite loop */ |
| 114 | 114 | return new ScopedPsrLogger( |
| 115 | 115 | $c->get(PsrLoggerAdapter::class), |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | ); |
| 118 | 118 | }); |
| 119 | 119 | |
| 120 | - $this->registerService(IServerContainer::class, function () { |
|
| 120 | + $this->registerService(IServerContainer::class, function() { |
|
| 121 | 121 | return $this->getServer(); |
| 122 | 122 | }); |
| 123 | 123 | /** @deprecated 32.0.0 */ |
@@ -129,28 +129,28 @@ discard block |
||
| 129 | 129 | $this->registerDeprecatedAlias(IAppContainer::class, ContainerInterface::class); |
| 130 | 130 | |
| 131 | 131 | // commonly used attributes |
| 132 | - $this->registerService('userId', function (ContainerInterface $c): ?string { |
|
| 132 | + $this->registerService('userId', function(ContainerInterface $c): ?string { |
|
| 133 | 133 | return $c->get(ISession::class)->get('user_id'); |
| 134 | 134 | }); |
| 135 | 135 | |
| 136 | - $this->registerService('webRoot', function (ContainerInterface $c): string { |
|
| 136 | + $this->registerService('webRoot', function(ContainerInterface $c): string { |
|
| 137 | 137 | return $c->get(IServerContainer::class)->getWebRoot(); |
| 138 | 138 | }); |
| 139 | 139 | |
| 140 | - $this->registerService('OC_Defaults', function (ContainerInterface $c): object { |
|
| 140 | + $this->registerService('OC_Defaults', function(ContainerInterface $c): object { |
|
| 141 | 141 | return $c->get(IServerContainer::class)->get('ThemingDefaults'); |
| 142 | 142 | }); |
| 143 | 143 | |
| 144 | 144 | /** @deprecated 32.0.0 */ |
| 145 | 145 | $this->registerDeprecatedAlias('Protocol', Http::class); |
| 146 | - $this->registerService(Http::class, function (ContainerInterface $c) { |
|
| 146 | + $this->registerService(Http::class, function(ContainerInterface $c) { |
|
| 147 | 147 | $protocol = $c->get(IRequest::class)->getHttpProtocol(); |
| 148 | 148 | return new Http($_SERVER, $protocol); |
| 149 | 149 | }); |
| 150 | 150 | |
| 151 | 151 | /** @deprecated 32.0.0 */ |
| 152 | 152 | $this->registerDeprecatedAlias('Dispatcher', Dispatcher::class); |
| 153 | - $this->registerService(Dispatcher::class, function (ContainerInterface $c) { |
|
| 153 | + $this->registerService(Dispatcher::class, function(ContainerInterface $c) { |
|
| 154 | 154 | return new Dispatcher( |
| 155 | 155 | $c->get('Protocol'), |
| 156 | 156 | $c->get(MiddlewareDispatcher::class), |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | */ |
| 177 | 177 | /** @deprecated 32.0.0 */ |
| 178 | 178 | $this->registerDeprecatedAlias('MiddlewareDispatcher', MiddlewareDispatcher::class); |
| 179 | - $this->registerService(MiddlewareDispatcher::class, function (ContainerInterface $c) { |
|
| 179 | + $this->registerService(MiddlewareDispatcher::class, function(ContainerInterface $c) { |
|
| 180 | 180 | $server = $this->getServer(); |
| 181 | 181 | |
| 182 | 182 | $dispatcher = new MiddlewareDispatcher(); |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | * @param string $serviceName e.g. 'OCA\Files\Capabilities' |
| 293 | 293 | */ |
| 294 | 294 | public function registerCapability($serviceName) { |
| 295 | - $this->query('OC\CapabilitiesManager')->registerCapability(function () use ($serviceName) { |
|
| 295 | + $this->query('OC\CapabilitiesManager')->registerCapability(function() use ($serviceName) { |
|
| 296 | 296 | return $this->query($serviceName); |
| 297 | 297 | }); |
| 298 | 298 | } |
@@ -347,7 +347,7 @@ discard block |
||
| 347 | 347 | return parent::query($name); |
| 348 | 348 | } elseif ($this->appName === 'core' && str_starts_with($name, 'OC\\Core\\')) { |
| 349 | 349 | return parent::query($name); |
| 350 | - } elseif (str_starts_with($name, \OC\AppFramework\App::buildAppNamespace($this->appName) . '\\')) { |
|
| 350 | + } elseif (str_starts_with($name, \OC\AppFramework\App::buildAppNamespace($this->appName).'\\')) { |
|
| 351 | 351 | return parent::query($name); |
| 352 | 352 | } elseif ( |
| 353 | 353 | str_starts_with($name, 'OC\\AppFramework\\Services\\') |
@@ -357,7 +357,7 @@ discard block |
||
| 357 | 357 | return parent::query($name); |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | - throw new QueryException('Could not resolve ' . $name . '!' |
|
| 360 | + throw new QueryException('Could not resolve '.$name.'!' |
|
| 361 | 361 | . ' Class can not be instantiated', 1); |
| 362 | 362 | } |
| 363 | 363 | } |
@@ -26,224 +26,224 @@ |
||
| 26 | 26 | * Class to dispatch the request to the middleware dispatcher |
| 27 | 27 | */ |
| 28 | 28 | class Dispatcher { |
| 29 | - /** @var MiddlewareDispatcher */ |
|
| 30 | - private $middlewareDispatcher; |
|
| 31 | - |
|
| 32 | - /** @var Http */ |
|
| 33 | - private $protocol; |
|
| 34 | - |
|
| 35 | - /** @var ControllerMethodReflector */ |
|
| 36 | - private $reflector; |
|
| 37 | - |
|
| 38 | - /** @var IRequest */ |
|
| 39 | - private $request; |
|
| 40 | - |
|
| 41 | - /** @var IConfig */ |
|
| 42 | - private $config; |
|
| 43 | - |
|
| 44 | - /** @var ConnectionAdapter */ |
|
| 45 | - private $connection; |
|
| 46 | - |
|
| 47 | - /** @var LoggerInterface */ |
|
| 48 | - private $logger; |
|
| 49 | - |
|
| 50 | - /** @var IEventLogger */ |
|
| 51 | - private $eventLogger; |
|
| 52 | - |
|
| 53 | - private ContainerInterface $appContainer; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @param Http $protocol the http protocol with contains all status headers |
|
| 57 | - * @param MiddlewareDispatcher $middlewareDispatcher the dispatcher which |
|
| 58 | - * runs the middleware |
|
| 59 | - * @param ControllerMethodReflector $reflector the reflector that is used to inject |
|
| 60 | - * the arguments for the controller |
|
| 61 | - * @param IRequest $request the incoming request |
|
| 62 | - * @param IConfig $config |
|
| 63 | - * @param ConnectionAdapter $connection |
|
| 64 | - * @param LoggerInterface $logger |
|
| 65 | - * @param IEventLogger $eventLogger |
|
| 66 | - */ |
|
| 67 | - public function __construct( |
|
| 68 | - Http $protocol, |
|
| 69 | - MiddlewareDispatcher $middlewareDispatcher, |
|
| 70 | - ControllerMethodReflector $reflector, |
|
| 71 | - IRequest $request, |
|
| 72 | - IConfig $config, |
|
| 73 | - ConnectionAdapter $connection, |
|
| 74 | - LoggerInterface $logger, |
|
| 75 | - IEventLogger $eventLogger, |
|
| 76 | - ContainerInterface $appContainer, |
|
| 77 | - ) { |
|
| 78 | - $this->protocol = $protocol; |
|
| 79 | - $this->middlewareDispatcher = $middlewareDispatcher; |
|
| 80 | - $this->reflector = $reflector; |
|
| 81 | - $this->request = $request; |
|
| 82 | - $this->config = $config; |
|
| 83 | - $this->connection = $connection; |
|
| 84 | - $this->logger = $logger; |
|
| 85 | - $this->eventLogger = $eventLogger; |
|
| 86 | - $this->appContainer = $appContainer; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Handles a request and calls the dispatcher on the controller |
|
| 92 | - * @param Controller $controller the controller which will be called |
|
| 93 | - * @param string $methodName the method name which will be called on |
|
| 94 | - * the controller |
|
| 95 | - * @return array $array[0] contains the http status header as a string, |
|
| 96 | - * $array[1] contains response headers as an array, |
|
| 97 | - * $array[2] contains response cookies as an array, |
|
| 98 | - * $array[3] contains the response output as a string, |
|
| 99 | - * $array[4] contains the response object |
|
| 100 | - * @throws \Exception |
|
| 101 | - */ |
|
| 102 | - public function dispatch(Controller $controller, string $methodName): array { |
|
| 103 | - $out = [null, [], null]; |
|
| 104 | - |
|
| 105 | - try { |
|
| 106 | - // prefill reflector with everything that's needed for the |
|
| 107 | - // middlewares |
|
| 108 | - $this->reflector->reflect($controller, $methodName); |
|
| 109 | - |
|
| 110 | - $this->middlewareDispatcher->beforeController($controller, |
|
| 111 | - $methodName); |
|
| 112 | - |
|
| 113 | - $databaseStatsBefore = []; |
|
| 114 | - if ($this->config->getSystemValueBool('debug', false)) { |
|
| 115 | - $databaseStatsBefore = $this->connection->getInner()->getStats(); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - $response = $this->executeController($controller, $methodName); |
|
| 119 | - |
|
| 120 | - if (!empty($databaseStatsBefore)) { |
|
| 121 | - $databaseStatsAfter = $this->connection->getInner()->getStats(); |
|
| 122 | - $numBuilt = $databaseStatsAfter['built'] - $databaseStatsBefore['built']; |
|
| 123 | - $numExecuted = $databaseStatsAfter['executed'] - $databaseStatsBefore['executed']; |
|
| 124 | - |
|
| 125 | - if ($numBuilt > 50) { |
|
| 126 | - $this->logger->debug('Controller {class}::{method} created {count} QueryBuilder objects, please check if they are created inside a loop by accident.', [ |
|
| 127 | - 'class' => get_class($controller), |
|
| 128 | - 'method' => $methodName, |
|
| 129 | - 'count' => $numBuilt, |
|
| 130 | - ]); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - if ($numExecuted > 100) { |
|
| 134 | - $this->logger->warning('Controller {class}::{method} executed {count} queries.', [ |
|
| 135 | - 'class' => get_class($controller), |
|
| 136 | - 'method' => $methodName, |
|
| 137 | - 'count' => $numExecuted, |
|
| 138 | - ]); |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - // if an exception appears, the middleware checks if it can handle the |
|
| 143 | - // exception and creates a response. If no response is created, it is |
|
| 144 | - // assumed that there's no middleware who can handle it and the error is |
|
| 145 | - // thrown again |
|
| 146 | - } catch (\Exception $exception) { |
|
| 147 | - $response = $this->middlewareDispatcher->afterException( |
|
| 148 | - $controller, $methodName, $exception); |
|
| 149 | - } catch (\Throwable $throwable) { |
|
| 150 | - $exception = new \Exception($throwable->getMessage() . ' in file \'' . $throwable->getFile() . '\' line ' . $throwable->getLine(), $throwable->getCode(), $throwable); |
|
| 151 | - $response = $this->middlewareDispatcher->afterException( |
|
| 152 | - $controller, $methodName, $exception); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - $response = $this->middlewareDispatcher->afterController( |
|
| 156 | - $controller, $methodName, $response); |
|
| 157 | - |
|
| 158 | - // depending on the cache object the headers need to be changed |
|
| 159 | - $out[0] = $this->protocol->getStatusHeader($response->getStatus()); |
|
| 160 | - $out[1] = array_merge($response->getHeaders()); |
|
| 161 | - $out[2] = $response->getCookies(); |
|
| 162 | - $out[3] = $this->middlewareDispatcher->beforeOutput( |
|
| 163 | - $controller, $methodName, $response->render() |
|
| 164 | - ); |
|
| 165 | - $out[4] = $response; |
|
| 166 | - |
|
| 167 | - return $out; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Uses the reflected parameters, types and request parameters to execute |
|
| 173 | - * the controller |
|
| 174 | - * @param Controller $controller the controller to be executed |
|
| 175 | - * @param string $methodName the method on the controller that should be executed |
|
| 176 | - * @return Response |
|
| 177 | - */ |
|
| 178 | - private function executeController(Controller $controller, string $methodName): Response { |
|
| 179 | - $arguments = []; |
|
| 180 | - |
|
| 181 | - // valid types that will be cast |
|
| 182 | - $types = ['int', 'integer', 'bool', 'boolean', 'float', 'double']; |
|
| 183 | - |
|
| 184 | - foreach ($this->reflector->getParameters() as $param => $default) { |
|
| 185 | - // try to get the parameter from the request object and cast |
|
| 186 | - // it to the type annotated in the @param annotation |
|
| 187 | - $value = $this->request->getParam($param, $default); |
|
| 188 | - $type = $this->reflector->getType($param); |
|
| 189 | - |
|
| 190 | - // Converted the string `'false'` to false when the controller wants a boolean |
|
| 191 | - if ($value === 'false' && ($type === 'bool' || $type === 'boolean')) { |
|
| 192 | - $value = false; |
|
| 193 | - } elseif ($value !== null && \in_array($type, $types, true)) { |
|
| 194 | - settype($value, $type); |
|
| 195 | - $this->ensureParameterValueSatisfiesRange($param, $value); |
|
| 196 | - } elseif ($value === null && $type !== null && $this->appContainer->has($type)) { |
|
| 197 | - $value = $this->appContainer->get($type); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - $arguments[] = $value; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - $this->eventLogger->start('controller:' . get_class($controller) . '::' . $methodName, 'App framework controller execution'); |
|
| 204 | - $response = \call_user_func_array([$controller, $methodName], $arguments); |
|
| 205 | - $this->eventLogger->end('controller:' . get_class($controller) . '::' . $methodName); |
|
| 206 | - |
|
| 207 | - if (!($response instanceof Response)) { |
|
| 208 | - $this->logger->debug($controller::class . '::' . $methodName . ' returned raw data. Please wrap it in a Response or one of it\'s inheritors.'); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - // format response |
|
| 212 | - if ($response instanceof DataResponse || !($response instanceof Response)) { |
|
| 213 | - // get format from the url format or request format parameter |
|
| 214 | - $format = $this->request->getParam('format'); |
|
| 215 | - |
|
| 216 | - // if none is given try the first Accept header |
|
| 217 | - if ($format === null) { |
|
| 218 | - $headers = $this->request->getHeader('Accept'); |
|
| 219 | - $format = $controller->getResponderByHTTPHeader($headers, null); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - if ($format !== null) { |
|
| 223 | - $response = $controller->buildResponse($response, $format); |
|
| 224 | - } else { |
|
| 225 | - $response = $controller->buildResponse($response); |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - return $response; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * @psalm-param mixed $value |
|
| 234 | - * @throws ParameterOutOfRangeException |
|
| 235 | - */ |
|
| 236 | - private function ensureParameterValueSatisfiesRange(string $param, $value): void { |
|
| 237 | - $rangeInfo = $this->reflector->getRange($param); |
|
| 238 | - if ($rangeInfo) { |
|
| 239 | - if ($value < $rangeInfo['min'] || $value > $rangeInfo['max']) { |
|
| 240 | - throw new ParameterOutOfRangeException( |
|
| 241 | - $param, |
|
| 242 | - $value, |
|
| 243 | - $rangeInfo['min'], |
|
| 244 | - $rangeInfo['max'], |
|
| 245 | - ); |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - } |
|
| 29 | + /** @var MiddlewareDispatcher */ |
|
| 30 | + private $middlewareDispatcher; |
|
| 31 | + |
|
| 32 | + /** @var Http */ |
|
| 33 | + private $protocol; |
|
| 34 | + |
|
| 35 | + /** @var ControllerMethodReflector */ |
|
| 36 | + private $reflector; |
|
| 37 | + |
|
| 38 | + /** @var IRequest */ |
|
| 39 | + private $request; |
|
| 40 | + |
|
| 41 | + /** @var IConfig */ |
|
| 42 | + private $config; |
|
| 43 | + |
|
| 44 | + /** @var ConnectionAdapter */ |
|
| 45 | + private $connection; |
|
| 46 | + |
|
| 47 | + /** @var LoggerInterface */ |
|
| 48 | + private $logger; |
|
| 49 | + |
|
| 50 | + /** @var IEventLogger */ |
|
| 51 | + private $eventLogger; |
|
| 52 | + |
|
| 53 | + private ContainerInterface $appContainer; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @param Http $protocol the http protocol with contains all status headers |
|
| 57 | + * @param MiddlewareDispatcher $middlewareDispatcher the dispatcher which |
|
| 58 | + * runs the middleware |
|
| 59 | + * @param ControllerMethodReflector $reflector the reflector that is used to inject |
|
| 60 | + * the arguments for the controller |
|
| 61 | + * @param IRequest $request the incoming request |
|
| 62 | + * @param IConfig $config |
|
| 63 | + * @param ConnectionAdapter $connection |
|
| 64 | + * @param LoggerInterface $logger |
|
| 65 | + * @param IEventLogger $eventLogger |
|
| 66 | + */ |
|
| 67 | + public function __construct( |
|
| 68 | + Http $protocol, |
|
| 69 | + MiddlewareDispatcher $middlewareDispatcher, |
|
| 70 | + ControllerMethodReflector $reflector, |
|
| 71 | + IRequest $request, |
|
| 72 | + IConfig $config, |
|
| 73 | + ConnectionAdapter $connection, |
|
| 74 | + LoggerInterface $logger, |
|
| 75 | + IEventLogger $eventLogger, |
|
| 76 | + ContainerInterface $appContainer, |
|
| 77 | + ) { |
|
| 78 | + $this->protocol = $protocol; |
|
| 79 | + $this->middlewareDispatcher = $middlewareDispatcher; |
|
| 80 | + $this->reflector = $reflector; |
|
| 81 | + $this->request = $request; |
|
| 82 | + $this->config = $config; |
|
| 83 | + $this->connection = $connection; |
|
| 84 | + $this->logger = $logger; |
|
| 85 | + $this->eventLogger = $eventLogger; |
|
| 86 | + $this->appContainer = $appContainer; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Handles a request and calls the dispatcher on the controller |
|
| 92 | + * @param Controller $controller the controller which will be called |
|
| 93 | + * @param string $methodName the method name which will be called on |
|
| 94 | + * the controller |
|
| 95 | + * @return array $array[0] contains the http status header as a string, |
|
| 96 | + * $array[1] contains response headers as an array, |
|
| 97 | + * $array[2] contains response cookies as an array, |
|
| 98 | + * $array[3] contains the response output as a string, |
|
| 99 | + * $array[4] contains the response object |
|
| 100 | + * @throws \Exception |
|
| 101 | + */ |
|
| 102 | + public function dispatch(Controller $controller, string $methodName): array { |
|
| 103 | + $out = [null, [], null]; |
|
| 104 | + |
|
| 105 | + try { |
|
| 106 | + // prefill reflector with everything that's needed for the |
|
| 107 | + // middlewares |
|
| 108 | + $this->reflector->reflect($controller, $methodName); |
|
| 109 | + |
|
| 110 | + $this->middlewareDispatcher->beforeController($controller, |
|
| 111 | + $methodName); |
|
| 112 | + |
|
| 113 | + $databaseStatsBefore = []; |
|
| 114 | + if ($this->config->getSystemValueBool('debug', false)) { |
|
| 115 | + $databaseStatsBefore = $this->connection->getInner()->getStats(); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + $response = $this->executeController($controller, $methodName); |
|
| 119 | + |
|
| 120 | + if (!empty($databaseStatsBefore)) { |
|
| 121 | + $databaseStatsAfter = $this->connection->getInner()->getStats(); |
|
| 122 | + $numBuilt = $databaseStatsAfter['built'] - $databaseStatsBefore['built']; |
|
| 123 | + $numExecuted = $databaseStatsAfter['executed'] - $databaseStatsBefore['executed']; |
|
| 124 | + |
|
| 125 | + if ($numBuilt > 50) { |
|
| 126 | + $this->logger->debug('Controller {class}::{method} created {count} QueryBuilder objects, please check if they are created inside a loop by accident.', [ |
|
| 127 | + 'class' => get_class($controller), |
|
| 128 | + 'method' => $methodName, |
|
| 129 | + 'count' => $numBuilt, |
|
| 130 | + ]); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + if ($numExecuted > 100) { |
|
| 134 | + $this->logger->warning('Controller {class}::{method} executed {count} queries.', [ |
|
| 135 | + 'class' => get_class($controller), |
|
| 136 | + 'method' => $methodName, |
|
| 137 | + 'count' => $numExecuted, |
|
| 138 | + ]); |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + // if an exception appears, the middleware checks if it can handle the |
|
| 143 | + // exception and creates a response. If no response is created, it is |
|
| 144 | + // assumed that there's no middleware who can handle it and the error is |
|
| 145 | + // thrown again |
|
| 146 | + } catch (\Exception $exception) { |
|
| 147 | + $response = $this->middlewareDispatcher->afterException( |
|
| 148 | + $controller, $methodName, $exception); |
|
| 149 | + } catch (\Throwable $throwable) { |
|
| 150 | + $exception = new \Exception($throwable->getMessage() . ' in file \'' . $throwable->getFile() . '\' line ' . $throwable->getLine(), $throwable->getCode(), $throwable); |
|
| 151 | + $response = $this->middlewareDispatcher->afterException( |
|
| 152 | + $controller, $methodName, $exception); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + $response = $this->middlewareDispatcher->afterController( |
|
| 156 | + $controller, $methodName, $response); |
|
| 157 | + |
|
| 158 | + // depending on the cache object the headers need to be changed |
|
| 159 | + $out[0] = $this->protocol->getStatusHeader($response->getStatus()); |
|
| 160 | + $out[1] = array_merge($response->getHeaders()); |
|
| 161 | + $out[2] = $response->getCookies(); |
|
| 162 | + $out[3] = $this->middlewareDispatcher->beforeOutput( |
|
| 163 | + $controller, $methodName, $response->render() |
|
| 164 | + ); |
|
| 165 | + $out[4] = $response; |
|
| 166 | + |
|
| 167 | + return $out; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Uses the reflected parameters, types and request parameters to execute |
|
| 173 | + * the controller |
|
| 174 | + * @param Controller $controller the controller to be executed |
|
| 175 | + * @param string $methodName the method on the controller that should be executed |
|
| 176 | + * @return Response |
|
| 177 | + */ |
|
| 178 | + private function executeController(Controller $controller, string $methodName): Response { |
|
| 179 | + $arguments = []; |
|
| 180 | + |
|
| 181 | + // valid types that will be cast |
|
| 182 | + $types = ['int', 'integer', 'bool', 'boolean', 'float', 'double']; |
|
| 183 | + |
|
| 184 | + foreach ($this->reflector->getParameters() as $param => $default) { |
|
| 185 | + // try to get the parameter from the request object and cast |
|
| 186 | + // it to the type annotated in the @param annotation |
|
| 187 | + $value = $this->request->getParam($param, $default); |
|
| 188 | + $type = $this->reflector->getType($param); |
|
| 189 | + |
|
| 190 | + // Converted the string `'false'` to false when the controller wants a boolean |
|
| 191 | + if ($value === 'false' && ($type === 'bool' || $type === 'boolean')) { |
|
| 192 | + $value = false; |
|
| 193 | + } elseif ($value !== null && \in_array($type, $types, true)) { |
|
| 194 | + settype($value, $type); |
|
| 195 | + $this->ensureParameterValueSatisfiesRange($param, $value); |
|
| 196 | + } elseif ($value === null && $type !== null && $this->appContainer->has($type)) { |
|
| 197 | + $value = $this->appContainer->get($type); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + $arguments[] = $value; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + $this->eventLogger->start('controller:' . get_class($controller) . '::' . $methodName, 'App framework controller execution'); |
|
| 204 | + $response = \call_user_func_array([$controller, $methodName], $arguments); |
|
| 205 | + $this->eventLogger->end('controller:' . get_class($controller) . '::' . $methodName); |
|
| 206 | + |
|
| 207 | + if (!($response instanceof Response)) { |
|
| 208 | + $this->logger->debug($controller::class . '::' . $methodName . ' returned raw data. Please wrap it in a Response or one of it\'s inheritors.'); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + // format response |
|
| 212 | + if ($response instanceof DataResponse || !($response instanceof Response)) { |
|
| 213 | + // get format from the url format or request format parameter |
|
| 214 | + $format = $this->request->getParam('format'); |
|
| 215 | + |
|
| 216 | + // if none is given try the first Accept header |
|
| 217 | + if ($format === null) { |
|
| 218 | + $headers = $this->request->getHeader('Accept'); |
|
| 219 | + $format = $controller->getResponderByHTTPHeader($headers, null); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + if ($format !== null) { |
|
| 223 | + $response = $controller->buildResponse($response, $format); |
|
| 224 | + } else { |
|
| 225 | + $response = $controller->buildResponse($response); |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + return $response; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * @psalm-param mixed $value |
|
| 234 | + * @throws ParameterOutOfRangeException |
|
| 235 | + */ |
|
| 236 | + private function ensureParameterValueSatisfiesRange(string $param, $value): void { |
|
| 237 | + $rangeInfo = $this->reflector->getRange($param); |
|
| 238 | + if ($rangeInfo) { |
|
| 239 | + if ($value < $rangeInfo['min'] || $value > $rangeInfo['max']) { |
|
| 240 | + throw new ParameterOutOfRangeException( |
|
| 241 | + $param, |
|
| 242 | + $value, |
|
| 243 | + $rangeInfo['min'], |
|
| 244 | + $rangeInfo['max'], |
|
| 245 | + ); |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + } |
|
| 249 | 249 | } |
@@ -13,72 +13,72 @@ |
||
| 13 | 13 | * Very thin wrapper class to make output testable |
| 14 | 14 | */ |
| 15 | 15 | class Output implements IOutput { |
| 16 | - public function __construct( |
|
| 17 | - private string $webRoot, |
|
| 18 | - ) { |
|
| 19 | - } |
|
| 16 | + public function __construct( |
|
| 17 | + private string $webRoot, |
|
| 18 | + ) { |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @param string $out |
|
| 23 | - */ |
|
| 24 | - public function setOutput($out) { |
|
| 25 | - print($out); |
|
| 26 | - } |
|
| 21 | + /** |
|
| 22 | + * @param string $out |
|
| 23 | + */ |
|
| 24 | + public function setOutput($out) { |
|
| 25 | + print($out); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @param string|resource $path or file handle |
|
| 30 | - * |
|
| 31 | - * @return bool false if an error occurred |
|
| 32 | - */ |
|
| 33 | - public function setReadfile($path) { |
|
| 34 | - if (is_resource($path)) { |
|
| 35 | - $output = fopen('php://output', 'w'); |
|
| 36 | - return stream_copy_to_stream($path, $output) > 0; |
|
| 37 | - } else { |
|
| 38 | - return @readfile($path); |
|
| 39 | - } |
|
| 40 | - } |
|
| 28 | + /** |
|
| 29 | + * @param string|resource $path or file handle |
|
| 30 | + * |
|
| 31 | + * @return bool false if an error occurred |
|
| 32 | + */ |
|
| 33 | + public function setReadfile($path) { |
|
| 34 | + if (is_resource($path)) { |
|
| 35 | + $output = fopen('php://output', 'w'); |
|
| 36 | + return stream_copy_to_stream($path, $output) > 0; |
|
| 37 | + } else { |
|
| 38 | + return @readfile($path); |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @param string $header |
|
| 44 | - */ |
|
| 45 | - public function setHeader($header) { |
|
| 46 | - header($header); |
|
| 47 | - } |
|
| 42 | + /** |
|
| 43 | + * @param string $header |
|
| 44 | + */ |
|
| 45 | + public function setHeader($header) { |
|
| 46 | + header($header); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @param int $code sets the http status code |
|
| 51 | - */ |
|
| 52 | - public function setHttpResponseCode($code) { |
|
| 53 | - http_response_code($code); |
|
| 54 | - } |
|
| 49 | + /** |
|
| 50 | + * @param int $code sets the http status code |
|
| 51 | + */ |
|
| 52 | + public function setHttpResponseCode($code) { |
|
| 53 | + http_response_code($code); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @return int returns the current http response code |
|
| 58 | - */ |
|
| 59 | - public function getHttpResponseCode() { |
|
| 60 | - return http_response_code(); |
|
| 61 | - } |
|
| 56 | + /** |
|
| 57 | + * @return int returns the current http response code |
|
| 58 | + */ |
|
| 59 | + public function getHttpResponseCode() { |
|
| 60 | + return http_response_code(); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @param string $name |
|
| 65 | - * @param string $value |
|
| 66 | - * @param int $expire |
|
| 67 | - * @param string $path |
|
| 68 | - * @param string $domain |
|
| 69 | - * @param bool $secure |
|
| 70 | - * @param bool $httpOnly |
|
| 71 | - */ |
|
| 72 | - public function setCookie($name, $value, $expire, $path, $domain, $secure, $httpOnly, $sameSite = 'Lax') { |
|
| 73 | - $path = $this->webRoot ? : '/'; |
|
| 63 | + /** |
|
| 64 | + * @param string $name |
|
| 65 | + * @param string $value |
|
| 66 | + * @param int $expire |
|
| 67 | + * @param string $path |
|
| 68 | + * @param string $domain |
|
| 69 | + * @param bool $secure |
|
| 70 | + * @param bool $httpOnly |
|
| 71 | + */ |
|
| 72 | + public function setCookie($name, $value, $expire, $path, $domain, $secure, $httpOnly, $sameSite = 'Lax') { |
|
| 73 | + $path = $this->webRoot ? : '/'; |
|
| 74 | 74 | |
| 75 | - setcookie($name, $value, [ |
|
| 76 | - 'expires' => $expire, |
|
| 77 | - 'path' => $path, |
|
| 78 | - 'domain' => $domain, |
|
| 79 | - 'secure' => $secure, |
|
| 80 | - 'httponly' => $httpOnly, |
|
| 81 | - 'samesite' => $sameSite |
|
| 82 | - ]); |
|
| 83 | - } |
|
| 75 | + setcookie($name, $value, [ |
|
| 76 | + 'expires' => $expire, |
|
| 77 | + 'path' => $path, |
|
| 78 | + 'domain' => $domain, |
|
| 79 | + 'secure' => $secure, |
|
| 80 | + 'httponly' => $httpOnly, |
|
| 81 | + 'samesite' => $sameSite |
|
| 82 | + ]); |
|
| 83 | + } |
|
| 84 | 84 | } |
@@ -14,70 +14,70 @@ |
||
| 14 | 14 | use OCP\AppFramework\Middleware; |
| 15 | 15 | |
| 16 | 16 | class SameSiteCookieMiddleware extends Middleware { |
| 17 | - public function __construct( |
|
| 18 | - private Request $request, |
|
| 19 | - private ControllerMethodReflector $reflector, |
|
| 20 | - ) { |
|
| 21 | - } |
|
| 17 | + public function __construct( |
|
| 18 | + private Request $request, |
|
| 19 | + private ControllerMethodReflector $reflector, |
|
| 20 | + ) { |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - public function beforeController($controller, $methodName) { |
|
| 24 | - $requestUri = $this->request->getScriptName(); |
|
| 25 | - $processingScript = explode('/', $requestUri); |
|
| 26 | - $processingScript = $processingScript[count($processingScript) - 1]; |
|
| 23 | + public function beforeController($controller, $methodName) { |
|
| 24 | + $requestUri = $this->request->getScriptName(); |
|
| 25 | + $processingScript = explode('/', $requestUri); |
|
| 26 | + $processingScript = $processingScript[count($processingScript) - 1]; |
|
| 27 | 27 | |
| 28 | - if ($processingScript !== 'index.php') { |
|
| 29 | - return; |
|
| 30 | - } |
|
| 28 | + if ($processingScript !== 'index.php') { |
|
| 29 | + return; |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - $noSSC = $this->reflector->hasAnnotation('NoSameSiteCookieRequired'); |
|
| 33 | - if ($noSSC) { |
|
| 34 | - return; |
|
| 35 | - } |
|
| 32 | + $noSSC = $this->reflector->hasAnnotation('NoSameSiteCookieRequired'); |
|
| 33 | + if ($noSSC) { |
|
| 34 | + return; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - if (!$this->request->passesLaxCookieCheck()) { |
|
| 38 | - throw new LaxSameSiteCookieFailedException(); |
|
| 39 | - } |
|
| 40 | - } |
|
| 37 | + if (!$this->request->passesLaxCookieCheck()) { |
|
| 38 | + throw new LaxSameSiteCookieFailedException(); |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - public function afterException($controller, $methodName, \Exception $exception) { |
|
| 43 | - if ($exception instanceof LaxSameSiteCookieFailedException) { |
|
| 44 | - $response = new Response(); |
|
| 45 | - $response->setStatus(Http::STATUS_FOUND); |
|
| 46 | - $response->addHeader('Location', $this->request->getRequestUri()); |
|
| 42 | + public function afterException($controller, $methodName, \Exception $exception) { |
|
| 43 | + if ($exception instanceof LaxSameSiteCookieFailedException) { |
|
| 44 | + $response = new Response(); |
|
| 45 | + $response->setStatus(Http::STATUS_FOUND); |
|
| 46 | + $response->addHeader('Location', $this->request->getRequestUri()); |
|
| 47 | 47 | |
| 48 | - $this->setSameSiteCookie(); |
|
| 48 | + $this->setSameSiteCookie(); |
|
| 49 | 49 | |
| 50 | - return $response; |
|
| 51 | - } |
|
| 50 | + return $response; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - throw $exception; |
|
| 54 | - } |
|
| 53 | + throw $exception; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - protected function setSameSiteCookie(): void { |
|
| 57 | - $cookieParams = $this->request->getCookieParams(); |
|
| 58 | - $secureCookie = ($cookieParams['secure'] === true) ? 'secure; ' : ''; |
|
| 59 | - $policies = [ |
|
| 60 | - 'lax', |
|
| 61 | - 'strict', |
|
| 62 | - ]; |
|
| 56 | + protected function setSameSiteCookie(): void { |
|
| 57 | + $cookieParams = $this->request->getCookieParams(); |
|
| 58 | + $secureCookie = ($cookieParams['secure'] === true) ? 'secure; ' : ''; |
|
| 59 | + $policies = [ |
|
| 60 | + 'lax', |
|
| 61 | + 'strict', |
|
| 62 | + ]; |
|
| 63 | 63 | |
| 64 | - // Append __Host to the cookie if it meets the requirements |
|
| 65 | - $cookiePrefix = ''; |
|
| 66 | - if ($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
| 67 | - $cookiePrefix = '__Host-'; |
|
| 68 | - } |
|
| 64 | + // Append __Host to the cookie if it meets the requirements |
|
| 65 | + $cookiePrefix = ''; |
|
| 66 | + if ($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
| 67 | + $cookiePrefix = '__Host-'; |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - foreach ($policies as $policy) { |
|
| 71 | - header( |
|
| 72 | - sprintf( |
|
| 73 | - 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
| 74 | - $cookiePrefix, |
|
| 75 | - $policy, |
|
| 76 | - $cookieParams['path'], |
|
| 77 | - $policy |
|
| 78 | - ), |
|
| 79 | - false |
|
| 80 | - ); |
|
| 81 | - } |
|
| 82 | - } |
|
| 70 | + foreach ($policies as $policy) { |
|
| 71 | + header( |
|
| 72 | + sprintf( |
|
| 73 | + 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
| 74 | + $cookiePrefix, |
|
| 75 | + $policy, |
|
| 76 | + $cookieParams['path'], |
|
| 77 | + $policy |
|
| 78 | + ), |
|
| 79 | + false |
|
| 80 | + ); |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | 83 | } |
@@ -29,218 +29,218 @@ |
||
| 29 | 29 | * Handles all the dependency injection, controllers and output flow |
| 30 | 30 | */ |
| 31 | 31 | class App { |
| 32 | - /** @var string[] */ |
|
| 33 | - private static $nameSpaceCache = []; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Turns an app id into a namespace by either reading the appinfo.xml's |
|
| 37 | - * namespace tag or uppercasing the appid's first letter |
|
| 38 | - * @param string $appId the app id |
|
| 39 | - * @param string $topNamespace the namespace which should be prepended to |
|
| 40 | - * the transformed app id, defaults to OCA\ |
|
| 41 | - * @return string the starting namespace for the app |
|
| 42 | - */ |
|
| 43 | - public static function buildAppNamespace(string $appId, string $topNamespace = 'OCA\\'): string { |
|
| 44 | - // Hit the cache! |
|
| 45 | - if (isset(self::$nameSpaceCache[$appId])) { |
|
| 46 | - return $topNamespace . self::$nameSpaceCache[$appId]; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - $appInfo = \OCP\Server::get(IAppManager::class)->getAppInfo($appId); |
|
| 50 | - if (isset($appInfo['namespace'])) { |
|
| 51 | - self::$nameSpaceCache[$appId] = trim($appInfo['namespace']); |
|
| 52 | - } else { |
|
| 53 | - if ($appId !== 'spreed') { |
|
| 54 | - // if the tag is not found, fall back to uppercasing the first letter |
|
| 55 | - self::$nameSpaceCache[$appId] = ucfirst($appId); |
|
| 56 | - } else { |
|
| 57 | - // For the Talk app (appid spreed) the above fallback doesn't work. |
|
| 58 | - // This leads to a problem when trying to install it freshly, |
|
| 59 | - // because the apps namespace is already registered before the |
|
| 60 | - // app is downloaded from the appstore, because of the hackish |
|
| 61 | - // global route index.php/call/{token} which is registered via |
|
| 62 | - // the core/routes.php so it does not have the app namespace. |
|
| 63 | - // @ref https://github.com/nextcloud/server/pull/19433 |
|
| 64 | - self::$nameSpaceCache[$appId] = 'Talk'; |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - return $topNamespace . self::$nameSpaceCache[$appId]; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - public static function getAppIdForClass(string $className, string $topNamespace = 'OCA\\'): ?string { |
|
| 72 | - if (!str_starts_with($className, $topNamespace)) { |
|
| 73 | - return null; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - foreach (self::$nameSpaceCache as $appId => $namespace) { |
|
| 77 | - if (str_starts_with($className, $topNamespace . $namespace . '\\')) { |
|
| 78 | - return $appId; |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - return null; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Shortcut for calling a controller method and printing the result |
|
| 88 | - * |
|
| 89 | - * @param string $controllerName the name of the controller under which it is |
|
| 90 | - * stored in the DI container |
|
| 91 | - * @param string $methodName the method that you want to call |
|
| 92 | - * @param DIContainer $container an instance of a pimple container. |
|
| 93 | - * @param array $urlParams list of URL parameters (optional) |
|
| 94 | - * @throws HintException |
|
| 95 | - */ |
|
| 96 | - public static function main(string $controllerName, string $methodName, DIContainer $container, ?array $urlParams = null) { |
|
| 97 | - /** @var IProfiler $profiler */ |
|
| 98 | - $profiler = $container->get(IProfiler::class); |
|
| 99 | - $eventLogger = $container->get(IEventLogger::class); |
|
| 100 | - // Disable profiler on the profiler UI |
|
| 101 | - $profiler->setEnabled($profiler->isEnabled() && !is_null($urlParams) && isset($urlParams['_route']) && !str_starts_with($urlParams['_route'], 'profiler.')); |
|
| 102 | - if ($profiler->isEnabled()) { |
|
| 103 | - \OC::$server->get(IEventLogger::class)->activate(); |
|
| 104 | - $profiler->add(new RoutingDataCollector($container['appName'], $controllerName, $methodName)); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - $eventLogger->start('app:controller:params', 'Gather controller parameters'); |
|
| 108 | - |
|
| 109 | - if (!is_null($urlParams)) { |
|
| 110 | - /** @var Request $request */ |
|
| 111 | - $request = $container->get(IRequest::class); |
|
| 112 | - $request->setUrlParameters($urlParams); |
|
| 113 | - } elseif (isset($container['urlParams']) && !is_null($container['urlParams'])) { |
|
| 114 | - /** @var Request $request */ |
|
| 115 | - $request = $container->get(IRequest::class); |
|
| 116 | - $request->setUrlParameters($container['urlParams']); |
|
| 117 | - } |
|
| 118 | - $appName = $container['appName']; |
|
| 119 | - |
|
| 120 | - $eventLogger->end('app:controller:params'); |
|
| 121 | - |
|
| 122 | - $eventLogger->start('app:controller:load', 'Load app controller'); |
|
| 123 | - |
|
| 124 | - // first try $controllerName then go for \OCA\AppName\Controller\$controllerName |
|
| 125 | - try { |
|
| 126 | - $controller = $container->get($controllerName); |
|
| 127 | - } catch (QueryException $e) { |
|
| 128 | - if (str_contains($controllerName, '\\Controller\\')) { |
|
| 129 | - // This is from a global registered app route that is not enabled. |
|
| 130 | - [/*OC(A)*/, $app, /* Controller/Name*/] = explode('\\', $controllerName, 3); |
|
| 131 | - throw new HintException('App ' . strtolower($app) . ' is not enabled'); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - if ($appName === 'core') { |
|
| 135 | - $appNameSpace = 'OC\\Core'; |
|
| 136 | - } else { |
|
| 137 | - $appNameSpace = self::buildAppNamespace($appName); |
|
| 138 | - } |
|
| 139 | - $controllerName = $appNameSpace . '\\Controller\\' . $controllerName; |
|
| 140 | - $controller = $container->query($controllerName); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - $eventLogger->end('app:controller:load'); |
|
| 144 | - |
|
| 145 | - $eventLogger->start('app:controller:dispatcher', 'Initialize dispatcher and pre-middleware'); |
|
| 146 | - |
|
| 147 | - // initialize the dispatcher and run all the middleware before the controller |
|
| 148 | - /** @var Dispatcher $dispatcher */ |
|
| 149 | - $dispatcher = $container['Dispatcher']; |
|
| 150 | - |
|
| 151 | - $eventLogger->end('app:controller:dispatcher'); |
|
| 152 | - |
|
| 153 | - $eventLogger->start('app:controller:run', 'Run app controller'); |
|
| 154 | - |
|
| 155 | - [ |
|
| 156 | - $httpHeaders, |
|
| 157 | - $responseHeaders, |
|
| 158 | - $responseCookies, |
|
| 159 | - $output, |
|
| 160 | - $response |
|
| 161 | - ] = $dispatcher->dispatch($controller, $methodName); |
|
| 162 | - |
|
| 163 | - $eventLogger->end('app:controller:run'); |
|
| 164 | - |
|
| 165 | - $io = $container[IOutput::class]; |
|
| 166 | - |
|
| 167 | - if ($profiler->isEnabled()) { |
|
| 168 | - $eventLogger->end('runtime'); |
|
| 169 | - $profile = $profiler->collect($container->get(IRequest::class), $response); |
|
| 170 | - $profiler->saveProfile($profile); |
|
| 171 | - $io->setHeader('X-Debug-Token:' . $profile->getToken()); |
|
| 172 | - $io->setHeader('Server-Timing: token;desc="' . $profile->getToken() . '"'); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - if (!is_null($httpHeaders)) { |
|
| 176 | - $io->setHeader($httpHeaders); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - foreach ($responseHeaders as $name => $value) { |
|
| 180 | - $io->setHeader($name . ': ' . $value); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - foreach ($responseCookies as $name => $value) { |
|
| 184 | - $expireDate = null; |
|
| 185 | - if ($value['expireDate'] instanceof \DateTime) { |
|
| 186 | - $expireDate = $value['expireDate']->getTimestamp(); |
|
| 187 | - } |
|
| 188 | - $sameSite = $value['sameSite'] ?? 'Lax'; |
|
| 189 | - |
|
| 190 | - $io->setCookie( |
|
| 191 | - $name, |
|
| 192 | - $value['value'], |
|
| 193 | - $expireDate, |
|
| 194 | - $container->getServer()->getWebRoot(), |
|
| 195 | - null, |
|
| 196 | - $container->getServer()->getRequest()->getServerProtocol() === 'https', |
|
| 197 | - true, |
|
| 198 | - $sameSite |
|
| 199 | - ); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /* |
|
| 32 | + /** @var string[] */ |
|
| 33 | + private static $nameSpaceCache = []; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Turns an app id into a namespace by either reading the appinfo.xml's |
|
| 37 | + * namespace tag or uppercasing the appid's first letter |
|
| 38 | + * @param string $appId the app id |
|
| 39 | + * @param string $topNamespace the namespace which should be prepended to |
|
| 40 | + * the transformed app id, defaults to OCA\ |
|
| 41 | + * @return string the starting namespace for the app |
|
| 42 | + */ |
|
| 43 | + public static function buildAppNamespace(string $appId, string $topNamespace = 'OCA\\'): string { |
|
| 44 | + // Hit the cache! |
|
| 45 | + if (isset(self::$nameSpaceCache[$appId])) { |
|
| 46 | + return $topNamespace . self::$nameSpaceCache[$appId]; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + $appInfo = \OCP\Server::get(IAppManager::class)->getAppInfo($appId); |
|
| 50 | + if (isset($appInfo['namespace'])) { |
|
| 51 | + self::$nameSpaceCache[$appId] = trim($appInfo['namespace']); |
|
| 52 | + } else { |
|
| 53 | + if ($appId !== 'spreed') { |
|
| 54 | + // if the tag is not found, fall back to uppercasing the first letter |
|
| 55 | + self::$nameSpaceCache[$appId] = ucfirst($appId); |
|
| 56 | + } else { |
|
| 57 | + // For the Talk app (appid spreed) the above fallback doesn't work. |
|
| 58 | + // This leads to a problem when trying to install it freshly, |
|
| 59 | + // because the apps namespace is already registered before the |
|
| 60 | + // app is downloaded from the appstore, because of the hackish |
|
| 61 | + // global route index.php/call/{token} which is registered via |
|
| 62 | + // the core/routes.php so it does not have the app namespace. |
|
| 63 | + // @ref https://github.com/nextcloud/server/pull/19433 |
|
| 64 | + self::$nameSpaceCache[$appId] = 'Talk'; |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + return $topNamespace . self::$nameSpaceCache[$appId]; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + public static function getAppIdForClass(string $className, string $topNamespace = 'OCA\\'): ?string { |
|
| 72 | + if (!str_starts_with($className, $topNamespace)) { |
|
| 73 | + return null; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + foreach (self::$nameSpaceCache as $appId => $namespace) { |
|
| 77 | + if (str_starts_with($className, $topNamespace . $namespace . '\\')) { |
|
| 78 | + return $appId; |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + return null; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Shortcut for calling a controller method and printing the result |
|
| 88 | + * |
|
| 89 | + * @param string $controllerName the name of the controller under which it is |
|
| 90 | + * stored in the DI container |
|
| 91 | + * @param string $methodName the method that you want to call |
|
| 92 | + * @param DIContainer $container an instance of a pimple container. |
|
| 93 | + * @param array $urlParams list of URL parameters (optional) |
|
| 94 | + * @throws HintException |
|
| 95 | + */ |
|
| 96 | + public static function main(string $controllerName, string $methodName, DIContainer $container, ?array $urlParams = null) { |
|
| 97 | + /** @var IProfiler $profiler */ |
|
| 98 | + $profiler = $container->get(IProfiler::class); |
|
| 99 | + $eventLogger = $container->get(IEventLogger::class); |
|
| 100 | + // Disable profiler on the profiler UI |
|
| 101 | + $profiler->setEnabled($profiler->isEnabled() && !is_null($urlParams) && isset($urlParams['_route']) && !str_starts_with($urlParams['_route'], 'profiler.')); |
|
| 102 | + if ($profiler->isEnabled()) { |
|
| 103 | + \OC::$server->get(IEventLogger::class)->activate(); |
|
| 104 | + $profiler->add(new RoutingDataCollector($container['appName'], $controllerName, $methodName)); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + $eventLogger->start('app:controller:params', 'Gather controller parameters'); |
|
| 108 | + |
|
| 109 | + if (!is_null($urlParams)) { |
|
| 110 | + /** @var Request $request */ |
|
| 111 | + $request = $container->get(IRequest::class); |
|
| 112 | + $request->setUrlParameters($urlParams); |
|
| 113 | + } elseif (isset($container['urlParams']) && !is_null($container['urlParams'])) { |
|
| 114 | + /** @var Request $request */ |
|
| 115 | + $request = $container->get(IRequest::class); |
|
| 116 | + $request->setUrlParameters($container['urlParams']); |
|
| 117 | + } |
|
| 118 | + $appName = $container['appName']; |
|
| 119 | + |
|
| 120 | + $eventLogger->end('app:controller:params'); |
|
| 121 | + |
|
| 122 | + $eventLogger->start('app:controller:load', 'Load app controller'); |
|
| 123 | + |
|
| 124 | + // first try $controllerName then go for \OCA\AppName\Controller\$controllerName |
|
| 125 | + try { |
|
| 126 | + $controller = $container->get($controllerName); |
|
| 127 | + } catch (QueryException $e) { |
|
| 128 | + if (str_contains($controllerName, '\\Controller\\')) { |
|
| 129 | + // This is from a global registered app route that is not enabled. |
|
| 130 | + [/*OC(A)*/, $app, /* Controller/Name*/] = explode('\\', $controllerName, 3); |
|
| 131 | + throw new HintException('App ' . strtolower($app) . ' is not enabled'); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + if ($appName === 'core') { |
|
| 135 | + $appNameSpace = 'OC\\Core'; |
|
| 136 | + } else { |
|
| 137 | + $appNameSpace = self::buildAppNamespace($appName); |
|
| 138 | + } |
|
| 139 | + $controllerName = $appNameSpace . '\\Controller\\' . $controllerName; |
|
| 140 | + $controller = $container->query($controllerName); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + $eventLogger->end('app:controller:load'); |
|
| 144 | + |
|
| 145 | + $eventLogger->start('app:controller:dispatcher', 'Initialize dispatcher and pre-middleware'); |
|
| 146 | + |
|
| 147 | + // initialize the dispatcher and run all the middleware before the controller |
|
| 148 | + /** @var Dispatcher $dispatcher */ |
|
| 149 | + $dispatcher = $container['Dispatcher']; |
|
| 150 | + |
|
| 151 | + $eventLogger->end('app:controller:dispatcher'); |
|
| 152 | + |
|
| 153 | + $eventLogger->start('app:controller:run', 'Run app controller'); |
|
| 154 | + |
|
| 155 | + [ |
|
| 156 | + $httpHeaders, |
|
| 157 | + $responseHeaders, |
|
| 158 | + $responseCookies, |
|
| 159 | + $output, |
|
| 160 | + $response |
|
| 161 | + ] = $dispatcher->dispatch($controller, $methodName); |
|
| 162 | + |
|
| 163 | + $eventLogger->end('app:controller:run'); |
|
| 164 | + |
|
| 165 | + $io = $container[IOutput::class]; |
|
| 166 | + |
|
| 167 | + if ($profiler->isEnabled()) { |
|
| 168 | + $eventLogger->end('runtime'); |
|
| 169 | + $profile = $profiler->collect($container->get(IRequest::class), $response); |
|
| 170 | + $profiler->saveProfile($profile); |
|
| 171 | + $io->setHeader('X-Debug-Token:' . $profile->getToken()); |
|
| 172 | + $io->setHeader('Server-Timing: token;desc="' . $profile->getToken() . '"'); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + if (!is_null($httpHeaders)) { |
|
| 176 | + $io->setHeader($httpHeaders); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + foreach ($responseHeaders as $name => $value) { |
|
| 180 | + $io->setHeader($name . ': ' . $value); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + foreach ($responseCookies as $name => $value) { |
|
| 184 | + $expireDate = null; |
|
| 185 | + if ($value['expireDate'] instanceof \DateTime) { |
|
| 186 | + $expireDate = $value['expireDate']->getTimestamp(); |
|
| 187 | + } |
|
| 188 | + $sameSite = $value['sameSite'] ?? 'Lax'; |
|
| 189 | + |
|
| 190 | + $io->setCookie( |
|
| 191 | + $name, |
|
| 192 | + $value['value'], |
|
| 193 | + $expireDate, |
|
| 194 | + $container->getServer()->getWebRoot(), |
|
| 195 | + null, |
|
| 196 | + $container->getServer()->getRequest()->getServerProtocol() === 'https', |
|
| 197 | + true, |
|
| 198 | + $sameSite |
|
| 199 | + ); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /* |
|
| 203 | 203 | * Status 204 does not have a body and no Content Length |
| 204 | 204 | * Status 304 does not have a body and does not need a Content Length |
| 205 | 205 | * https://tools.ietf.org/html/rfc7230#section-3.3 |
| 206 | 206 | * https://tools.ietf.org/html/rfc7230#section-3.3.2 |
| 207 | 207 | */ |
| 208 | - $emptyResponse = false; |
|
| 209 | - if (preg_match('/^HTTP\/\d\.\d (\d{3}) .*$/', $httpHeaders, $matches)) { |
|
| 210 | - $status = (int)$matches[1]; |
|
| 211 | - if ($status === Http::STATUS_NO_CONTENT || $status === Http::STATUS_NOT_MODIFIED) { |
|
| 212 | - $emptyResponse = true; |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - if (!$emptyResponse) { |
|
| 217 | - if ($response instanceof ICallbackResponse) { |
|
| 218 | - $response->callback($io); |
|
| 219 | - } elseif (!is_null($output)) { |
|
| 220 | - $io->setHeader('Content-Length: ' . strlen($output)); |
|
| 221 | - $io->setOutput($output); |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * Shortcut for calling a controller method and printing the result. |
|
| 228 | - * Similar to App:main except that no headers will be sent. |
|
| 229 | - * |
|
| 230 | - * @param string $controllerName the name of the controller under which it is |
|
| 231 | - * stored in the DI container |
|
| 232 | - * @param string $methodName the method that you want to call |
|
| 233 | - * @param array $urlParams an array with variables extracted from the routes |
|
| 234 | - * @param DIContainer $container an instance of a pimple container. |
|
| 235 | - */ |
|
| 236 | - public static function part(string $controllerName, string $methodName, array $urlParams, |
|
| 237 | - DIContainer $container) { |
|
| 238 | - $container['urlParams'] = $urlParams; |
|
| 239 | - $controller = $container[$controllerName]; |
|
| 240 | - |
|
| 241 | - $dispatcher = $container['Dispatcher']; |
|
| 242 | - |
|
| 243 | - [, , $output] = $dispatcher->dispatch($controller, $methodName); |
|
| 244 | - return $output; |
|
| 245 | - } |
|
| 208 | + $emptyResponse = false; |
|
| 209 | + if (preg_match('/^HTTP\/\d\.\d (\d{3}) .*$/', $httpHeaders, $matches)) { |
|
| 210 | + $status = (int)$matches[1]; |
|
| 211 | + if ($status === Http::STATUS_NO_CONTENT || $status === Http::STATUS_NOT_MODIFIED) { |
|
| 212 | + $emptyResponse = true; |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + if (!$emptyResponse) { |
|
| 217 | + if ($response instanceof ICallbackResponse) { |
|
| 218 | + $response->callback($io); |
|
| 219 | + } elseif (!is_null($output)) { |
|
| 220 | + $io->setHeader('Content-Length: ' . strlen($output)); |
|
| 221 | + $io->setOutput($output); |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * Shortcut for calling a controller method and printing the result. |
|
| 228 | + * Similar to App:main except that no headers will be sent. |
|
| 229 | + * |
|
| 230 | + * @param string $controllerName the name of the controller under which it is |
|
| 231 | + * stored in the DI container |
|
| 232 | + * @param string $methodName the method that you want to call |
|
| 233 | + * @param array $urlParams an array with variables extracted from the routes |
|
| 234 | + * @param DIContainer $container an instance of a pimple container. |
|
| 235 | + */ |
|
| 236 | + public static function part(string $controllerName, string $methodName, array $urlParams, |
|
| 237 | + DIContainer $container) { |
|
| 238 | + $container['urlParams'] = $urlParams; |
|
| 239 | + $controller = $container[$controllerName]; |
|
| 240 | + |
|
| 241 | + $dispatcher = $container['Dispatcher']; |
|
| 242 | + |
|
| 243 | + [, , $output] = $dispatcher->dispatch($controller, $methodName); |
|
| 244 | + return $output; |
|
| 245 | + } |
|
| 246 | 246 | } |