Skip to content

Commit

Permalink
bug #2310 Use isMainRequest when available (ruudk)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.x branch.

Discussion
----------

Use `isMainRequest` when available

Symfony 5.3 deprecates `isMasterRequest` in favor of `isMainRequest`.

Commits
-------

9b85fd7 Use `isMainRequest` when available
  • Loading branch information
xabbuh committed Jul 9, 2021
2 parents 2dc8c34 + 9b85fd7 commit b91a484
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions EventListener/ResponseStatusCodeListener.php
Expand Up @@ -15,6 +15,7 @@
use FOS\RestBundle\Util\ExceptionValueMap;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\Event\KernelEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;

Expand All @@ -41,7 +42,7 @@ public static function getSubscribedEvents(): array

public function getResponseStatusCodeFromThrowable(ExceptionEvent $event): void
{
if (!$event->isMasterRequest()) {
if (!$this->isMainRequest($event)) {
return;
}

Expand All @@ -60,7 +61,7 @@ public function getResponseStatusCodeFromThrowable(ExceptionEvent $event): void

public function setResponseStatusCode(ResponseEvent $event): void
{
if (!$event->isMasterRequest()) {
if (!$this->isMainRequest($event)) {
return;
}

Expand All @@ -70,4 +71,13 @@ public function setResponseStatusCode(ResponseEvent $event): void
$this->responseStatusCode = null;
}
}

private function isMainRequest(KernelEvent $event): bool
{
if (method_exists($event, 'isMainRequest')) {
return $event->isMainRequest();
}

return $event->isMasterRequest();
}
}

0 comments on commit b91a484

Please sign in to comment.