Skip to content

Commit 82a9e46

Browse files
committed
Keeping backward compatibility with legacy FlattenException usage
1 parent 62216ea commit 82a9e46

File tree

13 files changed

+104
-26
lines changed

13 files changed

+104
-26
lines changed

UPGRADE-4.4.md

+27
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,33 @@ HttpKernel
155155
current directory or with a glob pattern. The fallback directories have never been advocated
156156
so you likely do not use those in any app based on the SF Standard or Flex edition.
157157
* Getting the container from a non-booted kernel is deprecated
158+
* Deprecated passing the `exception` attribute (instance of `Symfony\Component\Debug\Exception\FlattenException`)
159+
to the configured controller of the `ExceptionListener`, use the `e` attribute
160+
(instance of `Symfony\Component\ErrorRenderer\Exception\FlattenException`) instead
161+
162+
before:
163+
```php
164+
use Symfony\Component\Debug\Exception\FlattenException;
165+
166+
class ExceptionController
167+
{
168+
public function __invoke(FlattenException $exception)
169+
{
170+
}
171+
}
172+
```
173+
174+
after:
175+
```php
176+
use Symfony\Component\ErrorRenderer\Exception\FlattenException;
177+
178+
class ExceptionController
179+
{
180+
public function __invoke(FlattenException $e)
181+
{
182+
}
183+
}
184+
```
158185

159186
Lock
160187
----

UPGRADE-5.0.md

+27
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,33 @@ HttpKernel
341341
* Removed the second and third argument of `FileLocator::__construct`
342342
* Removed loading resources from `%kernel.root_dir%/Resources` and `%kernel.root_dir%` as
343343
fallback directories.
344+
* Removed passing the `exception` attribute (instance of `Symfony\Component\Debug\Exception\FlattenException`)
345+
to the configured controller of the `ExceptionListener`, use the `e` attribute
346+
(instance of `Symfony\Component\ErrorRenderer\Exception\FlattenException`) instead
347+
348+
before:
349+
```php
350+
use Symfony\Component\Debug\Exception\FlattenException;
351+
352+
class ExceptionController
353+
{
354+
public function __invoke(FlattenException $exception)
355+
{
356+
}
357+
}
358+
```
359+
360+
after:
361+
```php
362+
use Symfony\Component\ErrorRenderer\Exception\FlattenException;
363+
364+
class ExceptionController
365+
{
366+
public function __invoke(FlattenException $e)
367+
{
368+
}
369+
}
370+
```
344371

345372
Intl
346373
----

src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Bundle\TwigBundle\Controller;
1313

14-
use Symfony\Component\ErrorRenderer\Exception\FlattenException;
14+
use Symfony\Component\Debug\Exception\FlattenException;
1515
use Symfony\Component\HttpFoundation\Request;
1616
use Symfony\Component\HttpFoundation\Response;
1717
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;

src/Symfony/Bundle/TwigBundle/Controller/PreviewErrorController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Bundle\TwigBundle\Controller;
1313

14-
use Symfony\Component\ErrorRenderer\Exception\FlattenException;
14+
use Symfony\Component\Debug\Exception\FlattenException;
1515
use Symfony\Component\HttpFoundation\Request;
1616
use Symfony\Component\HttpKernel\HttpKernelInterface;
1717

src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Symfony\Bundle\TwigBundle\Controller\ExceptionController;
1515
use Symfony\Bundle\TwigBundle\Tests\TestCase;
16-
use Symfony\Component\ErrorRenderer\Exception\FlattenException;
16+
use Symfony\Component\Debug\Exception\FlattenException;
1717
use Symfony\Component\HttpFoundation\Request;
1818
use Twig\Environment;
1919
use Twig\Loader\ArrayLoader;

src/Symfony/Bundle/TwigBundle/Tests/Controller/PreviewErrorControllerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Symfony\Bundle\TwigBundle\Controller\PreviewErrorController;
1515
use Symfony\Bundle\TwigBundle\Tests\TestCase;
16-
use Symfony\Component\ErrorRenderer\Exception\FlattenException;
16+
use Symfony\Component\Debug\Exception\FlattenException;
1717
use Symfony\Component\HttpFoundation\Request;
1818
use Symfony\Component\HttpFoundation\Response;
1919
use Symfony\Component\HttpKernel\HttpKernelInterface;

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

