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

chore(index.php): Use strict_types and Server::get in index.php #43460

Merged
merged 1 commit into from
Feb 12, 2024
Merged
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
chore(index.php): Use strict_types and Server::get in index.php
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
  • Loading branch information
come-nc committed Feb 12, 2024
commit 15fb15bc1436f9659feefd82031e389a24ad3117
30 changes: 20 additions & 10 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Côme Chilliet <come.chilliet@nextcloud.com>
* @author Joas Schilling <coding@schilljs.com>
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
* @author Lukas Reschke <lukas@statuscode.ch>
Expand All @@ -28,33 +32,39 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

require_once __DIR__ . '/lib/versioncheck.php';

use OC\ServiceUnavailableException;
use OC\User\LoginException;
use OCP\HintException;
use OCP\IRequest;
use OCP\Security\Bruteforce\MaxDelayReached;
use OCP\Server;
use Psr\Log\LoggerInterface;

try {
require_once __DIR__ . '/lib/base.php';

OC::handleRequest();
} catch (\OC\ServiceUnavailableException $ex) {
\OC::$server->get(LoggerInterface::class)->error($ex->getMessage(), [
} catch (ServiceUnavailableException $ex) {
Server::get(LoggerInterface::class)->error($ex->getMessage(), [
'app' => 'index',
'exception' => $ex,
]);

//show the user a detailed error page
OC_Template::printExceptionErrorPage($ex, 503);
} catch (\OCP\HintException $ex) {
} catch (HintException $ex) {
try {
OC_Template::printErrorPage($ex->getMessage(), $ex->getHint(), 503);
} catch (Exception $ex2) {
try {
\OC::$server->get(LoggerInterface::class)->error($ex->getMessage(), [
Server::get(LoggerInterface::class)->error($ex->getMessage(), [
'app' => 'index',
'exception' => $ex,
]);
\OC::$server->get(LoggerInterface::class)->error($ex2->getMessage(), [
Server::get(LoggerInterface::class)->error($ex2->getMessage(), [
'app' => 'index',
'exception' => $ex2,
]);
Expand All @@ -65,8 +75,8 @@
//show the user a detailed error page
OC_Template::printExceptionErrorPage($ex, 500);
}
} catch (\OC\User\LoginException $ex) {
$request = \OC::$server->getRequest();
} catch (LoginException $ex) {
$request = Server::get(IRequest::class);
/**
* Routes with the @CORS annotation and other API endpoints should
* not return a webpage, so we only print the error page when html is accepted,
Expand All @@ -80,7 +90,7 @@
}
OC_Template::printErrorPage($ex->getMessage(), $ex->getMessage(), 401);
} catch (MaxDelayReached $ex) {
$request = \OC::$server->getRequest();
$request = Server::get(IRequest::class);
/**
* Routes with the @CORS annotation and other API endpoints should
* not return a webpage, so we only print the error page when html is accepted,
Expand All @@ -95,7 +105,7 @@
http_response_code(429);
OC_Template::printGuestPage('core', '429');
} catch (Exception $ex) {
\OC::$server->get(LoggerInterface::class)->error($ex->getMessage(), [
Server::get(LoggerInterface::class)->error($ex->getMessage(), [
'app' => 'index',
'exception' => $ex,
]);
Expand All @@ -104,7 +114,7 @@
OC_Template::printExceptionErrorPage($ex, 500);
} catch (Error $ex) {
try {
\OC::$server->get(LoggerInterface::class)->error($ex->getMessage(), [
Server::get(LoggerInterface::class)->error($ex->getMessage(), [
'app' => 'index',
'exception' => $ex,
]);
Expand Down
Loading