tryRestoreSession($_COOKIE[SESSION_COOKIE_NAME] ?? null, $_COOKIE[SESSION_REMEMBERME_COOKIE_NAME] ?? null); $user = $guard->hasUser() ? $guard->getUser() : $guard->getUser(0); // Fetch guest record (userid=0) if no user could be restored } else { $user = $guard->getUser(0); // Fetch guest } /** @var $sentry Raven_Client */ if (isset($sentry) && isset($user)) { $sentry->user_context([ 'id' => $user->user_id, 'username' => $user->username, ]); } $path = explode('/', $_GET['path']); switch ($path[0] ?: 'index') { case 'manga': case 'title': $controller = new MangaController(); break; case 'chapter': $controller = new ChapterController(); break; case 'user': $controller = new UserController(); break; case 'group': $controller = new GroupController(); break; case 'tag': $controller = new TagController(); break; case 'relations': $controller = new RelationTypeController(); break; case 'follows': $controller = new FollowsController(); break; case 'index': $controller = new IndexController(); break; case 'highest_chapter_id': $controller = new HighestChapterIDController(); break; default: throw new NotFoundHttpException("Invalid endpoint"); break; } $response = $controller->handleRequest(array_slice($path, 1)); } catch (HttpException $e) { $response->setCode($e->getCode()); $response->setMessage($e->getMessage()); } catch (\Throwable $e) { $response->setCode(500); $response->setMessage(DEBUG ? $e->getMessage() : "Internal server error"); } finally { header('Content-Type: application/json'); http_response_code($response->getCode()); echo json_encode($response->normalize()); }