I am currently using the lumen framework (5.6) to build an API, this API can be used to request a page by for example its title. The route for this is:
Route::group(["prefix" => '/api/v1', "middleware" => ["ContentTypeJson","Paginator"]], function () {
Route::group(["prefix" => '/{databaseIdentifier}', "middleware"=>"DatabaseIdentifier"], function () {
Route::group(["prefix" => '/pages'], function () {
Route::group(["prefix" => '/{title}'], function () {
Route::get("/", "PageController@getPageByTitle");
Route::get("/parents", "SearchController@getParentalSpecies");
Route::get("/all", "PageController@getPageByTitleWithLinks");
Route::get("/overlap/{overlapProperty}", "PageController@getPagesWithOverlap");
Route::put("/", "PageController@overwritePage");
});
});
});
As you can see the title
is used in multiple functions and controllers, the same applies to the databaseIdentifier
which is used in the middleware to determine which database needs to be used.
However all url parameters with a space will be converted with %20
instead of a space, which is the expected behaviour. However I would like to convert this back to the raw string, which can be done with urldecode()
.
But since this is applied in every controller and function I would like to use some kind of preprocessing step for this.
I have tried using a middleware for this to alter the route parameters as suggested here (using $request->route()->setParameter('key', $value);
).
Unfortunately this does not work in lumen since the result of $request->route()
is an array and not an object. I have tried altering this array but I can not get it to change the actual array in the Request
object. No error appears here.
So in short: I am looking for a way to urldecode every URL parameter which is passed to my controllers and functions without putting $param = urldecode($param);
everywhere.
If you need more information feel free to ask
Thank you in advance