Skip to content

Commit

Permalink
refactor the Flight router calls
Browse files Browse the repository at this point in the history
  • Loading branch information
pjc09h committed Jun 1, 2024
1 parent 57aa98b commit 4747268
Show file tree
Hide file tree
Showing 19 changed files with 200 additions and 79 deletions.
3 changes: 3 additions & 0 deletions app/Twig.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ function ($lock_to = null) {
[ "is_safe" => ["html"] ]
));

# https://kint-php.github.io/kint/advanced/#twig
$twig->addExtension(new \Kint\Twig\TwigExtension());

/*
# DebugBar
$profile = new \Twig\Profiler\Profile();
Expand Down
6 changes: 6 additions & 0 deletions bootstrap/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
$app = Gazelle\App::go();
$app->executionContext = "web";

# load the error handler
# https://github.com/filp/whoops
$whoops = new \Whoops\Run();
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
$whoops->register();

# quick sanity checks
$app->gotcha();

Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@
"ergebnis/composer-normalize": "^2.42.0",
"erusev/parsedown": "1.8.0-beta-7",
"erusev/parsedown-extra": "0.8.0",
"filp/whoops": "^2.15",
"firebase/php-jwt": "^6.10",
"foolz/sphinxql-query-builder": "^3.0.2",
"friendsofphp/php-cs-fixer": "^3.57.1",
"guzzlehttp/guzzle": "^7.8.1",
"illuminate/database": "^9.52.16",
"illuminate/support": "^9.52.16",
"kint-php/kint": "^4.2.3",
"kint-php/kint-twig": "^5.0",
"maximebf/debugbar": "^1.22.3",
"mikecao/flight": "^2.0.1",
"minishlink/web-push": "^8.0",
Expand Down
120 changes: 119 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions routes/api/better.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,35 @@
*/

