Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: 6b102c761e
Fetching contributors…

Cannot retrieve contributors at this time

38 lines (33 sloc) 0.805 kB
<?php
/* Router */
/* by Ben Crowder <ben.crowder@gmail.com> */
/* http://bencrowder.net/coding/router */
/* Modified by Chad Hansen */
class Router
{
public static function route($uri, $routes, $defaultHandler)
{
$found = false;
// go through each route and see if it matches; if so, execute the handler
foreach ($routes as $pattern=>$handler)
{
if (preg_match($pattern, $uri, $matches))
{
call_user_func($handler, array_slice($matches, 1));
$found = true;
break;
}
}
// call the default handler
if (!$found)
{
call_user_func($defaultHandler, $uri);
}
}
public static function routeURI($routes, $defaultHandler)
{
$uri = $_SERVER['REQUEST_URI'];
self::route($uri, $routes, $defaultHandler);
}
}
?>
Jump to Line
Something went wrong with that request. Please try again.