flightphp / core

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

match part of url, to either of the provided phrase or word, without making it optional #467

Closed ThetripGr closed 9 months ago

ThetripGr commented 2 years ago

Hello , i need to do something like the following but i can't seem to get the syntax right or something.

Flight::route("/$langRegex/a-url-part|another-url-part(/@permalink:[0-9a-z\-]+)", function ($permalink) {
   //...rest of code
});

so how I need this to behave -> 1) First match the languange (a simple e[nl] check ) 2) Then i want to match either a-url-part or another-url-part 3) Then look for the optional parameter inside the parenthesis, that's after either of the options before

i tried /$langRegex/(a-url-part|another-url-part)(/@permalink:[0-9a-z\-]+) this kinda does work but it makes the (a-url-part|another-url-part) part , optional which is something i do not want because then any url with just /$langRegex/ will match on this route.

Is there a way to make this work with just the syntax or a regex , without duplicating the block of code?

n0nag0n commented 9 months ago

Do you still need this?