Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor OC\Server::query #40156

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion console.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function exceptionHandler($exception) {
\OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class),
\OC::$server->getRequest(),
\OC::$server->get(\Psr\Log\LoggerInterface::class),
\OC::$server->query(\OC\MemoryInfo::class)
\OC::$server->get(\OC\MemoryInfo::class)
);
$application->loadCommands(new ArgvInput(), new ConsoleOutput());
$application->run();
Expand Down
2 changes: 1 addition & 1 deletion core/Command/App/Enable.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private function enableApp(string $appId, array $groupIds, bool $forceEnable, Ou

try {
/** @var Installer $installer */
$installer = \OC::$server->query(Installer::class);
$installer = \OC::$server->get(Installer::class);

if (false === $installer->isDownloaded($appId)) {
$installer->downloadApp($appId);
Expand Down
2 changes: 1 addition & 1 deletion core/Command/App/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

try {
/** @var Installer $installer */
$installer = \OC::$server->query(Installer::class);
$installer = \OC::$server->get(Installer::class);
$installer->downloadApp($appId, $input->getOption('allow-unstable'));
$result = $installer->installApp($appId, $forceEnable);
} catch (\Exception $e) {
Expand Down
4 changes: 2 additions & 2 deletions core/Command/Maintenance/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->config,
$this->iniGetWrapper,
$server->getL10N('lib'),
$server->query(Defaults::class),
$server->get(Defaults::class),
$server->get(LoggerInterface::class),
$server->getSecureRandom(),
\OC::$server->query(Installer::class)
\OC::$server->get(Installer::class)
);
$sysInfo = $setupHelper->getSystemInfo(true);
$errors = $sysInfo['errors'];
Expand Down
2 changes: 1 addition & 1 deletion core/ajax/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function handleRepairFeedback(Event $event): void {
$config,
\OC::$server->getIntegrityCodeChecker(),
$logger,
\OC::$server->query(\OC\Installer::class)
\OC::$server->get(\OC\Installer::class)
);
$incompatibleApps = [];

Expand Down
24 changes: 12 additions & 12 deletions core/register_command.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,22 @@
$application->add(new OC\Core\Command\App\Install());
$application->add(new OC\Core\Command\App\GetPath());
$application->add(new OC\Core\Command\App\ListApps(\OC::$server->getAppManager()));
$application->add(new OC\Core\Command\App\Remove(\OC::$server->getAppManager(), \OC::$server->query(\OC\Installer::class), \OC::$server->get(LoggerInterface::class)));
$application->add(\OC::$server->query(\OC\Core\Command\App\Update::class));
$application->add(new OC\Core\Command\App\Remove(\OC::$server->getAppManager(), \OC::$server->get(\OC\Installer::class), \OC::$server->get(LoggerInterface::class)));

Check notice

Code scanning / Psalm

DeprecatedMethod Note

The method OC\Server::getAppManager has been marked as deprecated
$application->add(\OC::$server->get(\OC\Core\Command\App\Update::class));

$application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Cleanup::class));
$application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Enforce::class));
$application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Enable::class));
$application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Disable::class));
$application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\State::class));
$application->add(\OC::$server->get(\OC\Core\Command\TwoFactorAuth\Cleanup::class));
$application->add(\OC::$server->get(\OC\Core\Command\TwoFactorAuth\Enforce::class));
$application->add(\OC::$server->get(\OC\Core\Command\TwoFactorAuth\Enable::class));
$application->add(\OC::$server->get(\OC\Core\Command\TwoFactorAuth\Disable::class));
$application->add(\OC::$server->get(\OC\Core\Command\TwoFactorAuth\State::class));

$application->add(new OC\Core\Command\Background\Cron(\OC::$server->getConfig()));
$application->add(new OC\Core\Command\Background\WebCron(\OC::$server->getConfig()));
$application->add(new OC\Core\Command\Background\Ajax(\OC::$server->getConfig()));
$application->add(new OC\Core\Command\Background\Job(\OC::$server->getJobList(), \OC::$server->getLogger()));
$application->add(new OC\Core\Command\Background\ListCommand(\OC::$server->getJobList()));

$application->add(\OC::$server->query(\OC\Core\Command\Broadcast\Test::class));
$application->add(\OC::$server->get(\OC\Core\Command\Broadcast\Test::class));

$application->add(new OC\Core\Command\Config\App\DeleteConfig(\OC::$server->getConfig()));
$application->add(new OC\Core\Command\Config\App\GetConfig(\OC::$server->getConfig()));
Expand Down Expand Up @@ -169,18 +169,18 @@
$application->add(new OC\Core\Command\Maintenance\UpdateHtaccess());
$application->add(new OC\Core\Command\Maintenance\UpdateTheme(\OC::$server->getMimeTypeDetector(), \OC::$server->getMemCacheFactory()));

