nikic / FastRoute

Fast request router for PHP
Other
5.12k stars 445 forks source link

Suport optinal middle segment #250

Closed GoldraK closed 10 months ago

GoldraK commented 2 years ago

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.

icetee commented 1 year ago

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

$request->getQueryParams();
lcobucci commented 10 months ago

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: