public static function restRouteHandler(GetResponseEvent $event) { $request = $event->getRequest(); if (!$request) { return; } $route = $request->route; if ($route->name != 'rest') { return; } $response = $event->getPixie()->restService->handleRequest($request, $event->getCookie()); if ($response) { $event->setResponse($response); } }
public static function redirectUnauthorized(GetResponseEvent $event) { $request = $event->getRequest(); if (!$request || !$request->isAdminPath() || !($event->getException() instanceof UnauthorizedException || $event->getException() instanceof ForbiddenException)) { return; } $pixie = $event->getPixie(); if ($event->getException() instanceof ForbiddenException) { if ($pixie->auth->has_role('admin')) { return; } $pixie->session->flash('error', 'You don\'t have permissions to access this resource.'); } $response = new Response($pixie); $response->redirect('/admin/user/login?return_url=' . rawurlencode($_SERVER['REQUEST_URI'])); $event->setResponse($response); }