Skip to content

Commit

Permalink
chore: Replace \OC::$server->query with \OCP\Server::get in /lib
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
  • Loading branch information
ChristophWurst committed Jul 6, 2023
1 parent 5538a40 commit 1471911
Show file tree
Hide file tree
Showing 21 changed files with 46 additions and 45 deletions.
6 changes: 3 additions & 3 deletions lib/private/Activity/Manager.php
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Authentication/TwoFactorAuth/ProviderLoader.php
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/private/Collaboration/Resources/Listener.php
Expand Up @@ -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);
};
Expand All @@ -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);
});
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions lib/private/Console/Application.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion lib/private/DB/MigrationService.php
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Cache/Cache.php
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Node/Folder.php
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Preview/WatcherConnector.php
Expand Up @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions lib/private/Repair.php
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Search/Provider/File.php
Expand Up @@ -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 [];
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Session/Internal.php
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions lib/private/Setup.php
Expand Up @@ -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'])) {
Expand Down Expand Up @@ -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());
Expand Down
6 changes: 3 additions & 3 deletions lib/private/TemplateLayout.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand All @@ -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()) {
Expand Down
2 changes: 1 addition & 1 deletion lib/private/User/Database.php
Expand Up @@ -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);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions lib/private/User/User.php
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -299,15 +299,15 @@ 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();
$notification->setUser($this->uid);
\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 */
Expand Down
12 changes: 6 additions & 6 deletions lib/private/legacy/OC_App.php
Expand Up @@ -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;
Expand All @@ -65,6 +64,7 @@
use OC\Installer;
use OC\Repair;
use OC\Repair\Events\RepairErrorEvent;
use Psr\Container\ContainerExceptionInterface;
use Psr\Log\LoggerInterface;

/**
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)) {
Expand All @@ -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(),
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/private/legacy/OC_Files.php
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion lib/private/legacy/OC_Template.php
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion lib/private/legacy/template/functions.php
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/public/AppFramework/Http/Response.php
Expand Up @@ -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));
Expand Down
5 changes: 3 additions & 2 deletions lib/public/Util.php
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 1471911

Please sign in to comment.