bug #34662 [HttpKernel] Support typehint to deprecated FlattenException in controller (andrew-demb)

This PR was squashed before being merged into the 4.4 branch.

Discussion
----------

[HttpKernel] Support typehint to deprecated FlattenException in controller

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #34661
| License       | MIT
| Doc PR        |

We should support converting throwable to `FlattenException` with typehint to deprecated class also

Commits
-------

26b4e372dd [HttpKernel] Support typehint to deprecated FlattenException in controller
This commit is contained in:
Nicolas Grekas 2019-11-28 08:56:36 +01:00
commit f9e6f11bea

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\HttpKernel\EventListener;
use Psr\Log\LoggerInterface;
use Symfony\Component\Debug\Exception\FlattenException as LegacyFlattenException;
use Symfony\Component\ErrorHandler\Exception\FlattenException;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@ -98,7 +99,7 @@ class ErrorListener implements EventSubscriberInterface
$r = new \ReflectionFunction(\Closure::fromCallable($event->getController()));
$r = $r->getParameters()[$k] ?? null;
if ($r && (!$r->hasType() || FlattenException::class === $r->getType()->getName())) {
if ($r && (!$r->hasType() || \in_array($r->getType()->getName(), [FlattenException::class, LegacyFlattenException::class], true])) {
$arguments = $event->getArguments();
$arguments[$k] = FlattenException::createFromThrowable($e);
$event->setArguments($arguments);