aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--build/rector.php11
-rw-r--r--console.php13
-rw-r--r--cron.php21
-rw-r--r--ocs/providers.php6
-rw-r--r--ocs/v1.php22
-rw-r--r--public.php4
-rw-r--r--remote.php14
7 files changed, 62 insertions, 29 deletions
diff --git a/build/rector.php b/build/rector.php
index 03e6eab0e87..95fcc8d961e 100644
--- a/build/rector.php
+++ b/build/rector.php
@@ -53,11 +53,18 @@ $config = RectorConfig::configure()
->withPaths([
$nextcloudDir . '/apps',
$nextcloudDir . '/core',
+ $nextcloudDir . '/ocs',
+ $nextcloudDir . '/ocs-provider',
+ $nextcloudDir . '/console.php',
+ $nextcloudDir . '/cron.php',
+ $nextcloudDir . '/index.php',
+ $nextcloudDir . '/occ',
+ $nextcloudDir . '/public.php',
+ $nextcloudDir . '/remote.php',
$nextcloudDir . '/status.php',
+ $nextcloudDir . '/version.php',
// $nextcloudDir . '/config',
// $nextcloudDir . '/lib',
- // $nextcloudDir . '/ocs',
- // $nextcloudDir . '/ocs-provider',
// $nextcloudDir . '/tests',
// $nextcloudDir . '/themes',
])
diff --git a/console.php b/console.php
index 4fcb3d6c7a3..bdfe4b63254 100644
--- a/console.php
+++ b/console.php
@@ -2,6 +2,9 @@
declare(strict_types=1);
+use OCP\IConfig;
+use OCP\Server;
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -37,7 +40,7 @@ try {
exit(1);
}
- $config = \OCP\Server::get(\OCP\IConfig::class);
+ $config = Server::get(IConfig::class);
set_exception_handler('exceptionHandler');
if (!function_exists('posix_getuid')) {
@@ -71,10 +74,10 @@ try {
echo "Additionally the function 'pcntl_signal' and 'pcntl_signal_dispatch' need to be enabled in your php.ini." . PHP_EOL;
}
- $eventLogger = \OCP\Server::get(IEventLogger::class);
+ $eventLogger = Server::get(IEventLogger::class);
$eventLogger->start('console:build_application', 'Build Application instance and load commands');
- $application = \OCP\Server::get(Application::class);
+ $application = Server::get(Application::class);
/* base.php will have removed eventual debug options from argv in $_SERVER */
$argv = $_SERVER['argv'];
$input = new ArgvInput($argv);
@@ -88,10 +91,10 @@ try {
$eventLogger->end('console:run');
- $profiler = \OCP\Server::get(IProfiler::class);
+ $profiler = Server::get(IProfiler::class);
if ($profiler->isEnabled()) {
$eventLogger->end('runtime');
- $profile = $profiler->collect(\OCP\Server::get(IRequest::class), new Response());
+ $profile = $profiler->collect(Server::get(IRequest::class), new Response());
$profile->setMethod('occ');
$profile->setUrl(implode(' ', $argv));
$profiler->saveProfile($profile);
diff --git a/cron.php b/cron.php
index 993faae3cae..0501c53ff40 100644
--- a/cron.php
+++ b/cron.php
@@ -2,6 +2,11 @@
declare(strict_types=1);
+use OC\Files\SetupManager;
+use OC\Session\CryptoWrapper;
+use OC\Session\Memory;
+use OCP\ILogger;
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -64,8 +69,8 @@ Options:
$verbose = isset($argv[1]) && ($argv[1] === '-v' || $argv[1] === '--verbose');
// initialize a dummy memory session
- $session = new \OC\Session\Memory();
- $cryptoWrapper = \OC::$server->getSessionCryptoWrapper();
+ $session = new Memory();
+ $cryptoWrapper = Server::get(CryptoWrapper::class);
$session = $cryptoWrapper->wrapSession($session);
\OC::$server->setSession($session);
@@ -177,11 +182,11 @@ Options:
$timeSpent = $timeAfter - $timeBefore;
if ($timeSpent > $cronInterval) {
$logLevel = match (true) {
- $timeSpent > $cronInterval * 128 => \OCP\ILogger::FATAL,
- $timeSpent > $cronInterval * 64 => \OCP\ILogger::ERROR,
- $timeSpent > $cronInterval * 16 => \OCP\ILogger::WARN,
- $timeSpent > $cronInterval * 8 => \OCP\ILogger::INFO,
- default => \OCP\ILogger::DEBUG,
+ $timeSpent > $cronInterval * 128 => ILogger::FATAL,
+ $timeSpent > $cronInterval * 64 => ILogger::ERROR,
+ $timeSpent > $cronInterval * 16 => ILogger::WARN,
+ $timeSpent > $cronInterval * 8 => ILogger::INFO,
+ default => ILogger::DEBUG,
};
$logger->log(
$logLevel,
@@ -206,7 +211,7 @@ Options:
}
// clean up after unclean jobs
- Server::get(\OC\Files\SetupManager::class)->tearDown();
+ Server::get(SetupManager::class)->tearDown();
$tempManager->clean();
if ($verbose) {
diff --git a/ocs/providers.php b/ocs/providers.php
index 6333a91fdb2..b1e5224ab2a 100644
--- a/ocs/providers.php
+++ b/ocs/providers.php
@@ -1,4 +1,8 @@
<?php
+
+use OCP\IRequest;
+use OCP\Server;
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -9,7 +13,7 @@ require_once __DIR__ . '/../lib/base.php';
header('Content-type: application/xml');
-$request = \OC::$server->getRequest();
+$request = Server::get(IRequest::class);
$url = $request->getServerProtocol() . '://' . substr($request->getServerHost() . $request->getRequestUri(), 0, -17) . 'ocs/v1.php/';
diff --git a/ocs/v1.php b/ocs/v1.php
index 7205f4a26b7..3fc800e198a 100644
--- a/ocs/v1.php
+++ b/ocs/v1.php
@@ -2,6 +2,14 @@
declare(strict_types=1);
+use OC\Route\Router;
+use OC\SystemConfig;
+use OC\User\LoginException;
+use OCP\IConfig;
+use OCP\IRequest;
+use OCP\IUserSession;
+use OCP\Server;
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -21,7 +29,7 @@ use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
if (Util::needUpgrade()
- || \OC::$server->getConfig()->getSystemValueBool('maintenance')) {
+ || Server::get(IConfig::class)->getSystemValueBool('maintenance')) {
// since the behavior of apps or remotes are unpredictable during
// an upgrade, return a 503 directly
ApiHelper::respond(503, 'Service unavailable', ['X-Nextcloud-Maintenance-Mode' => '1'], 503);
@@ -42,11 +50,11 @@ try {
// side effects in existing apps
OC_App::loadApps();
- if (!\OC::$server->getUserSession()->isLoggedIn()) {
- OC::handleLogin(\OC::$server->getRequest());
+ if (!Server::get(IUserSession::class)->isLoggedIn()) {
+ OC::handleLogin(Server::get(IRequest::class));
}
- OC::$server->get(\OC\Route\Router::class)->match('/ocsapp' . \OC::$server->getRequest()->getRawPathInfo());
+ Server::get(Router::class)->match('/ocsapp' . Server::get(IRequest::class)->getRawPathInfo());
} catch (MaxDelayReached $ex) {
ApiHelper::respond(Http::STATUS_TOO_MANY_REQUESTS, $ex->getMessage());
} catch (ResourceNotFoundException $e) {
@@ -56,14 +64,14 @@ try {
} catch (MethodNotAllowedException $e) {
ApiHelper::setContentType();
http_response_code(405);
-} catch (\OC\User\LoginException $e) {
+} catch (LoginException $e) {
ApiHelper::respond(OCSController::RESPOND_UNAUTHORISED, 'Unauthorised');
} catch (\Exception $e) {
- \OCP\Server::get(LoggerInterface::class)->error($e->getMessage(), ['exception' => $e]);
+ Server::get(LoggerInterface::class)->error($e->getMessage(), ['exception' => $e]);
$txt = 'Internal Server Error' . "\n";
try {
- if (\OC::$server->getSystemConfig()->getValue('debug', false)) {
+ if (Server::get(SystemConfig::class)->getValue('debug', false)) {
$txt .= $e->getMessage();
}
} catch (\Throwable $e) {
diff --git a/public.php b/public.php
index 682d5cb2538..8ae6deff203 100644
--- a/public.php
+++ b/public.php
@@ -2,6 +2,8 @@
declare(strict_types=1);
+use OC\ServiceUnavailableException;
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -88,7 +90,7 @@ try {
require_once $file;
} catch (Exception $ex) {
$status = 500;
- if ($ex instanceof \OC\ServiceUnavailableException) {
+ if ($ex instanceof ServiceUnavailableException) {
$status = 503;
}
//show the user a detailed error page
diff --git a/remote.php b/remote.php
index 7058e7aceb4..2cfd9d818c8 100644
--- a/remote.php
+++ b/remote.php
@@ -1,5 +1,9 @@
<?php
+use OC\ServiceUnavailableException;
+use OCP\IConfig;
+use OCP\Util;
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -35,7 +39,7 @@ function handleException(Exception|Error $e): void {
// we shall not log on RemoteException
$server->addPlugin(new ExceptionLoggerPlugin('webdav', \OCP\Server::get(LoggerInterface::class)));
}
- $server->on('beforeMethod:*', function () use ($e) {
+ $server->on('beforeMethod:*', function () use ($e): void {
if ($e instanceof RemoteException) {
switch ($e->getCode()) {
case 503:
@@ -51,7 +55,7 @@ function handleException(Exception|Error $e): void {
$server->exec();
} else {
$statusCode = 500;
- if ($e instanceof \OC\ServiceUnavailableException) {
+ if ($e instanceof ServiceUnavailableException) {
$statusCode = 503;
}
if ($e instanceof RemoteException) {
@@ -86,7 +90,7 @@ function resolveService($service) {
return $services[$service];
}
- return \OC::$server->getConfig()->getAppValue('core', 'remote_' . $service);
+ return \OCP\Server::get(IConfig::class)->getAppValue('core', 'remote_' . $service);
}
try {
@@ -97,13 +101,13 @@ try {
// this policy with a softer one if debug mode is enabled.
header("Content-Security-Policy: default-src 'none';");
- if (\OCP\Util::needUpgrade()) {
+ if (Util::needUpgrade()) {
// since the behavior of apps or remotes are unpredictable during
// an upgrade, return a 503 directly
throw new RemoteException('Service unavailable', 503);
}
- $request = \OC::$server->getRequest();
+ $request = \OCP\Server::get(IRequest::class);
$pathInfo = $request->getPathInfo();
if ($pathInfo === false || $pathInfo === '') {
throw new RemoteException('Path not found', 404);