working on routing architecture.

This commit is contained in:
Taylor Otwell
2011-07-31 21:51:55 -05:00
parent 344f49e1bf
commit 0af326b636
6 changed files with 59 additions and 22 deletions

View File

@@ -8,28 +8,35 @@ class Loader {
* @param string
* @return array
*/
public static function load($uri)
public function load($uri)
{
$base = require APP_PATH.'routes'.EXT;
if ( ! is_dir(APP_PATH.'routes') or $uri == '')
{
return $base;
}
return (is_dir(APP_PATH.'routes') and $uri != '') ? array_merge($this->load_nested_routes($uri), $base) : $base;
}
list($routes, $segments) = array(array(), explode('/', $uri));
/**
* Load the appropriate routes from the routes directory.
*
* This is done by working down the URI until we find the deepest
* possible matching route file.
*
* @param string $uri
* @return array
*/
private function load_nested_routes($uri)
{
$segments = explode('/', $uri);
foreach (array_reverse($segments, true) as $key => $value)
{
if (file_exists($path = ROUTE_PATH.implode('/', array_slice($segments, 0, $key + 1)).EXT))
{
$routes = require $path;
break;
return require $path;
}
}
return array_merge($routes, $base);
}
return array();
}
}