This is a very simply routing system that makes it easy to test requests to different paths. This is very limited so do not use for your applications - it's just for fun.
require('route.php');
// A user profile
route('/(\w+)/profile', function($path, $user)
{
print "Hello " . $user;
});
// Home page
route('/', function($path)
{
print "Hello World";
});
// Catch all fun
route('.+', function($path)
{
print "You are at: " . $path;
});
// Run request
route(getenv('REQUEST_URI'));
The first argument is the path you wish to call or save the callback for.
route($path, ....);
The second argument must be callable, so you can use
route('/', function () { /* ... */ });
route('/', 'function');
route('/', array($Object, 'method'));
route('/', array('Class', 'staticMethod'));
route('/', $Object); // Used with __invoke
Sorry, in order to fit in under 140 characters I had to remove support for GET|POST|HEAD|OPTIONS|DELETE|PUT...
:(