Commit 2275c746 authored by Taylor Otwell's avatar Taylor Otwell

moved all routing classes into routing namespace.

parent d8eba638
......@@ -138,14 +138,16 @@ if (System\Config::get('session.driver') != '')
// --------------------------------------------------------------
// Execute the global "before" filter.
// --------------------------------------------------------------
$response = System\Route_Filter::call('before', array(), true);
$response = System\Routing\Filter::call('before', array(), true);
// ----------------------------------------------------------
// Execute the route function.
// ----------------------------------------------------------
if (is_null($response))
{
$route = System\Router::make(System\Request::method(), System\Request::uri())->route();
list($method, $uri) = array(System\Request::method(), System\Request::uri());
$route = System\Routing\Router::make($method, $uri, System\Routing\Loader::load($uri))->route();
$response = (is_null($route)) ? System\Response::make(System\View::make('error/404'), 404) : $route->call();
}
......@@ -157,7 +159,7 @@ else
// ----------------------------------------------------------
// Execute the global "after" filter.
// ----------------------------------------------------------
System\Route_Filter::call('after', array($response));
System\Routing\Filter::call('after', array($response));
// ----------------------------------------------------------
// Stringify the response.
......
......@@ -62,7 +62,7 @@ class Error {
{
if (Config::get('error.detail'))
{
$view = View::make('exception')
$view = View::make('error/exception')
->bind('severity', $severity)
->bind('message', $message)
->bind('file', $e->getFile())
......
<?php namespace System;
<?php namespace System\Routing;
class Route_Filter {
class Filter {
/**
* The loaded route filters.
......
<?php namespace System;
<?php namespace System\Routing;
class Route_Finder {
class Finder {
/**
* All of the loaded routes.
......
<?php namespace System\Routing;
class Loader {
/**
* Load the appropriate routes for the request URI.
*
* @param string
* @return array
*/
public static function load($uri)
{
$base = require APP_PATH.'routes'.EXT;
if ( ! is_dir(APP_PATH.'routes') or $uri == '')
{
return $base;
}
list($routes, $segments) = array(array(), 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;
}
}
return array_merge($routes, $base);
}
}
\ No newline at end of file
<?php namespace System;
<?php namespace System\Routing;
use System\Response;
class Route {
......@@ -55,7 +57,7 @@ class Route {
}
elseif (is_array($this->callback))
{
$response = isset($this->callback['before']) ? Route_Filter::call($this->callback['before'], array(), true) : null;
$response = isset($this->callback['before']) ? Filter::call($this->callback['before'], array(), true) : null;
if (is_null($response) and isset($this->callback['do']))
{
......@@ -67,7 +69,7 @@ class Route {
if (is_array($this->callback) and isset($this->callback['after']))
{
Route_Filter::call($this->callback['after'], array($response));
Filter::call($this->callback['after'], array($response));
}
return $response;
......
<?php namespace System;
<?php namespace System\Routing;
use System\Request;
class Router {
......@@ -24,13 +26,12 @@ class Router {
* @param array $routes
* @return void
*/
public function __construct($method, $uri, $routes = null)
public function __construct($method, $uri, $routes)
{
// Put the request method and URI in route form. Routes begin with
// the request method and a forward slash.
$this->request = $method.' /'.trim($uri, '/');
$this->routes = (is_array($routes)) ? $routes : $this->load($uri);
$this->routes = $routes;
}
/**
......@@ -46,34 +47,6 @@ class Router {
return new static($method, $uri, $routes);
}
/**
* Load the appropriate routes for the request URI.
*
* @param string $uri
* @return array
*/
public function load($uri)
{
$base = require APP_PATH.'routes'.EXT;
if ( ! is_dir(APP_PATH.'routes') or $uri == '')
{
return $base;
}
list($routes, $segments) = array(array(), 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;
}
}
return array_merge($routes, $base);
}
/**
* Search a set of routes for the route matching a method and URI.
*
......
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