nikic / FastRoute

Fast request router for PHP
Other
5.13k stars 444 forks source link

Return variable as array #248

Closed lookingdown closed 10 months ago

lookingdown commented 2 years ago

Is there a way to get variables returned in an array instead of individually.. Like so Instead of $app->get('/nanna/{name}[/{id}[/{product}[/{size}]]]', function($name, $id, $product, $size ) {

Like so $app->get('/nanna/{name}[/{id}[/{product}[/{size}]]]', function(array $params ) {

And then access in $params ( $params['name'], $params[''id] etcetera) , that would be very useful no need to named variable in route setup et al and so on ..

Currently using Leocavalcante/siler Route and works like this.. but is not maintained anymore and need to use FastRoute (perhaps).. (also multiple optional middle segments AS well which I find useful)

:)

lcobucci commented 10 months ago

@lookingdown apologies for the really late response.

I'm not sure how you're integrating FastRoute into your application but the dispatch result already contains all matched route variables in an array: https://github.com/nikic/FastRoute?tab=readme-ov-file#dispatching-a-uri