Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Merge pull request #218 from jeroennoten/patch-1
Browse files Browse the repository at this point in the history
Replace the use of deprecated get/setException() by get/setThrowable()
  • Loading branch information
sampart authored Dec 2, 2019
2 parents 5421d5e + 2f6066a commit 6df5608
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
19 changes: 16 additions & 3 deletions EventListener/ConvertNotValidCurrentPageToNotFoundListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,21 @@ class ConvertNotValidCurrentPageToNotFoundListener implements EventSubscriberInt
*/
public function onException(GetResponseForExceptionEvent $event)
{
if ($event->getException() instanceof NotValidCurrentPageException) {
$event->setException(new NotFoundHttpException('Page Not Found', $event->getException()));
if (method_exists($event, 'getThrowable')) {
$throwable = $event->getThrowable();
} else {
// Support for Symfony 4.3 and before
$throwable = $event->getException();
}

if ($throwable instanceof NotValidCurrentPageException) {
$notFoundHttpException = new NotFoundHttpException('Page Not Found', $throwable);
if (method_exists($event, 'setThrowable')) {
$event->setThrowable($notFoundHttpException);
} else {
// Support for Symfony 4.3 and before
$event->setException($notFoundHttpException);
}
}
}

Expand All @@ -28,4 +41,4 @@ public static function getSubscribedEvents()
KernelEvents::EXCEPTION => array('onException', 512)
);
}
}
}
19 changes: 16 additions & 3 deletions EventListener/ConvertNotValidMaxPerPageToNotFoundListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,21 @@ class ConvertNotValidMaxPerPageToNotFoundListener implements EventSubscriberInte
*/
public function onException(GetResponseForExceptionEvent $event)
{
if ($event->getException() instanceof NotValidMaxPerPageException) {
$event->setException(new NotFoundHttpException('Page Not Found', $event->getException()));
if (method_exists($event, 'getThrowable')) {
$throwable = $event->getThrowable();
} else {
// Support for Symfony 4.3 and before
$throwable = $event->getException();
}

if ($throwable instanceof NotValidMaxPerPageException) {
$notFoundHttpException = new NotFoundHttpException('Page Not Found', $throwable);
if (method_exists($event, 'setThrowable')) {
$event->setThrowable($notFoundHttpException);
} else {
// Support for Symfony 4.3 and before
$event->setException($notFoundHttpException);
}
}
}

Expand All @@ -28,4 +41,4 @@ public static function getSubscribedEvents()
KernelEvents::EXCEPTION => array('onException', 512)
);
}
}
}

0 comments on commit 6df5608

Please sign in to comment.