From 14719110b9c795a95b23c2278168b9d6123b1a62 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Tue, 6 Jun 2023 11:09:24 +0200 Subject: [PATCH] chore: Replace \OC::$server->query with \OCP\Server::get in /lib Signed-off-by: Christoph Wurst --- lib/private/Activity/Manager.php | 6 +++--- .../Authentication/TwoFactorAuth/ProviderLoader.php | 4 ++-- lib/private/Collaboration/Resources/Listener.php | 6 +++--- lib/private/Console/Application.php | 6 +++--- lib/private/DB/MigrationService.php | 2 +- lib/private/Files/Cache/Cache.php | 2 +- lib/private/Files/Node/Folder.php | 2 +- lib/private/Preview/WatcherConnector.php | 2 +- lib/private/Repair.php | 6 +++--- lib/private/Search/Provider/File.php | 4 ++-- lib/private/Session/Internal.php | 2 +- lib/private/Setup.php | 10 +++++----- lib/private/TemplateLayout.php | 6 +++--- lib/private/User/Database.php | 2 +- lib/private/User/User.php | 6 +++--- lib/private/legacy/OC_App.php | 12 ++++++------ lib/private/legacy/OC_Files.php | 2 +- lib/private/legacy/OC_Template.php | 2 +- lib/private/legacy/template/functions.php | 2 +- lib/public/AppFramework/Http/Response.php | 2 +- lib/public/Util.php | 5 +++-- 21 files changed, 46 insertions(+), 45 deletions(-) diff --git a/lib/private/Activity/Manager.php b/lib/private/Activity/Manager.php index 00b2ba434a841..a7d24510d530e 100644 --- a/lib/private/Activity/Manager.php +++ b/lib/private/Activity/Manager.php @@ -192,7 +192,7 @@ public function registerFilter(string $filter): void { public function getFilters(): array { foreach ($this->filterClasses as $class => $false) { /** @var IFilter $filter */ - $filter = \OC::$server->query($class); + $filter = \OCP\Server::get($class); if (!$filter instanceof IFilter) { throw new \InvalidArgumentException('Invalid activity filter registered'); @@ -242,7 +242,7 @@ public function registerProvider(string $provider): void { public function getProviders(): array { foreach ($this->providerClasses as $class => $false) { /** @var IProvider $provider */ - $provider = \OC::$server->query($class); + $provider = \OCP\Server::get($class); if (!$provider instanceof IProvider) { throw new \InvalidArgumentException('Invalid activity provider registered'); @@ -276,7 +276,7 @@ public function registerSetting(string $setting): void { public function getSettings(): array { foreach ($this->settingsClasses as $class => $false) { /** @var ISetting $setting */ - $setting = \OC::$server->query($class); + $setting = \OCP\Server::get($class); if ($setting instanceof ISetting) { if (!$setting instanceof ActivitySettings) { diff --git a/lib/private/Authentication/TwoFactorAuth/ProviderLoader.php b/lib/private/Authentication/TwoFactorAuth/ProviderLoader.php index 25cdc387f614e..efd92f8ba3010 100644 --- a/lib/private/Authentication/TwoFactorAuth/ProviderLoader.php +++ b/lib/private/Authentication/TwoFactorAuth/ProviderLoader.php @@ -66,7 +66,7 @@ public function getProviders(IUser $user): array { foreach ($providerClasses as $class) { try { $this->loadTwoFactorApp($appId); - $provider = OC::$server->query($class); + $provider = \OCP\Server::get($class); $providers[$provider->getId()] = $provider; } catch (QueryException $exc) { // Provider class can not be resolved @@ -80,7 +80,7 @@ public function getProviders(IUser $user): array { foreach ($registeredProviders as $provider) { try { $this->loadTwoFactorApp($provider->getAppId()); - $provider = OC::$server->query($provider->getService()); + $provider = \OCP\Server::get($provider->getService()); $providers[$provider->getId()] = $provider; } catch (QueryException $exc) { // Provider class can not be resolved diff --git a/lib/private/Collaboration/Resources/Listener.php b/lib/private/Collaboration/Resources/Listener.php index b9f1e72cbfaa1..d3b2f012a2916 100644 --- a/lib/private/Collaboration/Resources/Listener.php +++ b/lib/private/Collaboration/Resources/Listener.php @@ -40,7 +40,7 @@ public static function register(SymfonyAdapter $symfonyDispatcher, IEventDispatc /** @var IUser $user */ $user = $event->getArgument('user'); /** @var IManager $resourceManager */ - $resourceManager = \OC::$server->query(IManager::class); + $resourceManager = \OCP\Server::get(IManager::class); $resourceManager->invalidateAccessCacheForUser($user); }; @@ -51,7 +51,7 @@ public static function register(SymfonyAdapter $symfonyDispatcher, IEventDispatc /** @var IUser $user */ $user = $event->getSubject(); /** @var IManager $resourceManager */ - $resourceManager = \OC::$server->query(IManager::class); + $resourceManager = \OCP\Server::get(IManager::class); $resourceManager->invalidateAccessCacheForUser($user); }); @@ -60,7 +60,7 @@ public static function register(SymfonyAdapter $symfonyDispatcher, IEventDispatc /** @var IGroup $group */ $group = $event->getSubject(); /** @var IManager $resourceManager */ - $resourceManager = \OC::$server->query(IManager::class); + $resourceManager = \OCP\Server::get(IManager::class); foreach ($group->getUsers() as $user) { $resourceManager->invalidateAccessCacheForUser($user); diff --git a/lib/private/Console/Application.php b/lib/private/Console/Application.php index 11515f268660c..113f0507ef534 100644 --- a/lib/private/Console/Application.php +++ b/lib/private/Console/Application.php @@ -33,12 +33,12 @@ use OC\MemoryInfo; use OC\NeedsUpdateException; use OC_App; -use OCP\AppFramework\QueryException; use OCP\App\IAppManager; use OCP\Console\ConsoleEvent; use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; use OCP\IRequest; +use Psr\Container\ContainerExceptionInterface; use Psr\Log\LoggerInterface; use Symfony\Component\Console\Application as SymfonyApplication; use Symfony\Component\Console\Input\InputInterface; @@ -216,8 +216,8 @@ public function run(InputInterface $input = null, OutputInterface $output = null private function loadCommandsFromInfoXml($commands) { foreach ($commands as $command) { try { - $c = \OC::$server->query($command); - } catch (QueryException $e) { + $c = \OCP\Server::get($command); + } catch (ContainerExceptionInterface $e) { if (class_exists($command)) { try { $c = new $command(); diff --git a/lib/private/DB/MigrationService.php b/lib/private/DB/MigrationService.php index 7993730b23006..3afe2f689f94e 100644 --- a/lib/private/DB/MigrationService.php +++ b/lib/private/DB/MigrationService.php @@ -487,7 +487,7 @@ public function describeMigrationStep($to = 'latest') { protected function createInstance($version) { $class = $this->getClass($version); try { - $s = \OC::$server->query($class); + $s = \OCP\Server::get($class); if (!$s instanceof IMigrationStep) { throw new \InvalidArgumentException('Not a valid migration'); diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index 5aa0568363136..4770e168bfbec 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -125,7 +125,7 @@ public function __construct(IStorage $storage) { $this->mimetypeLoader = \OC::$server->getMimeTypeLoader(); $this->connection = \OC::$server->getDatabaseConnection(); $this->eventDispatcher = \OC::$server->get(IEventDispatcher::class); - $this->querySearchHelper = \OC::$server->query(QuerySearchHelper::class); + $this->querySearchHelper = \OCP\Server::get(QuerySearchHelper::class); } protected function getQueryBuilder() { diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php index 3622f336047d6..ccd10da9d0c3c 100644 --- a/lib/private/Files/Node/Folder.php +++ b/lib/private/Files/Node/Folder.php @@ -204,7 +204,7 @@ private function queryFromOperator(ISearchOperator $operator, string $uid = null $user = null; } else { /** @var IUserManager $userManager */ - $userManager = \OC::$server->query(IUserManager::class); + $userManager = \OCP\Server::get(IUserManager::class); $user = $userManager->get($uid); } return new SearchQuery($operator, $limit, $offset, [], $user); diff --git a/lib/private/Preview/WatcherConnector.php b/lib/private/Preview/WatcherConnector.php index d0eafed42c123..ffbdf825211f1 100644 --- a/lib/private/Preview/WatcherConnector.php +++ b/lib/private/Preview/WatcherConnector.php @@ -52,7 +52,7 @@ public function __construct(IRootFolder $root, * @return Watcher */ private function getWatcher(): Watcher { - return \OC::$server->query(Watcher::class); + return \OCP\Server::get(Watcher::class); } public function connectWatcher() { diff --git a/lib/private/Repair.php b/lib/private/Repair.php index 330fa241b1e09..9c6a6cd00f270 100644 --- a/lib/private/Repair.php +++ b/lib/private/Repair.php @@ -191,14 +191,14 @@ public static function getRepairSteps(): array { new FixMountStorages(\OC::$server->getDatabaseConnection()), new UpdateLanguageCodes(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()), new AddLogRotateJob(\OC::$server->getJobList()), - new ClearFrontendCaches(\OC::$server->getMemCacheFactory(), \OC::$server->query(JSCombiner::class)), + new ClearFrontendCaches(\OC::$server->getMemCacheFactory(), \OCP\Server::get(JSCombiner::class)), \OCP\Server::get(ClearGeneratedAvatarCache::class), new AddPreviewBackgroundCleanupJob(\OC::$server->getJobList()), new AddCleanupUpdaterBackupsJob(\OC::$server->getJobList()), new CleanupCardDAVPhotoCache(\OC::$server->getConfig(), \OC::$server->getAppDataDir('dav-photocache'), \OC::$server->get(LoggerInterface::class)), new AddClenupLoginFlowV2BackgroundJob(\OC::$server->getJobList()), - new RemoveLinkShares(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig(), \OC::$server->getGroupManager(), \OC::$server->getNotificationManager(), \OC::$server->query(ITimeFactory::class)), - new ClearCollectionsAccessCache(\OC::$server->getConfig(), \OC::$server->query(IManager::class)), + new RemoveLinkShares(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig(), \OC::$server->getGroupManager(), \OC::$server->getNotificationManager(), \OCP\Server::get(ITimeFactory::class)), + new ClearCollectionsAccessCache(\OC::$server->getConfig(), \OCP\Server::get(IManager::class)), \OCP\Server::get(ResetGeneratedAvatarFlag::class), \OCP\Server::get(EncryptionLegacyCipher::class), \OCP\Server::get(EncryptionMigration::class), diff --git a/lib/private/Search/Provider/File.php b/lib/private/Search/Provider/File.php index 7046fea33d29e..5ec0132cc031b 100644 --- a/lib/private/Search/Provider/File.php +++ b/lib/private/Search/Provider/File.php @@ -53,9 +53,9 @@ class File extends PagedProvider { */ public function search($query, int $limit = null, int $offset = null) { /** @var IRootFolder $rootFolder */ - $rootFolder = \OC::$server->query(IRootFolder::class); + $rootFolder = \OCP\Server::get(IRootFolder::class); /** @var IUserSession $userSession */ - $userSession = \OC::$server->query(IUserSession::class); + $userSession = \OCP\Server::get(IUserSession::class); $user = $userSession->getUser(); if (!$user) { return []; diff --git a/lib/private/Session/Internal.php b/lib/private/Session/Internal.php index e0f92c2e887b6..e8e2a4f2d8e43 100644 --- a/lib/private/Session/Internal.php +++ b/lib/private/Session/Internal.php @@ -149,7 +149,7 @@ public function regenerateId(bool $deleteOldSession = true, bool $updateToken = $newId = $this->getId(); /** @var IProvider $tokenProvider */ - $tokenProvider = \OC::$server->query(IProvider::class); + $tokenProvider = \OCP\Server::get(IProvider::class); try { $tokenProvider->renewSessionToken($oldId, $newId); diff --git a/lib/private/Setup.php b/lib/private/Setup.php index 3a2e7614dd92e..d847125cc7983 100644 --- a/lib/private/Setup.php +++ b/lib/private/Setup.php @@ -424,20 +424,20 @@ public function install($options) { unlink(\OC::$configDir.'/CAN_INSTALL'); } - $bootstrapCoordinator = \OC::$server->query(\OC\AppFramework\Bootstrap\Coordinator::class); + $bootstrapCoordinator = \OCP\Server::get(\OC\AppFramework\Bootstrap\Coordinator::class); $bootstrapCoordinator->runInitialRegistration(); // Create a session token for the newly created user // The token provider requires a working db, so it's not injected on setup /* @var $userSession User\Session */ $userSession = \OC::$server->getUserSession(); - $provider = \OC::$server->query(PublicKeyTokenProvider::class); + $provider = \OCP\Server::get(PublicKeyTokenProvider::class); $userSession->setTokenProvider($provider); $userSession->login($username, $password); $userSession->createSessionToken($request, $userSession->getUser()->getUID(), $username, $password); $session = $userSession->getSession(); - $session->set('last-password-confirm', \OC::$server->query(ITimeFactory::class)->getTime()); + $session->set('last-password-confirm', \OCP\Server::get(ITimeFactory::class)->getTime()); // Set email for admin if (!empty($options['adminemail'])) { @@ -506,10 +506,10 @@ public static function updateHtaccess() { $config, \OC::$server->get(IniGetWrapper::class), \OC::$server->getL10N('lib'), - \OC::$server->query(Defaults::class), + \OCP\Server::get(Defaults::class), \OC::$server->get(LoggerInterface::class), \OC::$server->getSecureRandom(), - \OC::$server->query(Installer::class) + \OCP\Server::get(Installer::class) ); $htaccessContent = file_get_contents($setupHelper->pathToHtaccess()); diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php index 5c6488cbc0fb9..658a85152bf49 100644 --- a/lib/private/TemplateLayout.php +++ b/lib/private/TemplateLayout.php @@ -190,7 +190,7 @@ public function __construct($renderAs, $appId = '') { $this->assign('bodyid', 'body-public'); /** @var IRegistry $subscription */ - $subscription = \OC::$server->query(IRegistry::class); + $subscription = \OCP\Server::get(IRegistry::class); $showSimpleSignup = $this->config->getSystemValueBool('simpleSignUpLink.shown', true); if ($showSimpleSignup && $subscription->delegateHasValidSubscription()) { $showSimpleSignup = false; @@ -226,7 +226,7 @@ public function __construct($renderAs, $appId = '') { // see https://github.com/nextcloud/server/pull/22636 for details $jsConfigHelper = new JSConfigHelper( \OC::$server->getL10N('lib'), - \OC::$server->query(Defaults::class), + \OCP\Server::get(Defaults::class), \OC::$server->getAppManager(), \OC::$server->getSession(), \OC::$server->getUserSession()->getUser(), @@ -235,7 +235,7 @@ public function __construct($renderAs, $appId = '') { \OC::$server->get(IniGetWrapper::class), \OC::$server->getURLGenerator(), \OC::$server->getCapabilitiesManager(), - \OC::$server->query(IInitialStateService::class) + \OCP\Server::get(IInitialStateService::class) ); $config = $jsConfigHelper->getConfig(); if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) { diff --git a/lib/private/User/Database.php b/lib/private/User/Database.php index 615c392395e88..9ef1bc67a58d0 100644 --- a/lib/private/User/Database.php +++ b/lib/private/User/Database.php @@ -97,7 +97,7 @@ class Database extends ABackend implements public function __construct($eventDispatcher = null, $table = 'users') { $this->cache = new CappedMemoryCache(); $this->table = $table; - $this->eventDispatcher = $eventDispatcher ? $eventDispatcher : \OC::$server->query(IEventDispatcher::class); + $this->eventDispatcher = $eventDispatcher ? $eventDispatcher : \OCP\Server::get(IEventDispatcher::class); } /** diff --git a/lib/private/User/User.php b/lib/private/User/User.php index 8f3192d070e78..dc4cdec1235b0 100644 --- a/lib/private/User/User.php +++ b/lib/private/User/User.php @@ -117,7 +117,7 @@ public function __construct(string $uid, ?UserInterface $backend, EventDispatche $this->urlGenerator = \OC::$server->getURLGenerator(); } // TODO: inject - $this->dispatcher = \OC::$server->query(IEventDispatcher::class); + $this->dispatcher = \OCP\Server::get(IEventDispatcher::class); } /** @@ -299,7 +299,7 @@ public function delete() { \OC::$server->getCommentsManager()->deleteReadMarksFromUser($this); /** @var AvatarManager $avatarManager */ - $avatarManager = \OC::$server->query(AvatarManager::class); + $avatarManager = \OCP\Server::get(AvatarManager::class); $avatarManager->deleteUserAvatar($this->uid); $notification = \OC::$server->getNotificationManager()->createNotification(); @@ -307,7 +307,7 @@ public function delete() { \OC::$server->getNotificationManager()->markProcessed($notification); /** @var AccountManager $accountManager */ - $accountManager = \OC::$server->query(AccountManager::class); + $accountManager = \OCP\Server::get(AccountManager::class); $accountManager->deleteUser($this); /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ diff --git a/lib/private/legacy/OC_App.php b/lib/private/legacy/OC_App.php index a1aeb50bbf475..9337492e77574 100644 --- a/lib/private/legacy/OC_App.php +++ b/lib/private/legacy/OC_App.php @@ -52,7 +52,6 @@ */ use OCP\App\Events\AppUpdateEvent; -use OCP\AppFramework\QueryException; use OCP\App\IAppManager; use OCP\App\ManagerEvent; use OCP\Authentication\IAlternativeLogin; @@ -65,6 +64,7 @@ use OC\Installer; use OC\Repair; use OC\Repair\Events\RepairErrorEvent; +use Psr\Container\ContainerExceptionInterface; use Psr\Log\LoggerInterface; /** @@ -255,7 +255,7 @@ public function enable(string $appId, array $groups = []) { // Check if app is already downloaded /** @var Installer $installer */ - $installer = \OC::$server->query(Installer::class); + $installer = \OCP\Server::get(Installer::class); $isDownloaded = $installer->isDownloaded($appId); if (!$isDownloaded) { @@ -463,7 +463,7 @@ public static function registerLogIn(array $entry) { */ public static function getAlternativeLogIns(): array { /** @var Coordinator $bootstrapCoordinator */ - $bootstrapCoordinator = \OC::$server->query(Coordinator::class); + $bootstrapCoordinator = \OCP\Server::get(Coordinator::class); foreach ($bootstrapCoordinator->getRegistrationContext()->getAlternativeLogins() as $registration) { if (!in_array(IAlternativeLogin::class, class_implements($registration->getService()), true)) { @@ -477,8 +477,8 @@ public static function getAlternativeLogIns(): array { try { /** @var IAlternativeLogin $provider */ - $provider = \OC::$server->query($registration->getService()); - } catch (QueryException $e) { + $provider = \OCP\Server::get($registration->getService()); + } catch (ContainerExceptionInterface $e) { \OC::$server->getLogger()->logException($e, [ 'message' => 'Alternative login option {option} can not be initialised.', 'option' => $registration->getService(), @@ -543,7 +543,7 @@ public static function getAllApps(): array { */ public function getSupportedApps(): array { /** @var \OCP\Support\Subscription\IRegistry $subscriptionRegistry */ - $subscriptionRegistry = \OC::$server->query(\OCP\Support\Subscription\IRegistry::class); + $subscriptionRegistry = \OCP\Server::get(\OCP\Support\Subscription\IRegistry::class); $supportedApps = $subscriptionRegistry->delegateGetSupportedApps(); return $supportedApps; } diff --git a/lib/private/legacy/OC_Files.php b/lib/private/legacy/OC_Files.php index b6c45e164ef0c..7bc1fab94b6b4 100644 --- a/lib/private/legacy/OC_Files.php +++ b/lib/private/legacy/OC_Files.php @@ -333,7 +333,7 @@ private static function getSingleFile($view, $dir, $name, $params) { $rangeArray = self::parseHttpRangeHeader(substr($params['range'], 6), $fileSize); } - $dispatcher = \OC::$server->query(IEventDispatcher::class); + $dispatcher = \OCP\Server::get(IEventDispatcher::class); $event = new BeforeDirectFileDownloadEvent($filename); $dispatcher->dispatchTyped($event); diff --git a/lib/private/legacy/OC_Template.php b/lib/private/legacy/OC_Template.php index 0c9fa1ccc0cdc..70477ea6a0627 100644 --- a/lib/private/legacy/OC_Template.php +++ b/lib/private/legacy/OC_Template.php @@ -83,7 +83,7 @@ public function __construct($app, $name, $renderAs = TemplateResponse::RENDER_AS $parts = explode('/', $app); // fix translation when app is something like core/lostpassword $l10n = \OC::$server->getL10N($parts[0]); /** @var \OCP\Defaults $themeDefaults */ - $themeDefaults = \OC::$server->query(\OCP\Defaults::class); + $themeDefaults = \OCP\Server::get(\OCP\Defaults::class); [$path, $template] = $this->findTemplate($theme, $app, $name); diff --git a/lib/private/legacy/template/functions.php b/lib/private/legacy/template/functions.php index 7081bd4f74371..57c3a83412802 100644 --- a/lib/private/legacy/template/functions.php +++ b/lib/private/legacy/template/functions.php @@ -308,7 +308,7 @@ function strip_time($timestamp) { */ function relative_modified_date($timestamp, $fromTime = null, $dateOnly = false) { /** @var \OC\DateTimeFormatter $formatter */ - $formatter = \OC::$server->query('DateTimeFormatter'); + $formatter = \OCP\Server::get('DateTimeFormatter'); if ($dateOnly) { return $formatter->formatDateSpan($timestamp, $fromTime); diff --git a/lib/public/AppFramework/Http/Response.php b/lib/public/AppFramework/Http/Response.php index d14d68d32b374..dd4f2c5341860 100644 --- a/lib/public/AppFramework/Http/Response.php +++ b/lib/public/AppFramework/Http/Response.php @@ -119,7 +119,7 @@ public function cacheFor(int $cacheSeconds, bool $public = false, bool $immutabl // Set expires header $expires = new \DateTime(); /** @var ITimeFactory $time */ - $time = \OC::$server->query(ITimeFactory::class); + $time = \OCP\Server::get(ITimeFactory::class); $expires->setTimestamp($time->getTime()); $expires->add(new \DateInterval('PT'.$cacheSeconds.'S')); $this->addHeader('Expires', $expires->format(\DateTimeInterface::RFC2822)); diff --git a/lib/public/Util.php b/lib/public/Util.php index 5bb126d26b042..63ed9e835c770 100644 --- a/lib/public/Util.php +++ b/lib/public/Util.php @@ -49,6 +49,7 @@ use OC\AppScriptDependency; use OC\AppScriptSort; use bantu\IniGetWrapper\IniGetWrapper; +use Psr\Container\ContainerExceptionInterface; /** * This class provides different helper functions to make the life of a developer easier @@ -83,9 +84,9 @@ public static function getVersion() { public static function hasExtendedSupport(): bool { try { /** @var \OCP\Support\Subscription\IRegistry */ - $subscriptionRegistry = \OC::$server->query(\OCP\Support\Subscription\IRegistry::class); + $subscriptionRegistry = \OCP\Server::get(\OCP\Support\Subscription\IRegistry::class); return $subscriptionRegistry->delegateHasExtendedSupport(); - } catch (AppFramework\QueryException $e) { + } catch (ContainerExceptionInterface $e) { } return \OC::$server->getConfig()->getSystemValueBool('extendedSupport', false); }