FastRoute icon indicating copy to clipboard operation
FastRoute copied to clipboard

Suport optinal middle segment

Open GoldraK opened this issue 3 years ago • 1 comments

Hello, They could accept this PR (#179), it would be very useful for example to create file managers, not forcing to always have a path from the base path.

In the current situation the url would have to be like this

/file/{path:[A-Za-z0-9\/]+}/{file:[\w,\s-]+\.[A-Za-z]{3,4}}

with this expression I can make these routes

files/mandatory-folder/file.jpg
files/obligatory-folder/another-folder/file.jpg

but i can't do

files/file.jpg

since path is always required.

Thanks for the work.

GoldraK avatar Mar 12 '22 10:03 GoldraK

This is exactly what I need. My hotfix: I use query param:

$request->getQueryParams();

icetee avatar Aug 28 '23 12:08 icetee

The implementation in #179 has some performance impact that needs to be considered (extra calls, recursion, etc). I'll look into ways to reduce it as much as possible...

I'm hesitant to prioritise/consider this due to its limited benefit. It's possible to register two routes (/file/{path:[A-Za-z0-9\/]+}/{file:[\w,\s-]+\.[A-Za-z]{3,4}} and /file/{file:[\w,\s-]+\.[A-Za-z]{3,4}}) that point to the same handler.

Let's keep the discussion on the PR, though :+1:

lcobucci avatar Jan 09 '24 21:01 lcobucci