Skip to content

[ErrorRenderer] extend legacy exception for backwards compatibility #33981

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

Merged
merged 1 commit into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions src/Symfony/Component/Debug/Exception/FlattenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
27 changes: 13 additions & 14 deletions src/Symfony/Component/ErrorRenderer/Exception/FlattenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,10 +23,8 @@
* Basically, this class removes all objects from the trace.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @internal
*/
class FlattenException
final class FlattenException extends LegacyFlattenException
{
private $title;
private $message;
Expand All @@ -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());
Expand Down Expand Up @@ -106,7 +105,7 @@ public function getStatusCode()
/**
* @return $this
*/
public function setStatusCode($code)
public function setStatusCode($code): self
{
$this->statusCode = $code;

Expand All @@ -121,7 +120,7 @@ public function getHeaders()
/**
* @return $this
*/
public function setHeaders(array $headers)
public function setHeaders(array $headers): self
{
$this->headers = $headers;

Expand All @@ -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;

Expand All @@ -151,7 +150,7 @@ public function getFile()
/**
* @return $this
*/
public function setFile($file)
public function setFile($file): self
{
$this->file = $file;

Expand All @@ -166,7 +165,7 @@ public function getLine()
/**
* @return $this
*/
public function setLine($line)
public function setLine($line): self
{
$this->line = $line;

Expand All @@ -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) {
Expand All @@ -214,7 +213,7 @@ public function getCode()
/**
* @return $this
*/
public function setCode($code)
public function setCode($code): self
{
$this->code = $code;

Expand All @@ -229,7 +228,7 @@ public function getPrevious()
/**
* @return $this
*/
public function setPrevious(self $previous)
public function setPrevious(LegacyFlattenException $previous): self
{
$this->previous = $previous;

Expand Down Expand Up @@ -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[] = [
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions src/Symfony/Component/ErrorRenderer/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -33,7 +34,6 @@
},
"autoload": {
"psr-4": { "Symfony\\Component\\ErrorRenderer\\": "" },
"classmap": [ "Resources/stubs/Exception/FlattenException.php" ],
"exclude-from-classmap": [
"/Tests/"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down