Commit 06cb63f5 by Taylor Otwell

removed route\loader and route\parser classes.

parent ad824341
<?php namespace System\Route;
class Loader {
/**
* Load the route file based on the first segment of the URI.
*
* @param string $uri
* @return void
*/
public static function load($uri)
{
if ( ! is_dir(APP_PATH.'routes'))
{
return require APP_PATH.'routes'.EXT;
}
if ( ! file_exists(APP_PATH.'routes/home'.EXT))
{
throw new \Exception("A [home] route file is required when using a route directory.");
}
if ($uri == '/')
{
return require APP_PATH.'routes/home'.EXT;
}
else
{
$segments = explode('/', trim($uri, '/'));
if ( ! file_exists(APP_PATH.'routes/'.$segments[0].EXT))
{
return require APP_PATH.'routes/home'.EXT;
}
return array_merge(require APP_PATH.'routes/'.$segments[0].EXT, require APP_PATH.'routes/home'.EXT);
}
}
}
\ No newline at end of file
<?php namespace System\Route;
class Parser {
/**
* Get the parameters that should be passed to the route callback.
*
* @param string $uri
* @param string $route
* @return array
*/
public static function parameters($uri, $route)
{
$parameters = array();
$uri_segments = explode('/', $uri);
$route_segments = explode('/', $route);
// --------------------------------------------------------------
// Any route segment wrapped in parentheses is a parameter.
// --------------------------------------------------------------
for ($i = 0; $i < count($route_segments); $i++)
{
if (strpos($route_segments[$i], '(') === 0)
{
$parameters[] = $uri_segments[$i];
}
}
return $parameters;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment