From e40faa1945c7e53b688cd62f59a2a72d8acc3d5f Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 2 Aug 2011 21:23:13 -0500 Subject: [PATCH] changed application file structure and routing definitions. --- application/{ => routes}/filters.php | 0 application/{ => routes}/routes.php | 0 application/{ => views}/composers.php | 0 public/index.php | 4 +-- system/routing/loader.php | 40 ++++++++++----------------- system/view.php | 2 +- 6 files changed, 17 insertions(+), 29 deletions(-) rename application/{ => routes}/filters.php (100%) rename application/{ => routes}/routes.php (100%) rename application/{ => views}/composers.php (100%) diff --git a/application/filters.php b/application/routes/filters.php similarity index 100% rename from application/filters.php rename to application/routes/filters.php diff --git a/application/routes.php b/application/routes/routes.php similarity index 100% rename from application/routes.php rename to application/routes/routes.php diff --git a/application/composers.php b/application/views/composers.php similarity index 100% rename from application/composers.php rename to application/views/composers.php diff --git a/public/index.php b/public/index.php index 11c3f6af..6d9097a9 100644 --- a/public/index.php +++ b/public/index.php @@ -158,7 +158,7 @@ // -------------------------------------------------------------- // Register the route filters. // -------------------------------------------------------------- -System\Routing\Filter::register(require APP_PATH.'filters'.EXT); +System\Routing\Filter::register(require ROUTE_PATH.'filters'.EXT); // -------------------------------------------------------------- // Execute the global "before" filter. @@ -170,7 +170,7 @@ // ---------------------------------------------------------- if (is_null($response)) { - $route = System\Routing\Router::make(System\Request::method(), System\Request::uri(), new System\Routing\Loader(APP_PATH))->route(); + $route = System\Routing\Router::make(System\Request::method(), System\Request::uri(), new System\Routing\Loader(ROUTE_PATH))->route(); $response = (is_null($route)) ? System\Response::error('404') : $route->call(); } diff --git a/system/routing/loader.php b/system/routing/loader.php index cff3a5db..1185ccdb 100644 --- a/system/routing/loader.php +++ b/system/routing/loader.php @@ -35,14 +35,7 @@ public function __construct($path) */ public function load($uri) { - $base = require $this->path.'routes'.EXT; - - if ( ! is_dir($this->path.'routes') or $uri == '') - { - return $base; - } - - return array_merge($this->load_nested_routes($uri), $base); + return array_merge($this->load_nested_routes($uri), require $this->path.'routes'.EXT); } /** @@ -56,12 +49,12 @@ private function load_nested_routes($uri) $segments = explode('/', $uri); // Work backwards through the URI segments until we find the deepest possible - // matching route file in the routes directory. + // matching route directory. Once we find it, we will return those routes. foreach (array_reverse($segments, true) as $key => $value) { - if (file_exists($path = $this->path.'routes/'.implode('/', array_slice($segments, 0, $key + 1)).EXT)) + if (is_dir($path = $this->path.implode('/', array_slice($segments, 0, $key + 1)))) { - return require $path; + return require $path.'/routes'.EXT; } } @@ -78,28 +71,23 @@ private function load_nested_routes($uri) * @param string $path * @return array */ - public static function all($reload = false, $path = null) + public static function all($reload = false, $path = ROUTE_PATH) { if ( ! is_null(static::$routes) and ! $reload) return static::$routes; - if (is_null($path)) $path = APP_PATH; - $routes = require $path.'routes'.EXT; - if (is_dir($path.'routes')) + // Since route files can be nested deep within the route directory, we need to + // recursively spin through the directory to find every file. + $directoryIterator = new \RecursiveDirectoryIterator($path); + + $recursiveIterator = new \RecursiveIteratorIterator($directoryIterator, \RecursiveIteratorIterator::SELF_FIRST); + + foreach ($recursiveIterator as $file) { - // Since route files can be nested deep within the route directory, we need to - // recursively spin through the directory to find every file. - $directoryIterator = new \RecursiveDirectoryIterator($path.'routes'); - - $recursiveIterator = new \RecursiveIteratorIterator($directoryIterator, \RecursiveIteratorIterator::SELF_FIRST); - - foreach ($recursiveIterator as $file) + if (filetype($file) === 'file' and strpos($file, EXT) !== false and strpos($file, 'filters'.EXT) === false) { - if (filetype($file) === 'file' and strpos($file, EXT) !== false) - { - $routes = array_merge(require $file, $routes); - } + $routes = array_merge(require $file, $routes); } } diff --git a/system/view.php b/system/view.php index f91f7dfe..f1ca82d7 100644 --- a/system/view.php +++ b/system/view.php @@ -61,7 +61,7 @@ public static function make($view, $data = array()) { if (is_null(static::$composers)) { - static::$composers = require APP_PATH.'composers'.EXT; + static::$composers = require VIEW_PATH.'composers'.EXT; } $instance = new static($view, $data);