Lemon-Framework / Lemon

🍋 A php microframework
https://lemon-framework.github.io/docs/
GNU General Public License v3.0
24 stars 8 forks source link

[HTTP] adds Request::mustBe #135

Closed tenmajkl closed 1 year ago

tenmajkl commented 1 year ago

This PR adds method mustBe to Request. It suspends parent fiber (mostly route callback) when request is not given content-type.

:nail_care:


// instead of
Route::post("/users/add", function(Request $r) {
    if ($request->aint('application/json')) {
         return 'error';
    }
    // ...
});

// you can do just
Route::post("/users/add", function(Request $r) {
    $request->mustBe('application/json'), 'error');
    // ...
});