Keeping backward compatibility with legacy FlattenException usage
This commit is contained in:
parent
62216ea677
commit
928363c408
|
@ -155,6 +155,33 @@ HttpKernel
|
||||||
current directory or with a glob pattern. The fallback directories have never been advocated
|
current directory or with a glob pattern. The fallback directories have never been advocated
|
||||||
so you likely do not use those in any app based on the SF Standard or Flex edition.
|
so you likely do not use those in any app based on the SF Standard or Flex edition.
|
||||||
* Getting the container from a non-booted kernel is deprecated
|
* Getting the container from a non-booted kernel is deprecated
|
||||||
|
* Deprecated passing the `exception` attribute (instance of `Symfony\Component\Debug\Exception\FlattenException`)
|
||||||
|
to the configured controller of the `ExceptionListener`, use the `e` attribute
|
||||||
|
(instance of `Symfony\Component\ErrorRenderer\Exception\FlattenException`) instead
|
||||||
|
|
||||||
|
before:
|
||||||
|
```php
|
||||||
|
use Symfony\Component\Debug\Exception\FlattenException;
|
||||||
|
|
||||||
|
class ExceptionController
|
||||||
|
{
|
||||||
|
public function __invoke(FlattenException $exception)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
after:
|
||||||
|
```php
|
||||||
|
use Symfony\Component\ErrorRenderer\Exception\FlattenException;
|
||||||
|
|
||||||
|
class ExceptionController
|
||||||
|
{
|
||||||
|
public function __invoke(FlattenException $e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
Lock
|
Lock
|
||||||
----
|
----
|
||||||
|
|
|
@ -341,6 +341,33 @@ HttpKernel
|
||||||
* Removed the second and third argument of `FileLocator::__construct`
|
* Removed the second and third argument of `FileLocator::__construct`
|
||||||
* Removed loading resources from `%kernel.root_dir%/Resources` and `%kernel.root_dir%` as
|
* Removed loading resources from `%kernel.root_dir%/Resources` and `%kernel.root_dir%` as
|
||||||
fallback directories.
|
fallback directories.
|
||||||
|
* Removed passing the `exception` attribute (instance of `Symfony\Component\Debug\Exception\FlattenException`)
|
||||||
|
to the configured controller of the `ExceptionListener`, use the `e` attribute
|
||||||
|
(instance of `Symfony\Component\ErrorRenderer\Exception\FlattenException`) instead
|
||||||
|
|
||||||
|
before:
|
||||||
|
```php
|
||||||
|
use Symfony\Component\Debug\Exception\FlattenException;
|
||||||
|
|
||||||
|
class ExceptionController
|
||||||
|
{
|
||||||
|
public function __invoke(FlattenException $exception)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
after:
|
||||||
|
```php
|
||||||
|
use Symfony\Component\ErrorRenderer\Exception\FlattenException;
|
||||||
|
|
||||||
|
class ExceptionController
|
||||||
|
{
|
||||||
|
public function __invoke(FlattenException $e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
Intl
|
Intl
|
||||||
----
|
----
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
namespace Symfony\Bundle\TwigBundle\Controller;
|
namespace Symfony\Bundle\TwigBundle\Controller;
|
||||||
|
|
||||||
use Symfony\Component\ErrorRenderer\Exception\FlattenException;
|
use Symfony\Component\Debug\Exception\FlattenException;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
|
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
namespace Symfony\Bundle\TwigBundle\Controller;
|
namespace Symfony\Bundle\TwigBundle\Controller;
|
||||||
|
|
||||||
use Symfony\Component\ErrorRenderer\Exception\FlattenException;
|
use Symfony\Component\Debug\Exception\FlattenException;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace Symfony\Bundle\TwigBundle\Tests\Controller;
|
||||||
|
|
||||||
use Symfony\Bundle\TwigBundle\Controller\ExceptionController;
|
use Symfony\Bundle\TwigBundle\Controller\ExceptionController;
|
||||||
use Symfony\Bundle\TwigBundle\Tests\TestCase;
|
use Symfony\Bundle\TwigBundle\Tests\TestCase;
|
||||||
use Symfony\Component\ErrorRenderer\Exception\FlattenException;
|
use Symfony\Component\Debug\Exception\FlattenException;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Twig\Environment;
|
use Twig\Environment;
|
||||||
use Twig\Loader\ArrayLoader;
|
use Twig\Loader\ArrayLoader;
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace Symfony\Bundle\TwigBundle\Tests\Controller;
|
||||||
|
|
||||||
use Symfony\Bundle\TwigBundle\Controller\PreviewErrorController;
|
use Symfony\Bundle\TwigBundle\Controller\PreviewErrorController;
|
||||||
use Symfony\Bundle\TwigBundle\Tests\TestCase;
|
use Symfony\Bundle\TwigBundle\Tests\TestCase;
|
||||||
use Symfony\Component\ErrorRenderer\Exception\FlattenException;
|
use Symfony\Component\Debug\Exception\FlattenException;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||||
|
|
|
@ -22,6 +22,8 @@ use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
|
||||||
* Basically, this class removes all objects from the trace.
|
* Basically, this class removes all objects from the trace.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
*/
|
*/
|
||||||
class FlattenException
|
class FlattenException
|
||||||
{
|
{
|
||||||
|
@ -37,6 +39,11 @@ class FlattenException
|
||||||
private $file;
|
private $file;
|
||||||
private $line;
|
private $line;
|
||||||
|
|
||||||
|
public static function create(\Exception $exception, int $statusCode = null, array $headers = []): self
|
||||||
|
{
|
||||||
|
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 = []): self
|
||||||
{
|
{
|
||||||
$e = new static();
|
$e = new static();
|
||||||
|
@ -374,18 +381,3 @@ class FlattenException
|
||||||
return rtrim($message);
|
return rtrim($message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
|
@ -33,6 +33,7 @@
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": { "Symfony\\Component\\ErrorRenderer\\": "" },
|
"psr-4": { "Symfony\\Component\\ErrorRenderer\\": "" },
|
||||||
|
"classmap": [ "Resources/stubs/Exception/FlattenException.php" ],
|
||||||
"exclude-from-classmap": [
|
"exclude-from-classmap": [
|
||||||
"/Tests/"
|
"/Tests/"
|
||||||
]
|
]
|
||||||
|
|
|
@ -15,6 +15,8 @@ CHANGELOG
|
||||||
* Marked all dispatched event classes as `@final`
|
* Marked all dispatched event classes as `@final`
|
||||||
* Added `ErrorController` to enable the preview and error rendering mechanism
|
* Added `ErrorController` to enable the preview and error rendering mechanism
|
||||||
* Getting the container from a non-booted kernel is deprecated.
|
* Getting the container from a non-booted kernel is deprecated.
|
||||||
|
* Deprecated passing the `exception` attribute (instance of `Symfony\Component\Debug\Exception\FlattenException`)
|
||||||
|
to the configured controller of the `ExceptionListener`
|
||||||
|
|
||||||
4.3.0
|
4.3.0
|
||||||
-----
|
-----
|
||||||
|
|
|
@ -37,12 +37,12 @@ class ErrorController
|
||||||
$this->errorRenderer = $errorRenderer;
|
$this->errorRenderer = $errorRenderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __invoke(Request $request, FlattenException $exception): Response
|
public function __invoke(Request $request, FlattenException $e): Response
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return new Response($this->errorRenderer->render($exception, $request->getPreferredFormat()), $exception->getStatusCode(), $exception->getHeaders());
|
return new Response($this->errorRenderer->render($e, $request->getPreferredFormat()), $e->getStatusCode(), $e->getHeaders());
|
||||||
} catch (ErrorRendererNotFoundException $e) {
|
} catch (ErrorRendererNotFoundException $_) {
|
||||||
return new Response($this->errorRenderer->render($exception), $exception->getStatusCode(), $exception->getHeaders());
|
return new Response($this->errorRenderer->render($e), $e->getStatusCode(), $e->getHeaders());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ class ErrorController
|
||||||
*/
|
*/
|
||||||
$subRequest = $request->duplicate(null, null, [
|
$subRequest = $request->duplicate(null, null, [
|
||||||
'_controller' => $this->controller,
|
'_controller' => $this->controller,
|
||||||
'exception' => $exception,
|
'e' => $exception,
|
||||||
'logger' => null,
|
'logger' => null,
|
||||||
'showException' => false,
|
'showException' => false,
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
namespace Symfony\Component\HttpKernel\EventListener;
|
namespace Symfony\Component\HttpKernel\EventListener;
|
||||||
|
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Symfony\Component\Debug\Exception\FlattenException as LegacyFlattenException;
|
||||||
use Symfony\Component\ErrorRenderer\Exception\FlattenException;
|
use Symfony\Component\ErrorRenderer\Exception\FlattenException;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
|
@ -123,9 +124,21 @@ class ExceptionListener implements EventSubscriberInterface
|
||||||
*/
|
*/
|
||||||
protected function duplicateRequest(\Exception $exception, Request $request)
|
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 = [
|
$attributes = [
|
||||||
'_controller' => $this->controller,
|
'_controller' => $this->controller,
|
||||||
'exception' => FlattenException::createFromThrowable($exception),
|
'exception' => $legacyFlattenException, // to be removed in 5.0
|
||||||
|
'e' => $flattenException,
|
||||||
'logger' => $this->logger instanceof DebugLoggerInterface ? $this->logger : null,
|
'logger' => $this->logger instanceof DebugLoggerInterface ? $this->logger : null,
|
||||||
];
|
];
|
||||||
$request = $request->duplicate(null, null, $attributes);
|
$request = $request->duplicate(null, null, $attributes);
|
||||||
|
|
|
@ -103,7 +103,7 @@ class ErrorControllerTest extends TestCase
|
||||||
->method('handle')
|
->method('handle')
|
||||||
->with(
|
->with(
|
||||||
$this->callback(function (Request $request) use ($_controller, $code) {
|
$this->callback(function (Request $request) use ($_controller, $code) {
|
||||||
$exception = $request->attributes->get('exception');
|
$exception = $request->attributes->get('e');
|
||||||
|
|
||||||
$this->assertSame($_controller, $request->attributes->get('_controller'));
|
$this->assertSame($_controller, $request->attributes->get('_controller'));
|
||||||
$this->assertInstanceOf(FlattenException::class, $exception);
|
$this->assertInstanceOf(FlattenException::class, $exception);
|
||||||
|
|
Reference in New Issue