From 2275c746607b092536b17efb11b5cafed5ad9503 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 31 Jul 2011 14:48:17 -0500 Subject: [PATCH] moved all routing classes into routing namespace. --- public/index.php | 8 ++-- system/error.php | 2 +- .../{route_filter.php => routing/filter.php} | 4 +- .../{route_finder.php => routing/finder.php} | 4 +- system/routing/loader.php | 33 +++++++++++++++++ system/{ => routing}/route.php | 8 ++-- system/{ => routing}/router.php | 37 +++---------------- 7 files changed, 53 insertions(+), 43 deletions(-) rename system/{route_filter.php => routing/filter.php} (94%) rename system/{route_finder.php => routing/finder.php} (97%) create mode 100644 system/routing/loader.php rename system/{ => routing}/route.php (84%) rename system/{ => routing}/router.php (78%) diff --git a/public/index.php b/public/index.php index e3d175eb..5cc31efc 100644 --- a/public/index.php +++ b/public/index.php @@ -138,14 +138,16 @@ // -------------------------------------------------------------- // 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 @@ // ---------------------------------------------------------- // Execute the global "after" filter. // ---------------------------------------------------------- -System\Route_Filter::call('after', array($response)); +System\Routing\Filter::call('after', array($response)); // ---------------------------------------------------------- // Stringify the response. diff --git a/system/error.php b/system/error.php index 4bf65a54..f6196723 100644 --- a/system/error.php +++ b/system/error.php @@ -62,7 +62,7 @@ private static function show($e, $severity, $message) { if (Config::get('error.detail')) { - $view = View::make('exception') + $view = View::make('error/exception') ->bind('severity', $severity) ->bind('message', $message) ->bind('file', $e->getFile()) diff --git a/system/route_filter.php b/system/routing/filter.php similarity index 94% rename from system/route_filter.php rename to system/routing/filter.php index 5fd9e10c..2286bd42 100644 --- a/system/route_filter.php +++ b/system/routing/filter.php @@ -1,6 +1,6 @@ - $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 diff --git a/system/route.php b/system/routing/route.php similarity index 84% rename from system/route.php rename to system/routing/route.php index f078e848..97710159 100644 --- a/system/route.php +++ b/system/routing/route.php @@ -1,4 +1,6 @@ -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 @@ public function call() 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; diff --git a/system/router.php b/system/routing/router.php similarity index 78% rename from system/router.php rename to system/routing/router.php index 6103995a..29f83d93 100644 --- a/system/router.php +++ b/system/routing/router.php @@ -1,4 +1,6 @@ -request = $method.' /'.trim($uri, '/'); - - $this->routes = (is_array($routes)) ? $routes : $this->load($uri); + $this->routes = $routes; } /** @@ -46,34 +47,6 @@ public static function make($method, $uri, $routes = null) 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. *