+7-15
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
* Basically, this class removes all objects from the trace.
2323
*
2424
* @author Fabien Potencier <fabien@symfony.com>
25+
*
26+
* @internal
2527
*/
2628
class FlattenException
2729
{
@@ -37,6 +39,11 @@ class FlattenException
3739
private $file;
3840
private $line;
3941

42+
public static function create(\Exception $exception, int $statusCode = null, array $headers = []): self
43+
{
44+
return static::createFromThrowable($exception, $statusCode, $headers);
45+
}
46+
4047
public static function createFromThrowable(\Throwable $exception, int $statusCode = null, array $headers = []): self
4148
{
4249
$e = new static();
@@ -374,18 +381,3 @@ public function getAsString()
374381
return rtrim($message);
375382
}
376383
}
377-
378-
namespace Symfony\Component\Debug\Exception;
379-
380-
if (!class_exists(FlattenException::class, false)) {
381-
class_alias(\Symfony\Component\ErrorRenderer\Exception\FlattenException::class, FlattenException::class);
382-
}
383-
384-
if (false) {
385-
/**
386-
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorRenderer\Exception\FlattenException instead.
387-
*/
388-
class FlattenException extends \Symfony\Component\ErrorRenderer\Exception\FlattenException
389-
{
390-
}
391-
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Debug\Exception;
13+
14+
if (!class_exists(FlattenException::class, false)) {
15+
class_alias(\Symfony\Component\ErrorRenderer\Exception\FlattenException::class, FlattenException::class);
16+
}
17+
18+
if (false) {
19+
/**
20+
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorRenderer\Exception\FlattenException instead.
21+
*/
22+
class FlattenException extends \Symfony\Component\ErrorRenderer\Exception\FlattenException
23+
{
24+
}
25+
}

src/Symfony/Component/ErrorRenderer/composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
},
3434
"autoload": {
3535
"psr-4": { "Symfony\\Component\\ErrorRenderer\\": "" },
36+
"classmap": [ "Resources/stubs/Exception/FlattenException.php" ],
3637
"exclude-from-classmap": [
3738
"/Tests/"
3839
]

src/Symfony/Component/HttpKernel/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ CHANGELOG
1515
* Marked all dispatched event classes as `@final`
1616
* Added `ErrorController` to enable the preview and error rendering mechanism
1717
* Getting the container from a non-booted kernel is deprecated.
18+
* Deprecated passing the `exception` attribute (instance of `Symfony\Component\Debug\Exception\FlattenException`)
19+
to the configured controller of the `ExceptionListener`
1820

1921
4.3.0
2022
-----

src/Symfony/Component/HttpKernel/Controller/ErrorController.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ public function __construct(HttpKernelInterface $kernel, $controller, ErrorRende
3737
$this->errorRenderer = $errorRenderer;
3838
}
3939

40-
public function __invoke(Request $request, FlattenException $exception): Response
40+
public function __invoke(Request $request, FlattenException $e): Response
4141
{
4242
try {
43-
return new Response($this->errorRenderer->render($exception, $request->getPreferredFormat()), $exception->getStatusCode(), $exception->getHeaders());
44-
} catch (ErrorRendererNotFoundException $e) {
45-
return new Response($this->errorRenderer->render($exception), $exception->getStatusCode(), $exception->getHeaders());
43+
return new Response($this->errorRenderer->render($e, $request->getPreferredFormat()), $e->getStatusCode(), $e->getHeaders());
44+
} catch (ErrorRendererNotFoundException $_) {
45+
return new Response($this->errorRenderer->render($e), $e->getStatusCode(), $e->getHeaders());
4646
}
4747
}
4848

@@ -57,7 +57,7 @@ public function preview(Request $request, int $code): Response
5757
*/
5858
$subRequest = $request->duplicate(null, null, [
5959
'_controller' => $this->controller,
60-
'exception' => $exception,
60+
'e' => $exception,
6161
'logger' => null,
6262
'showException' => false,
6363
]);

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\HttpKernel\EventListener;
1313

1414
use Psr\Log\LoggerInterface;
15+
use Symfony\Component\Debug\Exception\FlattenException as LegacyFlattenException;
1516
use Symfony\Component\ErrorRenderer\Exception\FlattenException;
1617
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
1718
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -123,9 +124,12 @@ protected function logException(\Exception $exception, $message)
123124
*/
124125
protected function duplicateRequest(\Exception $exception, Request $request)
125126
{
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+
126129
$attributes = [
127130
'_controller' => $this->controller,
128-
'exception' => FlattenException::createFromThrowable($exception),
131+
'exception' => LegacyFlattenException::createFromThrowable($exception), // to be removed in 5.0
132+
'e' => FlattenException::createFromThrowable($exception),
129133
'logger' => $this->logger instanceof DebugLoggerInterface ? $this->logger : null,
130134
];
131135
$request = $request->duplicate(null, null, $attributes);

src/Symfony/Component/HttpKernel/Tests/Controller/ErrorControllerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function testPreviewController()
103103
->method('handle')
104104
->with(
105105
$this->callback(function (Request $request) use ($_controller, $code) {
106-
$exception = $request->attributes->get('exception');
106+
$exception = $request->attributes->get('e');
107107

108108
$this->assertSame($_controller, $request->attributes->get('_controller'));
109109
$this->assertInstanceOf(FlattenException::class, $exception);

0 commit comments

Comments
 (0)