Is there an standalone PHP routing library? [closed]
Try Klein:
Single file, standalone and robust:
"klein.php is a lightning fast router for PHP 5.3+"
- Flexible regular expression routing (inspired by Sinatra)
- A set of boilerplate methods for rapidly building web apps
- Almost no overhead => 2500+ requests/second
Due to the oldish answers on this question I think it would be a pretty good idea to mention some more up-to-date solutions to the case in the OP.
The 2 solutions which came to my mind as soon as I saw your question ware:
- FastRoute https://github.com/nikic/FastRoute - Written by Nikita Popov
- Phroute https://github.com/mrjgreen/phroute - Written by Joe Green
Phroute is built on top of FastRoute, hence they both require PHP 5.4.
If you need a PHP 5.3+ solution, I would definitely recommend Slim Framework's routing. If you don't want any of the other functionality which come with the framework, you might extract the Routing parts and use only them (SLIM is MIT licensed, so you are allowed to do whatever)
Ive used the slim routing standalone, in a project of mine - DaGhostman\CodeWave @ github, see tags <=2.4, the relative parts are in Application\Core
& Application\Controller
.
Fastroute is a standalone routing library. It's based on an OOP model and has a full testing framework. Open Source and Licence is free. If you are looking for something to modify for your own projects this is a good place to start.