Skip to content

Commit 71a0b9b

Browse files
xabbuhnicolas-grekas
authored andcommitted
extend legacy exception for backwards compatibility
1 parent 3723d03 commit 71a0b9b

File tree

5 files changed

+16
-57
lines changed

5 files changed

+16
-57
lines changed

src/Symfony/Component/Debug/Exception/FlattenException.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
use Symfony\Component\HttpFoundation\Exception\RequestExceptionInterface;
1515
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
1616

17-
@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);
18-
1917
/**
2018
* FlattenException wraps a PHP Error or Exception to be able to serialize it.
2119
*

src/Symfony/Component/ErrorRenderer/Exception/FlattenException.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\ErrorRenderer\Exception;
1313

14+
use Symfony\Component\Debug\Exception\FlattenException as LegacyFlattenException;
1415
use Symfony\Component\ErrorHandler\Exception\ErrorException;
1516
use Symfony\Component\HttpFoundation\Exception\RequestExceptionInterface;
1617
use Symfony\Component\HttpFoundation\Response;
@@ -22,10 +23,8 @@
2223
* Basically, this class removes all objects from the trace.
2324
*
2425
* @author Fabien Potencier <fabien@symfony.com>
25-
*
26-
* @internal
2726
*/
28-
class FlattenException
27+
final class FlattenException extends LegacyFlattenException
2928
{
3029
private $title;
3130
private $message;
@@ -39,12 +38,12 @@ class FlattenException
3938
private $file;
4039
private $line;
4140

42-
public static function create(\Exception $exception, int $statusCode = null, array $headers = []): self
41+
public static function create(\Exception $exception, $statusCode = null, array $headers = []): LegacyFlattenException
4342
{
4443
return static::createFromThrowable($exception, $statusCode, $headers);
4544
}
4645

47-
public static function createFromThrowable(\Throwable $exception, int $statusCode = null, array $headers = []): self
46+
public static function createFromThrowable(\Throwable $exception, int $statusCode = null, array $headers = []): LegacyFlattenException
4847
{
4948
$e = new static();
5049
$e->setMessage($exception->getMessage());
@@ -106,7 +105,7 @@ public function getStatusCode()
106105
/**
107106
* @return $this
108107
*/
109-
public function setStatusCode($code)
108+
public function setStatusCode($code): self
110109
{
111110
$this->statusCode = $code;
112111

@@ -121,7 +120,7 @@ public function getHeaders()
121120
/**
122121
* @return $this
123122
*/
124-
public function setHeaders(array $headers)
123+
public function setHeaders(array $headers): self
125124
{
126125
$this->headers = $headers;
127126

@@ -136,7 +135,7 @@ public function getClass()
136135
/**
137136
* @return $this
138137
*/
139-
public function setClass($class)
138+
public function setClass($class): self
140139
{
141140
$this->class = 'c' === $class[0] && 0 === strpos($class, "class@anonymous\0") ? get_parent_class($class).'@anonymous' : $class;
142141

@@ -151,7 +150,7 @@ public function getFile()
151150
/**
152151
* @return $this
153152
*/
154-
public function setFile($file)
153+
public function setFile($file): self
155154
{
156155
$this->file = $file;
157156

@@ -166,7 +165,7 @@ public function getLine()
166165
/**
167166
* @return $this
168167
*/
169-
public function setLine($line)
168+
public function setLine($line): self
170169
{
171170
$this->line = $line;
172171

@@ -193,7 +192,7 @@ public function getMessage()
193192
/**
194193
* @return $this
195194
*/
196-
public function setMessage($message)
195+
public function setMessage($message): self
197196
{
198197
if (false !== strpos($message, "class@anonymous\0")) {
199198
$message = preg_replace_callback('/class@anonymous\x00.*?\.php0x?[0-9a-fA-F]++/', function ($m) {
@@ -214,7 +213,7 @@ public function getCode()
214213
/**
215214
* @return $this
216215
*/
217-
public function setCode($code)
216+
public function setCode($code): self
218217
{
219218
$this->code = $code;
220219

@@ -229,7 +228,7 @@ public function getPrevious()
229228
/**
230229
* @return $this
231230
*/
232-
public function setPrevious(self $previous)
231+
public function setPrevious(LegacyFlattenException $previous): self
233232
{
234233
$this->previous = $previous;
235234

@@ -272,7 +271,7 @@ public function setTraceFromThrowable(\Throwable $throwable)
272271
/**
273272
* @return $this
274273
*/
275-
public function setTrace($trace, $file, $line)
274+
public function setTrace($trace, $file, $line): self
276275
{
277276
$this->trace = [];
278277
$this->trace[] = [

src/Symfony/Component/ErrorRenderer/Resources/stubs/Exception/FlattenException.php

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/Symfony/Component/ErrorRenderer/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
],
2222
"require": {
2323
"php": "^7.1.3",
24-
"psr/log": "~1.0"
24+
"psr/log": "~1.0",
25+
"symfony/debug": "^4.4"
2526
},
2627
"require-dev": {
2728
"symfony/console": "^4.4",
@@ -33,7 +34,6 @@
3334
},
3435
"autoload": {
3536
"psr-4": { "Symfony\\Component\\ErrorRenderer\\": "" },
36-
"classmap": [ "Resources/stubs/Exception/FlattenException.php" ],
3737
"exclude-from-classmap": [
3838
"/Tests/"
3939
]

src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Component\HttpKernel\EventListener;
1313

1414
use Psr\Log\LoggerInterface;
15-
use Symfony\Component\Debug\Exception\FlattenException as LegacyFlattenException;
1615
use Symfony\Component\ErrorRenderer\Exception\FlattenException;
1716
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
1817
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -124,21 +123,9 @@ protected function logException(\Exception $exception, $message)
124123
*/
125124
protected function duplicateRequest(\Exception $exception, Request $request)
126125
{
127-
@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));
128-
129-
$flattenException = FlattenException::createFromThrowable($exception);
130-
131-
// BC layer to be removed in 5.0
132-
if (class_exists(\Symfony\Component\Debug\Debug::class, false)) {
133-
$legacyFlattenException = LegacyFlattenException::createFromThrowable($exception);
134-
} else {
135-
$legacyFlattenException = $flattenException;
136-
}
137-
138126
$attributes = [
139127
'_controller' => $this->controller,
140-
'exception' => $legacyFlattenException, // to be removed in 5.0
141-
'e' => $flattenException,
128+
'exception' => FlattenException::createFromThrowable($exception),
142129
'logger' => $this->logger instanceof DebugLoggerInterface ? $this->logger : null,
143130
];
144131
$request = $request->duplicate(null, null, $attributes);

0 commit comments

Comments
 (0)