# badFolders
Flight::route("GET /api/better/badFolders(/@snatchedOnly)", ["Gazelle\Api\Better", "badFolders"])->addMiddleware(function () {
Flight::get("/api/better/badFolders(/@snatchedOnly)", ["Gazelle\Api\Better", "badFolders"])->addMiddleware(function () {
$app = Gazelle\App::go();
$app->middleware(["torrents" => "read"]);
});


# badTags
Flight::route("GET /api/better/badTags(/@snatchedOnly)", ["Gazelle\Api\Better", "badTags"])->addMiddleware(function () {
Flight::get("/api/better/badTags(/@snatchedOnly)", ["Gazelle\Api\Better", "badTags"])->addMiddleware(function () {
$app = Gazelle\App::go();
$app->middleware(["torrents" => "read"]);
});


# missingCitations
Flight::route("GET /api/better/missingCitations(/@snatchedOnly)", ["Gazelle\Api\Better", "missingCitations"])->addMiddleware(function () {
Flight::get("/api/better/missingCitations(/@snatchedOnly)", ["Gazelle\Api\Better", "missingCitations"])->addMiddleware(function () {
$app = Gazelle\App::go();
$app->middleware(["torrents" => "read"]);
});


# missingPictures
Flight::route("GET /api/better/missingPictures(/@snatchedOnly)", ["Gazelle\Api\Better", "missingPictures"])->addMiddleware(function () {
Flight::get("/api/better/missingPictures(/@snatchedOnly)", ["Gazelle\Api\Better", "missingPictures"])->addMiddleware(function () {
$app = Gazelle\App::go();
$app->middleware(["torrents" => "read"]);
});


# singleSeeder
Flight::route("GET /api/better/singleSeeder(/@snatchedOnly)", ["Gazelle\Api\Better", "singleSeeder"])->addMiddleware(function () {
Flight::get("/api/better/singleSeeder(/@snatchedOnly)", ["Gazelle\Api\Better", "singleSeeder"])->addMiddleware(function () {
$app = Gazelle\App::go();
$app->middleware(["torrents" => "read"]);
});
2 changes: 1 addition & 1 deletion routes/api/bonusPoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
*/

# checkout
Flight::route("POST /api/store/checkout/@item", ["Gazelle\Api\BonusPoints", "checkout"]);
Flight::post("/api/store/checkout/@item", ["Gazelle\Api\BonusPoints", "checkout"]);
10 changes: 5 additions & 5 deletions routes/api/collages.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,35 @@
*/

# browse
Flight::route("POST /api/collages/browse", ["Gazelle\Api\Collages", "browse"])->addMiddleware(function () {
Flight::post("/api/collages/browse", ["Gazelle\Api\Collages", "browse"])->addMiddleware(function () {
$app = Gazelle\App::go();
$app->middleware(["collages" => "read"]);
});


# create
Flight::route("POST /api/collages", ["Gazelle\Api\Collages", "create"])->addMiddleware(function () {
Flight::post("/api/collages", ["Gazelle\Api\Collages", "create"])->addMiddleware(function () {
$app = Gazelle\App::go();
$app->middleware(["collages" => "create"]);
});


# read
Flight::route("GET /api/collages/@identifier", ["Gazelle\Api\Collages", "read"])->addMiddleware(function () {
Flight::get("/api/collages/@identifier", ["Gazelle\Api\Collages", "read"])->addMiddleware(function () {
$app = Gazelle\App::go();
$app->middleware(["collages" => "read"]);
});


# update
Flight::route("PATCH /api/collages/@identifier", ["Gazelle\Api\Collages", "update"])->addMiddleware(function () {
Flight::patch("/api/collages/@identifier", ["Gazelle\Api\Collages", "update"])->addMiddleware(function () {
$app = Gazelle\App::go();
$app->middleware(["collages" => "update"]);
});


# delete
Flight::route("DELETE /api/collages/@identifier", ["Gazelle\Api\Collages", "delete"])->addMiddleware(function () {
Flight::delete("/api/collages/@identifier", ["Gazelle\Api\Collages", "delete"])->addMiddleware(function () {
$app = Gazelle\App::go();
$app->middleware(["collages" => "delete"]);
});
10 changes: 5 additions & 5 deletions routes/api/creators.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,35 @@
*/

# browse
Flight::route("POST /api/creators/browse", ["Gazelle\Api\Creators", "browse"])->addMiddleware(function () {
Flight::post("/api/creators/browse", ["Gazelle\Api\Creators", "browse"])->addMiddleware(function () {
$app = Gazelle\App::go();
$app->middleware(["creators" => "read"]);
});


# create
Flight::route("POST /api/creators", ["Gazelle\Api\Creators", "create"])->addMiddleware(function () {
Flight::post("/api/creators", ["Gazelle\Api\Creators", "create"])->addMiddleware(function () {
$app = Gazelle\App::go();
$app->middleware(["creators" => "create"]);
});


# read
Flight::route("GET /api/creators/@identifier", ["Gazelle\Api\Creators", "read"])->addMiddleware(function () {
Flight::get("/api/creators/@identifier", ["Gazelle\Api\Creators", "read"])->addMiddleware(function () {
$app = Gazelle\App::go();
$app->middleware(["creators" => "read"]);
});


# update
Flight::route("PATCH /api/creators/@identifier", ["Gazelle\Api\Creators", "update"])->addMiddleware(function () {
Flight::patch("/api/creators/@identifier", ["Gazelle\Api\Creators", "update"])->addMiddleware(function () {
$app = Gazelle\App::go();
$app->middleware(["creators" => "update"]);
});


# delete
Flight::route("DELETE /api/creators/@identifier", ["Gazelle\Api\Creators", "delete"])->addMiddleware(function () {
Flight::delete("/api/creators/@identifier", ["Gazelle\Api\Creators", "delete"])->addMiddleware(function () {
$app = Gazelle\App::go();
$app->middleware(["creators" => "delete"]);
});
8 changes: 4 additions & 4 deletions routes/api/friends.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@
*/

# create
Flight::route("POST /api/friends", ["Gazelle\Api\Friends", "create"])->addMiddleware(function () {
Flight::post("/api/friends", ["Gazelle\Api\Friends", "create"])->addMiddleware(function () {
$app = Gazelle\App::go();
$app->middleware(["userProfiles" => "create"]);
});


# read
Flight::route("GET /api/friends(/@identifier)", ["Gazelle\Api\Friends", "read"])->addMiddleware(function () {
Flight::get("/api/friends(/@identifier)", ["Gazelle\Api\Friends", "read"])->addMiddleware(function () {
$app = Gazelle\App::go();
$app->middleware(["userProfiles" => "read"]);
});


# update
Flight::route("PATCH /api/friends/@identifier", ["Gazelle\Api\Friends", "update"])->addMiddleware(function () {
Flight::patch("/api/friends/@identifier", ["Gazelle\Api\Friends", "update"])->addMiddleware(function () {
$app = Gazelle\App::go();
$app->middleware(["userProfiles" => "update"]);
});


# delete
Flight::route("DELETE /api/friends/@identifier", ["Gazelle\Api\Friends", "delete"])->addMiddleware(function () {
Flight::delete("/api/friends/@identifier", ["Gazelle\Api\Friends", "delete"])->addMiddleware(function () {
$app = Gazelle\App::go();
$app->middleware(["userProfiles" => "delete"]);
});
10 changes: 5 additions & 5 deletions routes/api/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,35 @@
*/

# browse
Flight::route("POST /api/groups/browse", ["Gazelle\Api\Groups", "browse"])->addMiddleware(function () {
Flight::post("/api/groups/browse", ["Gazelle\Api\Groups", "browse"])->addMiddleware(function () {
$app = Gazelle\App::go();
$app->middleware(["torrentGroups" => "read"]);
});


# create
Flight::route("POST /api/groups", ["Gazelle\Api\Groups", "create"])->addMiddleware(function () {
Flight::post("/api/groups", ["Gazelle\Api\Groups", "create"])->addMiddleware(function () {
$app = Gazelle\App::go();
$app->middleware(["torrentGroups" => "create"]);
});


# read
Flight::route("GET /api/groups/@identifier", ["Gazelle\Api\Groups", "read"])->addMiddleware(function () {
Flight::get("/api/groups/@identifier", ["Gazelle\Api\Groups", "read"])->addMiddleware(function () {
$app = Gazelle\App::go();
$app->middleware(["torrentGroups" => "read"]);
});


# update
Flight::route("PATCH /api/groups/@identifier", ["Gazelle\Api\Groups", "update"])->addMiddleware(function () {
Flight::patch("/api/groups/@identifier", ["Gazelle\Api\Groups", "update"])->addMiddleware(function () {
$app = Gazelle\App::go();
$app->middleware(["torrentGroups" => "update"]);
});


# delete
Flight::route("DELETE /api/groups/@identifier", ["Gazelle\Api\Groups", "delete"])->addMiddleware(function () {
Flight::delete("/api/groups/@identifier", ["Gazelle\Api\Groups", "delete"])->addMiddleware(function () {
$app = Gazelle\App::go();
$app->middleware(["torrentGroups" => "delete"]);
});
Loading

0 comments on commit 4747268

Please sign in to comment.