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

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
pull/43460/head
Côme Chilliet 3 months ago committed by Côme Chilliet
parent 61f58e8043
commit 15fb15bc14

@ -1,8 +1,12 @@
<?php <?php
declare(strict_types=1);
/** /**
* @copyright Copyright (c) 2016, ownCloud, Inc. * @copyright Copyright (c) 2016, ownCloud, Inc.
* *
* @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Côme Chilliet <come.chilliet@nextcloud.com>
* @author Joas Schilling <coding@schilljs.com> * @author Joas Schilling <coding@schilljs.com>
* @author Jörn Friedrich Dreyer <jfd@butonic.de> * @author Jörn Friedrich Dreyer <jfd@butonic.de>
* @author Lukas Reschke <lukas@statuscode.ch> * @author Lukas Reschke <lukas@statuscode.ch>
@ -28,33 +32,39 @@
* along with this program. If not, see <http://www.gnu.org/licenses/> * along with this program. If not, see <http://www.gnu.org/licenses/>
* *
*/ */
require_once __DIR__ . '/lib/versioncheck.php'; 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\Security\Bruteforce\MaxDelayReached;
use OCP\Server;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
try { try {
require_once __DIR__ . '/lib/base.php'; require_once __DIR__ . '/lib/base.php';
OC::handleRequest(); OC::handleRequest();
} catch (\OC\ServiceUnavailableException $ex) { } catch (ServiceUnavailableException $ex) {
\OC::$server->get(LoggerInterface::class)->error($ex->getMessage(), [ Server::get(LoggerInterface::class)->error($ex->getMessage(), [
'app' => 'index', 'app' => 'index',
'exception' => $ex, 'exception' => $ex,
]); ]);
//show the user a detailed error page //show the user a detailed error page
OC_Template::printExceptionErrorPage($ex, 503); OC_Template::printExceptionErrorPage($ex, 503);
} catch (\OCP\HintException $ex) { } catch (HintException $ex) {
try { try {
OC_Template::printErrorPage($ex->getMessage(), $ex->getHint(), 503); OC_Template::printErrorPage($ex->getMessage(), $ex->getHint(), 503);
} catch (Exception $ex2) { } catch (Exception $ex2) {
try { try {
\OC::$server->get(LoggerInterface::class)->error($ex->getMessage(), [ Server::get(LoggerInterface::class)->error($ex->getMessage(), [
'app' => 'index', 'app' => 'index',
'exception' => $ex, 'exception' => $ex,
]); ]);
\OC::$server->get(LoggerInterface::class)->error($ex2->getMessage(), [ Server::get(LoggerInterface::class)->error($ex2->getMessage(), [
'app' => 'index', 'app' => 'index',
'exception' => $ex2, 'exception' => $ex2,
]); ]);
@ -65,8 +75,8 @@ try {
//show the user a detailed error page //show the user a detailed error page
OC_Template::printExceptionErrorPage($ex, 500); OC_Template::printExceptionErrorPage($ex, 500);
} }
} catch (\OC\User\LoginException $ex) { } catch (LoginException $ex) {
$request = \OC::$server->getRequest(); $request = Server::get(IRequest::class);
/** /**
* Routes with the @CORS annotation and other API endpoints should * 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, * not return a webpage, so we only print the error page when html is accepted,
@ -80,7 +90,7 @@ try {
} }
OC_Template::printErrorPage($ex->getMessage(), $ex->getMessage(), 401); OC_Template::printErrorPage($ex->getMessage(), $ex->getMessage(), 401);
} catch (MaxDelayReached $ex) { } catch (MaxDelayReached $ex) {
$request = \OC::$server->getRequest(); $request = Server::get(IRequest::class);
/** /**
* Routes with the @CORS annotation and other API endpoints should * 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, * not return a webpage, so we only print the error page when html is accepted,
@ -95,7 +105,7 @@ try {
http_response_code(429); http_response_code(429);
OC_Template::printGuestPage('core', '429'); OC_Template::printGuestPage('core', '429');
} catch (Exception $ex) { } catch (Exception $ex) {
\OC::$server->get(LoggerInterface::class)->error($ex->getMessage(), [ Server::get(LoggerInterface::class)->error($ex->getMessage(), [
'app' => 'index', 'app' => 'index',
'exception' => $ex, 'exception' => $ex,
]); ]);
@ -104,7 +114,7 @@ try {
OC_Template::printExceptionErrorPage($ex, 500); OC_Template::printExceptionErrorPage($ex, 500);
} catch (Error $ex) { } catch (Error $ex) {
try { try {
\OC::$server->get(LoggerInterface::class)->error($ex->getMessage(), [ Server::get(LoggerInterface::class)->error($ex->getMessage(), [
'app' => 'index', 'app' => 'index',
'exception' => $ex, 'exception' => $ex,
]); ]);

Loading…
Cancel
Save