QUESTION: switch-route /route/ ending with "/" not the same as /route/
lookingdown opened this issue · comments
Thanks for a very useful script.
Tried this out as (and will use it in a project) it seemed logical that a switch approach would be a lot faster than traditional approaches to switching.
In my usecase of 50 odd routes its in the order of magnitude faster :) .. than others including fastroute :)
With regards to the routes a route of /user/shop/{id}/products/ do not correspond to url of /user/shop/cakestore/products/ .. not found but /user/shop/{id}/products does .. Is there a way to allow trailing slash in route so that route (example ) /user/shop/{shop}/products/ corresponds to /user/shop/cakestore/products/ AND /user/shop/{shop}/products/{id} corresponds to /user/shop/cakestore/products/45
As it works now a trailing slash is identified as another segment..
(I mainly route to a php file ['include' => 'products.php'] and need an array of variables in my case $params['{$vars[key]}'=>$segments[$vars[value]..] AND $params[0] for trimmed $path value )
Might be good to consider adding variable access for include files.. but since the level of difficulty adding in the return for 'include' route is quite low in my case its not necessary.. BUT allow for trailing slash in routes would be great..
I think the idea is brilliant to generate a route script like this..
Cheers
Trailing slashes are trimmed. See https://github.com/jasny/switch-route/blob/master/src/Generator/GenerateFunction.php#L62
Without that, it should probably work as you would like.