Skip to content

Commit 788f203

Browse files
nicolas-grekasteohhanhui
authored andcommitted
fix compat with Symfony 5
1 parent 208964b commit 788f203

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

phpstan.neon.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,12 @@ parameters:
116116
-
117117
message: '#Parameter \$exception of method ApiPlatform\\Core\\Action\\ExceptionAction::__invoke\(\) has invalid typehint type Symfony\\Component\\ErrorHandler\\Exception\\FlattenException\.#'
118118
path: %currentWorkingDirectory%/src/Action/ExceptionAction.php
119+
119120
- '#Call to method get(Class|Headers|StatusCode)\(\) on an unknown class Symfony\\Component\\ErrorHandler\\Exception\\FlattenException\.#'
120121
- '#Class Symfony\\Component\\ErrorHandler\\Exception\\FlattenException not found\.#'
121122
-
122123
message: '#Instanceof between bool\|float\|int|null and ArrayObject will always evaluate to false\.#'
123124
paths:
124125
- %currentWorkingDirectory%/src/JsonApi/Serializer/ItemNormalizer.php
125126
- %currentWorkingDirectory%/src/Serializer/AbstractItemNormalizer.php
127+
- '#Symfony\\Component\\HttpKernel\\EventListener\\ErrorListener#'

src/Bridge/Symfony/Validator/EventListener/ValidationExceptionListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct(SerializerInterface $serializer, array $errorFormats
4040
*/
4141
public function onKernelException(ExceptionEvent $event): void
4242
{
43-
$exception = $event->getException();
43+
$exception = method_exists($event, 'getThrowable') ? $event->getThrowable() : $event->getException();
4444
if (!$exception instanceof ValidationException) {
4545
return;
4646
}

src/EventListener/ExceptionListener.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use ApiPlatform\Core\Util\RequestAttributesExtractor;
1717
use Psr\Log\LoggerInterface;
1818
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
19+
use Symfony\Component\HttpKernel\EventListener\ErrorListener;
1920
use Symfony\Component\HttpKernel\EventListener\ExceptionListener as BaseExceptionListener;
2021

2122
/**
@@ -30,7 +31,11 @@ final class ExceptionListener
3031

3132
public function __construct($controller, LoggerInterface $logger = null, $debug = false)
3233
{
33-
$this->exceptionListener = new BaseExceptionListener($controller, $logger, $debug);
34+
if (class_exists(ErrorListener::class)) {
35+
$this->exceptionListener = new ErrorListener($controller, $logger, $debug);
36+
} else {
37+
$this->exceptionListener = new BaseExceptionListener($controller, $logger, $debug);
38+
}
3439
}
3540

3641
public function onKernelException(ExceptionEvent $event): void

0 commit comments

Comments
 (0)