public function PageNotFoundEventSubscriber::onNotFoundException in Apigee API Catalog 8
Same name and namespace in other branches
- 8.2 src/EventSubscriber/PageNotFoundEventSubscriber.php \Drupal\apigee_api_catalog\EventSubscriber\PageNotFoundEventSubscriber::onNotFoundException()
Redirects to the apidoc canonical route if we have a not found exception.
Parameters
\Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event: The exception event.
File
- src/
EventSubscriber/ PageNotFoundEventSubscriber.php, line 71
Class
- PageNotFoundEventSubscriber
- Handles not found exceptions for apidoc entities.
Namespace
Drupal\apigee_api_catalog\EventSubscriberCode
public function onNotFoundException(GetResponseForExceptionEvent $event) {
// Check if the request uri matches an apidoc canonical route.
// Also check for apidoc valid path.
if ($event
->getException() instanceof NotFoundHttpException && ($uri = $event
->getRequest()
->getRequestUri()) && $this->pathMatcher
->matchPath($uri, '/api/*/*') && (list(, , $id) = explode('/', $uri)) && ($path = "/api/{$id}") && $this->pathValidator
->isValid($path)) {
// Redirect to the apidoc.
$event
->setResponse(new RedirectResponse($path));
}
}