flightphp / core

An extensible micro-framework for PHP
https://docs.flightphp.com
MIT License
2.63k stars 407 forks source link

Dinamic params on routes #469

Closed riv0tril closed 9 months ago

riv0tril commented 2 years ago

Find an alternative to the following or directly initialize the array as empty since the params are already inside the route object.

https://github.com/mikecao/flight/blob/2df64f37ea76ce98b97ed327c6b1f5ea2a5df2b0/flight/Engine.php#L359

This line generates conflicts when it comes to extracting the params using the method Flight::route('/', array($greeting, 'hello'), true); You will find that the order of the parameters passed into the callback method (in this case 'hello') changes depending on whether there are any params in the request or not.

because of this https://github.com/mikecao/flight/blob/2df64f37ea76ce98b97ed327c6b1f5ea2a5df2b0/flight/Engine.php#L366-L370

Other possible solutions is once the routing proccess is done, set the params into the request object.

If you still can't figure out the scenario, think of an abstract controller where all routes execute the same public method and concrete controllers implement this class.

n0nag0n commented 9 months ago

Since the framework is 100% unit tested now, if you could help create a pull request, or at least an example code of what happens, that would be very helpful!