Use the new Symfony error handler

This commit is contained in:
Pierre Rudloff 2020-05-13 22:57:25 +02:00
parent b670b16ca2
commit 6a19a1ddc1
4 changed files with 44 additions and 44 deletions

View file

@ -32,8 +32,8 @@
"roave/security-advisories": "dev-master", "roave/security-advisories": "dev-master",
"smarty-gettext/smarty-gettext": "^1.6", "smarty-gettext/smarty-gettext": "^1.6",
"squizlabs/php_codesniffer": "^3.5", "squizlabs/php_codesniffer": "^3.5",
"symfony/debug": "^4.0", "symfony/error-handler": "^5.0",
"symfony/var-dumper": "^4.0", "symfony/var-dumper": "^5.0",
"ytdl-org/youtube-dl": "^2020.03.24" "ytdl-org/youtube-dl": "^2020.03.24"
}, },
"extra": { "extra": {

70
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "0963a360e0cc19e97da7da9b8cad2285", "content-hash": "9860b748974de6e19945cfae8619d223",
"packages": [ "packages": [
{ {
"name": "aura/session", "name": "aura/session",
@ -932,16 +932,16 @@
}, },
{ {
"name": "psr/log", "name": "psr/log",
"version": "1.1.0", "version": "1.1.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/php-fig/log.git", "url": "https://github.com/php-fig/log.git",
"reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd" "reference": "0f73288fd15629204f9d42b7055f72dacbe811fc"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/php-fig/log/zipball/6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd", "url": "https://api.github.com/repos/php-fig/log/zipball/0f73288fd15629204f9d42b7055f72dacbe811fc",
"reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd", "reference": "0f73288fd15629204f9d42b7055f72dacbe811fc",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -950,7 +950,7 @@
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "1.0.x-dev" "dev-master": "1.1.x-dev"
} }
}, },
"autoload": { "autoload": {
@ -975,7 +975,7 @@
"psr", "psr",
"psr-3" "psr-3"
], ],
"time": "2018-11-20T15:27:04+00:00" "time": "2020-03-23T09:12:05+00:00"
}, },
{ {
"name": "ralouphie/getallheaders", "name": "ralouphie/getallheaders",
@ -5841,38 +5841,37 @@
"time": "2019-10-28T04:36:32+00:00" "time": "2019-10-28T04:36:32+00:00"
}, },
{ {
"name": "symfony/debug", "name": "symfony/error-handler",
"version": "v4.4.0", "version": "v5.0.8",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/debug.git", "url": "https://github.com/symfony/error-handler.git",
"reference": "b24b791f817116b29e52a63e8544884cf9a40757" "reference": "949ffc17c3ac3a9f8e6232220e2da33913c04ea4"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/debug/zipball/b24b791f817116b29e52a63e8544884cf9a40757", "url": "https://api.github.com/repos/symfony/error-handler/zipball/949ffc17c3ac3a9f8e6232220e2da33913c04ea4",
"reference": "b24b791f817116b29e52a63e8544884cf9a40757", "reference": "949ffc17c3ac3a9f8e6232220e2da33913c04ea4",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": "^7.1.3", "php": "^7.2.5",
"psr/log": "~1.0" "psr/log": "^1.0",
}, "symfony/var-dumper": "^4.4|^5.0"
"conflict": {
"symfony/http-kernel": "<3.4"
}, },
"require-dev": { "require-dev": {
"symfony/http-kernel": "^3.4|^4.0|^5.0" "symfony/http-kernel": "^4.4|^5.0",
"symfony/serializer": "^4.4|^5.0"
}, },
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "4.4-dev" "dev-master": "5.0-dev"
} }
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"Symfony\\Component\\Debug\\": "" "Symfony\\Component\\ErrorHandler\\": ""
}, },
"exclude-from-classmap": [ "exclude-from-classmap": [
"/Tests/" "/Tests/"
@ -5892,38 +5891,37 @@
"homepage": "https://symfony.com/contributors" "homepage": "https://symfony.com/contributors"
} }
], ],
"description": "Symfony Debug Component", "description": "Symfony ErrorHandler Component",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"time": "2019-11-10T17:54:30+00:00" "time": "2020-03-30T14:14:32+00:00"
}, },
{ {
"name": "symfony/var-dumper", "name": "symfony/var-dumper",
"version": "v4.4.0", "version": "v5.0.8",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/var-dumper.git", "url": "https://github.com/symfony/var-dumper.git",
"reference": "eade2890f8b0eeb279b6cf41b50a10007294490f" "reference": "09de28632f16f81058a85fcf318397218272a07b"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/var-dumper/zipball/eade2890f8b0eeb279b6cf41b50a10007294490f", "url": "https://api.github.com/repos/symfony/var-dumper/zipball/09de28632f16f81058a85fcf318397218272a07b",
"reference": "eade2890f8b0eeb279b6cf41b50a10007294490f", "reference": "09de28632f16f81058a85fcf318397218272a07b",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": "^7.1.3", "php": "^7.2.5",
"symfony/polyfill-mbstring": "~1.0", "symfony/polyfill-mbstring": "~1.0"
"symfony/polyfill-php72": "~1.5"
}, },
"conflict": { "conflict": {
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0", "phpunit/phpunit": "<5.4.3",
"symfony/console": "<3.4" "symfony/console": "<4.4"
}, },
"require-dev": { "require-dev": {
"ext-iconv": "*", "ext-iconv": "*",
"symfony/console": "^3.4|^4.0|^5.0", "symfony/console": "^4.4|^5.0",
"symfony/process": "^4.4|^5.0", "symfony/process": "^4.4|^5.0",
"twig/twig": "^1.34|^2.4|^3.0" "twig/twig": "^2.4|^3.0"
}, },
"suggest": { "suggest": {
"ext-iconv": "To convert non-UTF-8 strings to UTF-8 (or symfony/polyfill-iconv in case ext-iconv cannot be used).", "ext-iconv": "To convert non-UTF-8 strings to UTF-8 (or symfony/polyfill-iconv in case ext-iconv cannot be used).",
@ -5936,7 +5934,7 @@
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "4.4-dev" "dev-master": "5.0-dev"
} }
}, },
"autoload": { "autoload": {
@ -5970,7 +5968,7 @@
"debug", "debug",
"dump" "dump"
], ],
"time": "2019-11-12T14:51:11+00:00" "time": "2020-04-12T16:45:47+00:00"
}, },
{ {
"name": "theseer/tokenizer", "name": "theseer/tokenizer",

View file

@ -9,14 +9,15 @@ namespace Alltube\Controller;
use Alltube\Exception\PasswordException; use Alltube\Exception\PasswordException;
use Alltube\Locale; use Alltube\Locale;
use Alltube\Video; use Alltube\Video;
use Symfony\Component\ErrorHandler\ErrorHandler;
use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer;
use Symfony\Component\ErrorHandler\Exception\FlattenException;
use Throwable; use Throwable;
use Exception; use Exception;
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
use Slim\Http\Request; use Slim\Http\Request;
use Slim\Http\Response; use Slim\Http\Response;
use Slim\Views\Smarty; use Slim\Views\Smarty;
use Symfony\Component\Debug\ExceptionHandler;
use Symfony\Component\Debug\Exception\FlattenException;
/** /**
* Main controller. * Main controller.
@ -240,9 +241,9 @@ class FrontController extends BaseController
public function error(Request $request, Response $response, Throwable $error) public function error(Request $request, Response $response, Throwable $error)
{ {
if ($this->config->debug) { if ($this->config->debug) {
$exception = FlattenException::createFromThrowable($error); $renderer = new HtmlErrorRenderer(true);
$handler = new ExceptionHandler(); $exception = $renderer->render($error);
$response->getBody()->write($handler->getHtml($exception)); $response->getBody()->write($exception->getAsString());
return $response->withStatus($exception->getStatusCode()); return $response->withStatus($exception->getStatusCode());
} else { } else {

View file

@ -1,6 +1,7 @@
<?php <?php
require_once __DIR__ . '/vendor/autoload.php'; require_once __DIR__ . '/vendor/autoload.php';
use Alltube\Config; use Alltube\Config;
use Alltube\Controller\DownloadController; use Alltube\Controller\DownloadController;
use Alltube\Controller\FrontController; use Alltube\Controller\FrontController;
@ -11,7 +12,7 @@ use Alltube\UglyRouter;
use Alltube\ViewFactory; use Alltube\ViewFactory;
use Slim\App; use Slim\App;
use Slim\Container; use Slim\Container;
use Symfony\Component\Debug\Debug; use Symfony\Component\ErrorHandler\Debug;
if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '/index.php') !== false) { if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '/index.php') !== false) {
header('Location: ' . str_ireplace('/index.php', '/', $_SERVER['REQUEST_URI'])); header('Location: ' . str_ireplace('/index.php', '/', $_SERVER['REQUEST_URI']));