plugin-endpoints
plugin-endpoints copied to clipboard
Adds regex comparison
Because sometimes you want to enable things on /category/, but not on /category/product/. /category/?$ will achieve that. All the declarations work as normal.
I have no idea how to test this functionality besides clicking on things.
Hi @javorszky,
While I love the idea of supporting regexes in routes, I'm thinking something along the lines of how NGINX does it (prefix that indicates a regex follows) would be better suited here.
This because the performance cost of a regex can really add up in scale. Here's a rough (relative) performance comparison:
10 endpoints, no match
stripos: 0.14 secondspreg_match: 0.34 seconds
100 endpoints, no match
stripos: 0.19 secondspreg_match: 1.1 seconds
1000 endpoints, no match
stripos: 0.73 secondspreg_match: 7.84 seconds
I'll have a play with other options over the next few days to see what could be a good solution here. :)
PS. You can run these benchmarks yourself by running the newly added tests/benchmark.php file.
php tests/benchmark.php 1000
Another option is to simply pull in nikic's FastRoute or my AltoRouter as then we'd have a very powerful router at a minimal performance cost, but it'll still be more complex and slower than a simple string comparison.