From 71a0b9b30b569efb92e3d25ac6b33a3c1e1945d2 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Mon, 14 Oct 2019 15:11:40 +0200 Subject: [PATCH] extend legacy exception for backwards compatibility --- .../Debug/Exception/FlattenException.php | 2 -- .../Exception/FlattenException.php | 27 +++++++++---------- .../stubs/Exception/FlattenException.php | 25 ----------------- .../Component/ErrorRenderer/composer.json | 4 +-- .../EventListener/ExceptionListener.php | 15 +---------- 5 files changed, 16 insertions(+), 57 deletions(-) delete mode 100644 src/Symfony/Component/ErrorRenderer/Resources/stubs/Exception/FlattenException.php diff --git a/src/Symfony/Component/Debug/Exception/FlattenException.php b/src/Symfony/Component/Debug/Exception/FlattenException.php index af3bcef076b21..d091cb5f6800a 100644 --- a/src/Symfony/Component/Debug/Exception/FlattenException.php +++ b/src/Symfony/Component/Debug/Exception/FlattenException.php @@ -14,8 +14,6 @@ use Symfony\Component\HttpFoundation\Exception\RequestExceptionInterface; use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; -@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', FlattenException::class, \Symfony\Component\ErrorRenderer\Exception\FlattenException::class), E_USER_DEPRECATED); - /** * FlattenException wraps a PHP Error or Exception to be able to serialize it. * diff --git a/src/Symfony/Component/ErrorRenderer/Exception/FlattenException.php b/src/Symfony/Component/ErrorRenderer/Exception/FlattenException.php index 30995a111cdb3..0ecbb31a74cad 100644 --- a/src/Symfony/Component/ErrorRenderer/Exception/FlattenException.php +++ b/src/Symfony/Component/ErrorRenderer/Exception/FlattenException.php @@ -11,6 +11,7 @@ namespace Symfony\Component\ErrorRenderer\Exception; +use Symfony\Component\Debug\Exception\FlattenException as LegacyFlattenException; use Symfony\Component\ErrorHandler\Exception\ErrorException; use Symfony\Component\HttpFoundation\Exception\RequestExceptionInterface; use Symfony\Component\HttpFoundation\Response; @@ -22,10 +23,8 @@ * Basically, this class removes all objects from the trace. * * @author Fabien Potencier - * - * @internal */ -class FlattenException +final class FlattenException extends LegacyFlattenException { private $title; private $message; @@ -39,12 +38,12 @@ class FlattenException private $file; private $line; - public static function create(\Exception $exception, int $statusCode = null, array $headers = []): self + public static function create(\Exception $exception, $statusCode = null, array $headers = []): LegacyFlattenException { return static::createFromThrowable($exception, $statusCode, $headers); } - public static function createFromThrowable(\Throwable $exception, int $statusCode = null, array $headers = []): self + public static function createFromThrowable(\Throwable $exception, int $statusCode = null, array $headers = []): LegacyFlattenException { $e = new static(); $e->setMessage($exception->getMessage()); @@ -106,7 +105,7 @@ public function getStatusCode() /** * @return $this */ - public function setStatusCode($code) + public function setStatusCode($code): self { $this->statusCode = $code; @@ -121,7 +120,7 @@ public function getHeaders() /** * @return $this */ - public function setHeaders(array $headers) + public function setHeaders(array $headers): self { $this->headers = $headers; @@ -136,7 +135,7 @@ public function getClass() /** * @return $this */ - public function setClass($class) + public function setClass($class): self { $this->class = 'c' === $class[0] && 0 === strpos($class, "class@anonymous\0") ? get_parent_class($class).'@anonymous' : $class; @@ -151,7 +150,7 @@ public function getFile() /** * @return $this */ - public function setFile($file) + public function setFile($file): self { $this->file = $file; @@ -166,7 +165,7 @@ public function getLine() /** * @return $this */ - public function setLine($line) + public function setLine($line): self { $this->line = $line; @@ -193,7 +192,7 @@ public function getMessage() /** * @return $this */ - public function setMessage($message) + public function setMessage($message): self { if (false !== strpos($message, "class@anonymous\0")) { $message = preg_replace_callback('/class@anonymous\x00.*?\.php0x?[0-9a-fA-F]++/', function ($m) { @@ -214,7 +213,7 @@ public function getCode() /** * @return $this */ - public function setCode($code) + public function setCode($code): self { $this->code = $code; @@ -229,7 +228,7 @@ public function getPrevious() /** * @return $this */ - public function setPrevious(self $previous) + public function setPrevious(LegacyFlattenException $previous): self { $this->previous = $previous; @@ -272,7 +271,7 @@ public function setTraceFromThrowable(\Throwable $throwable) /** * @return $this */ - public function setTrace($trace, $file, $line) + public function setTrace($trace, $file, $line): self { $this->trace = []; $this->trace[] = [ diff --git a/src/Symfony/Component/ErrorRenderer/Resources/stubs/Exception/FlattenException.php b/src/Symfony/Component/ErrorRenderer/Resources/stubs/Exception/FlattenException.php deleted file mode 100644 index f17f5711a37c6..0000000000000 --- a/src/Symfony/Component/ErrorRenderer/Resources/stubs/Exception/FlattenException.php +++ /dev/null @@ -1,25 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Debug\Exception; - -if (!class_exists(FlattenException::class, false)) { - class_alias(\Symfony\Component\ErrorRenderer\Exception\FlattenException::class, FlattenException::class); -} - -if (false) { - /** - * @deprecated since Symfony 4.4, use Symfony\Component\ErrorRenderer\Exception\FlattenException instead. - */ - class FlattenException extends \Symfony\Component\ErrorRenderer\Exception\FlattenException - { - } -} diff --git a/src/Symfony/Component/ErrorRenderer/composer.json b/src/Symfony/Component/ErrorRenderer/composer.json index 61e052e53611c..90351239fc689 100644 --- a/src/Symfony/Component/ErrorRenderer/composer.json +++ b/src/Symfony/Component/ErrorRenderer/composer.json @@ -21,7 +21,8 @@ ], "require": { "php": "^7.1.3", - "psr/log": "~1.0" + "psr/log": "~1.0", + "symfony/debug": "^4.4" }, "require-dev": { "symfony/console": "^4.4", @@ -33,7 +34,6 @@ }, "autoload": { "psr-4": { "Symfony\\Component\\ErrorRenderer\\": "" }, - "classmap": [ "Resources/stubs/Exception/FlattenException.php" ], "exclude-from-classmap": [ "/Tests/" ] diff --git a/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php b/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php index 0c8c871e67b36..ae64374c6efb4 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php @@ -12,7 +12,6 @@ namespace Symfony\Component\HttpKernel\EventListener; use Psr\Log\LoggerInterface; -use Symfony\Component\Debug\Exception\FlattenException as LegacyFlattenException; use Symfony\Component\ErrorRenderer\Exception\FlattenException; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -124,21 +123,9 @@ protected function logException(\Exception $exception, $message) */ protected function duplicateRequest(\Exception $exception, Request $request) { - @trigger_error(sprintf('Passing the "exception" attribute (instance of "%s") to the configured controller of the "%s" class is deprecated since Symfony 4.4, use the passed "e" attribute (instance of "%s") instead.', LegacyFlattenException::class, self::class, FlattenException::class)); - - $flattenException = FlattenException::createFromThrowable($exception); - - // BC layer to be removed in 5.0 - if (class_exists(\Symfony\Component\Debug\Debug::class, false)) { - $legacyFlattenException = LegacyFlattenException::createFromThrowable($exception); - } else { - $legacyFlattenException = $flattenException; - } - $attributes = [ '_controller' => $this->controller, - 'exception' => $legacyFlattenException, // to be removed in 5.0 - 'e' => $flattenException, + 'exception' => FlattenException::createFromThrowable($exception), 'logger' => $this->logger instanceof DebugLoggerInterface ? $this->logger : null, ]; $request = $request->duplicate(null, null, $attributes);