moved all routing classes into routing namespace.
This commit is contained in:
parent
d8eba6389c
commit
2275c74660
|
@ -138,14 +138,16 @@
|
||||||
// --------------------------------------------------------------
|
// --------------------------------------------------------------
|
||||||
// Execute the global "before" filter.
|
// 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.
|
// Execute the route function.
|
||||||
// ----------------------------------------------------------
|
// ----------------------------------------------------------
|
||||||
if (is_null($response))
|
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();
|
$response = (is_null($route)) ? System\Response::make(System\View::make('error/404'), 404) : $route->call();
|
||||||
}
|
}
|
||||||
|
@ -157,7 +159,7 @@
|
||||||
// ----------------------------------------------------------
|
// ----------------------------------------------------------
|
||||||
// Execute the global "after" filter.
|
// Execute the global "after" filter.
|
||||||
// ----------------------------------------------------------
|
// ----------------------------------------------------------
|
||||||
System\Route_Filter::call('after', array($response));
|
System\Routing\Filter::call('after', array($response));
|
||||||
|
|
||||||
// ----------------------------------------------------------
|
// ----------------------------------------------------------
|
||||||
// Stringify the response.
|
// Stringify the response.
|
||||||
|
|
|
@ -62,7 +62,7 @@ private static function show($e, $severity, $message)
|
||||||
{
|
{
|
||||||
if (Config::get('error.detail'))
|
if (Config::get('error.detail'))
|
||||||
{
|
{
|
||||||
$view = View::make('exception')
|
$view = View::make('error/exception')
|
||||||
->bind('severity', $severity)
|
->bind('severity', $severity)
|
||||||
->bind('message', $message)
|
->bind('message', $message)
|
||||||
->bind('file', $e->getFile())
|
->bind('file', $e->getFile())
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php namespace System;
|
<?php namespace System\Routing;
|
||||||
|
|
||||||
class Route_Filter {
|
class Filter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The loaded route filters.
|
* The loaded route filters.
|
|
@ -1,6 +1,6 @@
|
||||||
<?php namespace System;
|
<?php namespace System\Routing;
|
||||||
|
|
||||||
class Route_Finder {
|
class Finder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All of the loaded routes.
|
* All of the loaded routes.
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,4 +1,6 @@
|
||||||
<?php namespace System;
|
<?php namespace System\Routing;
|
||||||
|
|
||||||
|
use System\Response;
|
||||||
|
|
||||||
class Route {
|
class Route {
|
||||||
|
|
||||||
|
@ -55,7 +57,7 @@ public function call()
|
||||||
}
|
}
|
||||||
elseif (is_array($this->callback))
|
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']))
|
if (is_null($response) and isset($this->callback['do']))
|
||||||
{
|
{
|
||||||
|
@ -67,7 +69,7 @@ public function call()
|
||||||
|
|
||||||
if (is_array($this->callback) and isset($this->callback['after']))
|
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;
|
return $response;
|
|
@ -1,4 +1,6 @@
|
||||||
<?php namespace System;
|
<?php namespace System\Routing;
|
||||||
|
|
||||||
|
use System\Request;
|
||||||
|
|
||||||
class Router {
|
class Router {
|
||||||
|
|
||||||
|
@ -24,13 +26,12 @@ class Router {
|
||||||
* @param array $routes
|
* @param array $routes
|
||||||
* @return void
|
* @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
|
// Put the request method and URI in route form. Routes begin with
|
||||||
// the request method and a forward slash.
|
// the request method and a forward slash.
|
||||||
$this->request = $method.' /'.trim($uri, '/');
|
$this->request = $method.' /'.trim($uri, '/');
|
||||||
|
$this->routes = $routes;
|
||||||
$this->routes = (is_array($routes)) ? $routes : $this->load($uri);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,34 +47,6 @@ public static function make($method, $uri, $routes = null)
|
||||||
return new static($method, $uri, $routes);
|
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.
|
* Search a set of routes for the route matching a method and URI.
|
||||||
*
|
*
|
Loading…
Reference in New Issue