leoPHPard
Quick url router filter for routes with regular expressions that don't span multiple url pieces., (*1)
It takes an partial of this format: a/b/c/d, (*2)
And an array of routes with or without regular expressions:, (*3)
a/c/d/f, (*4)
some/account/{[0-9]{2,10}/, (*5)
a/{[a-z]}/c/d, (*6)
In this case the list will become, (*7)
a/{[a-z]}/c/d, (*8)
You can plug this in your favourite router that handles regular expressions matching - it will look at maching one rule instead of 3., (*9)
With a few hundred or thousand rules there is a noticeable increase in speed., (*10)
As long as your regular expressions don't span different url pieces (cointain slashes in them) you can use them. For instance this is not a good url to be used with this library: some/url{[0-9]/data}/download, (*11)
Install
- composer install with minimum-stability set at dev
- download the src/Filter.php and uset it
Usage
See test/FilterTest.php or test_random_benchmark/bench.php for usage examples, (*12)
Take a look into test_random_benchmark:. With 1000 random urls with 5-7 pieces of [a-z] or {regexp}, it takes around 2ms (0.0002s) to filter very obvious non-matching rules., (*13)
Work in progress
Improvements to follow
- add more filtering
- better readme :)
- logging (although not sure it's needed?), (*14)
Any feedback is welcome, (*15)