The URL Router in Alloy Framework (currently a work-in-progress) might be of some use to you. You can use Alloy\Router and Alloy\Router\Route independent of the framework itself, because there is no coupling or outside dependencies.
Basically, It uses a routing syntax like this:
PHP Code:
// View vehicle record
$router->route('vehicle', '/<#year>/<:make>/<:model>')
->defaults(array(
'module' => 'Vehicle',
'action' => 'view',
'format' => 'html'
));
And does a string match on a URL to produce an array of key/value pairs like this:
PHP Code:
// URL like this
$url = $_SERVER['REQUEST_URI']; // '2008/ferrari/f430'
// Match URL to provided routes
$params = $router->match('GET', $url); // <HTTP Method, URL>
/*
// Resulting params would look like this:
$params = array(
'year' => '2008',
'make' => 'ferrari',
'model' => 'f430',
'module' => 'Vehicle',
'action' => 'view',
'format' => 'html'
);
*/
It also does reverse matching to produce URLs for links:
PHP Code:
// To produce '2008/ferrari/f430' again
$linkUrl = $router->url('vehicle', array(
'year' => '2008',
'make' => 'ferrari',
'model' => 'f430'
));
It's the only PHP URL router I know of that is this easy and flexible, is REST-based, and has no other framework inter-dependencies. It was modeled after the URL router in Merb and Rails.
Bookmarks