$application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class), \OC::$server->query(\OC\Installer::class)));
$application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class), \OC::$server->get(\OC\Installer::class)));
$application->add(new OC\Core\Command\Maintenance\Repair(
new \OC\Repair([], \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class), \OC::$server->get(LoggerInterface::class)),
\OC::$server->getConfig(),
\OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class),
\OC::$server->getAppManager()
));
$application->add(\OC::$server->query(OC\Core\Command\Maintenance\RepairShareOwnership::class));
$application->add(\OC::$server->get(OC\Core\Command\Maintenance\RepairShareOwnership::class));

$application->add(\OC::$server->get(\OC\Core\Command\Preview\Generate::class));
$application->add(\OC::$server->query(\OC\Core\Command\Preview\Repair::class));
$application->add(\OC::$server->query(\OC\Core\Command\Preview\ResetRenderedTexts::class));
$application->add(\OC::$server->get(\OC\Core\Command\Preview\Repair::class));
$application->add(\OC::$server->get(\OC\Core\Command\Preview\ResetRenderedTexts::class));

$application->add(new OC\Core\Command\User\Add(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
$application->add(new OC\Core\Command\User\Delete(\OC::$server->getUserManager()));
Expand Down
2 changes: 1 addition & 1 deletion core/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
use OC\Core\Application;

/** @var Application $application */
$application = \OC::$server->query(Application::class);
$application = \OC::$server->get(Application::class);
$application->registerRoutes($this, [
'routes' => [
['name' => 'lost#email', 'url' => '/lostpassword/email', 'verb' => 'POST'],
Expand Down
4 changes: 2 additions & 2 deletions lib/private/AppFramework/Bootstrap/Coordinator.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private function registerApps(array $appIds): void {
$this->eventLogger->start("bootstrap:register_app:$appId:application", "Load `Application` instance for $appId");
try {
/** @var IBootstrap|App $application */
$apps[$appId] = $application = $this->serverContainer->query($applicationClassName);
$apps[$appId] = $application = $this->serverContainer->get($applicationClassName);
} catch (QueryException $e) {
// Weird, but ok
$this->eventLogger->end("bootstrap:register_app:$appId");
Expand Down Expand Up @@ -193,7 +193,7 @@ public function bootApp(string $appId): void {
$this->eventLogger->start('bootstrap:boot_app:' . $appId, "Call `Application::boot` for $appId");
try {
/** @var App $application */
$application = $this->serverContainer->query($applicationClassName);
$application = $this->serverContainer->get($applicationClassName);
if ($application instanceof IBootstrap) {
/** @var BootContext $context */
$context = new BootContext($application->getContainer());
Expand Down
16 changes: 8 additions & 8 deletions lib/private/AppFramework/DependencyInjection/DIContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
);
});
$this->registerService(ILogger::class, function (ContainerInterface $c) {
return new OC\AppFramework\Logger($this->server->query(ILogger::class), $c->get('AppName'));
return new OC\AppFramework\Logger($this->server->get(ILogger::class), $c->get('AppName'));
});

$this->registerService(IServerContainer::class, function () {
Expand Down Expand Up @@ -253,7 +253,7 @@
$c->get('AppName'),
$server->getUserSession()->isLoggedIn(),
$this->getUserId() !== null && $server->getGroupManager()->isAdmin($this->getUserId()),
$server->getUserSession()->getUser() !== null && $server->query(ISubAdmin::class)->isSubAdmin($server->getUserSession()->getUser()),
$server->getUserSession()->getUser() !== null && $server->get(ISubAdmin::class)->isSubAdmin($server->getUserSession()->getUser()),
$server->getAppManager(),
$server->getL10N('lib'),
$c->get(AuthorizedGroupMapper::class),
Expand All @@ -262,13 +262,13 @@
$dispatcher->registerMiddleware($securityMiddleware);
$dispatcher->registerMiddleware(
new OC\AppFramework\Middleware\Security\CSPMiddleware(
$server->query(OC\Security\CSP\ContentSecurityPolicyManager::class),
$server->query(OC\Security\CSP\ContentSecurityPolicyNonceManager::class),
$server->query(OC\Security\CSRF\CsrfTokenManager::class)
$server->get(OC\Security\CSP\ContentSecurityPolicyManager::class),
$server->get(OC\Security\CSP\ContentSecurityPolicyNonceManager::class),
$server->get(OC\Security\CSRF\CsrfTokenManager::class)
)
);
$dispatcher->registerMiddleware(
$server->query(OC\AppFramework\Middleware\Security\FeaturePolicyMiddleware::class)
$server->get(OC\AppFramework\Middleware\Security\FeaturePolicyMiddleware::class)
);
$dispatcher->registerMiddleware(
new OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware(
Expand Down Expand Up @@ -459,15 +459,15 @@

$isServerClass = str_starts_with($name, 'OCP\\') || str_starts_with($name, 'OC\\');
if ($isServerClass && !$this->has($name)) {
return $this->getServer()->query($name, $autoload);
return $this->getServer()->get($name, $autoload);
}

Check failure on line 463 in lib/private/AppFramework/DependencyInjection/DIContainer.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

TooManyArguments

lib/private/AppFramework/DependencyInjection/DIContainer.php:463:31: TooManyArguments: Too many arguments for method Psr\Container\ContainerInterface::get - saw 2 (see https://psalm.dev/026)

try {
return $this->queryNoFallback($name);
} catch (QueryException $firstException) {
try {
return $this->getServer()->query($name, $autoload);
return $this->getServer()->get($name, $autoload);
} catch (QueryException $secondException) {

Check failure on line 470 in lib/private/AppFramework/DependencyInjection/DIContainer.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

TooManyArguments

lib/private/AppFramework/DependencyInjection/DIContainer.php:470:32: TooManyArguments: Too many arguments for method Psr\Container\ContainerInterface::get - saw 2 (see https://psalm.dev/026)
if ($firstException->getCode() === 1) {
throw $secondException;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Calendar/Resource/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function getBackends():array {
continue;
}

$this->initializedBackends[$backend] = $this->server->query($backend);
$this->initializedBackends[$backend] = $this->server->get($backend);
}

return array_values($this->initializedBackends);
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Calendar/Room/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function getBackends():array {
* The backend might have services injected that can't be build from the
* server container.
*/
$this->initializedBackends[$backend] = $this->server->query($backend);
$this->initializedBackends[$backend] = $this->server->get($backend);
}

return array_values($this->initializedBackends);
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Collaboration/Resources/ProviderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function getResourceProviders(): array {
if ($this->providers !== []) {
foreach ($this->providers as $provider) {
try {
$this->providerInstances[] = $this->serverContainer->query($provider);
$this->providerInstances[] = $this->serverContainer->get($provider);
} catch (QueryException $e) {
$this->logger->error("Could not query resource provider $provider: " . $e->getMessage(), [
'exception' => $e,
Expand Down
2 changes: 1 addition & 1 deletion lib/private/EventDispatcher/ServiceEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function __invoke(Event $event) {
// TODO: fetch from the app containers, otherwise any custom services,
// parameters and aliases won't be resolved.
// See https://github.com/nextcloud/server/issues/27793 for details.
$this->service = $this->container->query($this->class);
$this->service = $this->container->get($this->class);
} catch (QueryException $e) {
$this->logger->error(
sprintf(
Expand Down
2 changes: 1 addition & 1 deletion lib/private/InitialStateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private function loadLazyStates(): void {
$initialStates = $context->getInitialStates();
foreach ($initialStates as $initialState) {
try {
$provider = $this->container->query($initialState->getService());
$provider = $this->container->get($initialState->getService());
} catch (QueryException $e) {
// Log an continue. We can be fault tolerant here.
$this->logger->error('Could not load initial state provider dynamically: ' . $e->getMessage(), [
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Search/SearchComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private function loadLazyProviders(): void {
foreach ($registrations as $registration) {
try {
/** @var IProvider $provider */
$provider = $this->container->query($registration->getService());
$provider = $this->container->get($registration->getService());
$this->providers[$provider->getId()] = $provider;
} catch (QueryException $e) {
// Log an continue. We can be fault tolerant here.
Expand Down
8 changes: 4 additions & 4 deletions lib/private/Share20/ProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected function defaultShareProvider() {
$this->serverContainer->getGroupManager(),
$this->serverContainer->getLazyRootFolder(),
$this->serverContainer->getMailer(),
$this->serverContainer->query(Defaults::class),
$this->serverContainer->get(Defaults::class),
$this->serverContainer->getL10NFactory(),
$this->serverContainer->getURLGenerator(),
$this->serverContainer->getConfig()
Expand Down Expand Up @@ -138,11 +138,11 @@ protected function federatedShareProvider() {
$notifications = new Notifications(
$addressHandler,
$this->serverContainer->getHTTPClientService(),
$this->serverContainer->query(\OCP\OCS\IDiscoveryService::class),
$this->serverContainer->get(\OCP\OCS\IDiscoveryService::class),
$this->serverContainer->getJobList(),
\OC::$server->getCloudFederationProviderManager(),
\OC::$server->getCloudFederationFactory(),
$this->serverContainer->query(IEventDispatcher::class),
$this->serverContainer->get(IEventDispatcher::class),
$this->serverContainer->get(LoggerInterface::class),
);
$tokenHandler = new TokenHandler(
Expand Down Expand Up @@ -197,7 +197,7 @@ protected function getShareByMailProvider() {
$this->serverContainer->getURLGenerator(),
$this->serverContainer->getActivityManager(),
$settingsManager,
$this->serverContainer->query(Defaults::class),
$this->serverContainer->get(Defaults::class),
$this->serverContainer->getHasher(),
$this->serverContainer->get(IEventDispatcher::class),
$this->serverContainer->get(IManager::class)
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Streamer.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function addDirRecursive(string $dir, string $internalDir = ''): void {
$files = $dirNode->getDirectoryListing();

/** @var LoggerInterface $logger */
$logger = \OC::$server->query(LoggerInterface::class);
$logger = \OC::$server->get(LoggerInterface::class);
foreach ($files as $file) {
if ($file instanceof File) {
try {
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Support/CrashReport/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private function loadLazyProviders(): void {
while (($class = array_shift($this->lazyReporters)) !== null) {
try {
/** @var IReporter $reporter */
$reporter = $this->serverContainer->query($class);
$reporter = $this->serverContainer->get($class);
} catch (QueryException $e) {
/*
* There is a circular dependency between the logger and the registry, so
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Support/Subscription/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function __construct(IConfig $config,
private function getSubscription(): ?ISubscription {
if ($this->subscription === null && $this->subscriptionService !== null) {
try {
$this->subscription = $this->container->query($this->subscriptionService);
$this->subscription = $this->container->get($this->subscriptionService);
} catch (QueryException $e) {
// Ignore this
}
Expand Down
4 changes: 2 additions & 2 deletions lib/public/AppFramework/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ public function registerRoutes(IRouter $router, array $routes) {
* parent::__construct('tasks', $params);
*
* $this->getContainer()->registerService('PageController', function(IAppContainer $c){
* $a = $c->query('API');
* $r = $c->query('Request');
* $a = $c->get('API');
* $r = $c->get('Request');
* return new PageController($a, $r);
* });
* }
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/BackgroundJob/QueuedJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function testJobShouldBeRemoved() {
}

public function testJobShouldBeRemovedNew() {
$job = new TestQueuedJobNew(\OC::$server->query(ITimeFactory::class));
$job = new TestQueuedJobNew(\OC::$server->get(ITimeFactory::class));
$job->setId(42);
$this->jobList->add($job);

Expand Down
2 changes: 1 addition & 1 deletion tests/lib/BackgroundJob/TimedJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected function setUp(): void {
parent::setUp();

$this->jobList = new DummyJobList();
$this->time = \OC::$server->query(ITimeFactory::class);
$this->time = \OC::$server->get(ITimeFactory::class);
}

public function testShouldRunAfterInterval() {
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Files/EtagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function testNewUser() {
$files = ['/foo.txt', '/folder/bar.txt', '/folder/subfolder', '/folder/subfolder/qwerty.txt'];
$originalEtags = $this->getEtags($files);

$scanner = new \OC\Files\Utils\Scanner($user1, \OC::$server->getDatabaseConnection(), \OC::$server->query(IEventDispatcher::class), \OC::$server->get(LoggerInterface::class));
$scanner = new \OC\Files\Utils\Scanner($user1, \OC::$server->getDatabaseConnection(), \OC::$server->get(IEventDispatcher::class), \OC::$server->get(LoggerInterface::class));
$scanner->backgroundScan('/');

$newEtags = $this->getEtags($files);
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Files/Node/HookConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected function setUp(): void {
$this->createMock(IUserManager::class),
$this->createMock(IEventDispatcher::class)
);
$this->eventDispatcher = \OC::$server->query(IEventDispatcher::class);
$this->eventDispatcher = \OC::$server->get(IEventDispatcher::class);
}

protected function tearDown(): void {
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Files/Utils/ScannerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function testScanSubMount() {
$storage->file_put_contents('foo.txt', 'qwerty');
$storage->file_put_contents('folder/bar.txt', 'qwerty');

$scanner = new \OC\Files\Utils\Scanner($uid, \OC::$server->getDatabaseConnection(), \OC::$server->query(IEventDispatcher::class), \OC::$server->get(LoggerInterface::class));
$scanner = new \OC\Files\Utils\Scanner($uid, \OC::$server->getDatabaseConnection(), \OC::$server->get(IEventDispatcher::class), \OC::$server->get(LoggerInterface::class));

$this->assertFalse($cache->inCache('folder/bar.txt'));
$scanner->scan('/' . $uid . '/files/foo');
Expand Down
Loading
Loading