From 5f3d40b76c82907cbee6d0af1345c01e4e77352a Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 1 Aug 2011 08:47:45 -0500 Subject: [PATCH 1/8] Added support for in-memory SQLite databases. --- system/db/connector.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/system/db/connector.php b/system/db/connector.php index 769f4f27..c93e34cd 100644 --- a/system/db/connector.php +++ b/system/db/connector.php @@ -47,14 +47,19 @@ class Connector { * Establish a PDO connection to a SQLite database. * * SQLite database paths can be specified either relative to the application/db - * directory, or as an absolute path to any location on the file system. + * directory, or as an absolute path to any location on the file system. In-memory + * databases are also supported. * * @param object $config * @return PDO */ private static function connect_to_sqlite($config) { - if (file_exists($path = DATABASE_PATH.$config->database.'.sqlite')) + if ($config->database == ':memory:') + { + return new \PDO('sqlite::memory:', null, null, static::$options); + } + elseif (file_exists($path = DATABASE_PATH.$config->database.'.sqlite')) { return new \PDO('sqlite:'.$path, null, null, static::$options); } From 23d5742575acb481a2b34053f3eea6ddfe1dae6e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 1 Aug 2011 09:15:03 -0500 Subject: [PATCH 2/8] remove item caching from cache manager. --- system/cache.php | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/system/cache.php b/system/cache.php index 4bdd1185..30e541b8 100644 --- a/system/cache.php +++ b/system/cache.php @@ -9,13 +9,6 @@ class Cache { */ public static $drivers = array(); - /** - * All of the items retrieved by the cache drivers. - * - * @var array - */ - public static $items = array(); - /** * Get a cache driver instance. If no driver name is specified, the default * cache driver will be returned as defined in the cache configuration file. @@ -66,9 +59,9 @@ class Cache { */ public static function get($key, $default = null, $driver = null) { - if (isset(static::$items[$driver][$key])) + if (is_null($driver)) { - return static::$items[$driver][$key]; + $driver = Config::get('cache.driver'); } if (is_null($item = static::driver($driver)->get($key))) @@ -76,7 +69,7 @@ class Cache { return is_callable($default) ? call_user_func($default) : $default; } - return static::$items[$driver][$key] = $item; + return $item; } /** @@ -91,7 +84,7 @@ class Cache { */ public static function remember($key, $default, $minutes, $driver = null) { - if ( ! is_null($item = static::get($key))) + if ( ! is_null($item = static::get($key, null, $driver))) { return $item; } From 10deff45054e70c40ad3e8456c5fd0bace8e3938 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 1 Aug 2011 09:57:53 -0500 Subject: [PATCH 3/8] Bypass auto-loader when loading core routing classes. --- public/index.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/public/index.php b/public/index.php index 11de2ee4..214ebdd9 100644 --- a/public/index.php +++ b/public/index.php @@ -135,6 +135,16 @@ if (System\Config::get('session.driver') != '') System\Session::load(System\Cookie::get('laravel_session')); } +// -------------------------------------------------------------- +// Load all of the core routing classes. +// -------------------------------------------------------------- +require SYS_PATH.'request'.EXT; +require SYS_PATH.'response'.EXT; +require SYS_PATH.'routing/route'.EXT; +require SYS_PATH.'routing/router'.EXT; +require SYS_PATH.'routing/loader'.EXT; +require SYS_PATH.'routing/filter'.EXT; + // -------------------------------------------------------------- // Register the route filters. // -------------------------------------------------------------- @@ -150,7 +160,7 @@ $response = System\Routing\Filter::call('before', array(), true); // ---------------------------------------------------------- if (is_null($response)) { - $route = System\Routing\Router::make(Request::method(), Request::uri(), new System\Routing\Loader)->route(); + $route = System\Routing\Router::make(System\Request::method(), System\Request::uri(), new System\Routing\Loader)->route(); $response = (is_null($route)) ? System\Response::error('404') : $route->call(); } From 2efdef01d2ee175f16c1ef01ba77addba0b1c78c Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 1 Aug 2011 15:36:09 -0500 Subject: [PATCH 4/8] Add path to route loader. --- system/routing/loader.php | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/system/routing/loader.php b/system/routing/loader.php index e5de1f0b..2f093994 100644 --- a/system/routing/loader.php +++ b/system/routing/loader.php @@ -9,6 +9,24 @@ class Loader { */ private static $routes; + /** + * The path where the routes are located. + * + * @var string + */ + public $path; + + /** + * Create a new route loader instance. + * + * @param string $path + * @return void + */ + public function __construct($path) + { + $this->path = $path; + } + /** * Load the appropriate routes for the request URI. * @@ -17,9 +35,9 @@ class Loader { */ public function load($uri) { - $base = require APP_PATH.'routes'.EXT; + $base = require $this->path.'routes'.EXT; - return (is_dir(APP_PATH.'routes') and $uri != '') ? array_merge($this->load_nested_routes($uri), $base) : $base; + return (is_dir($this->path.'routes') and $uri != '') ? array_merge($this->load_nested_routes($uri), $base) : $base; } /** @@ -36,7 +54,7 @@ class Loader { // matching route file in the routes directory. foreach (array_reverse($segments, true) as $key => $value) { - if (file_exists($path = ROUTE_PATH.implode('/', array_slice($segments, 0, $key + 1)).EXT)) + if (file_exists($path = $this->path.'routes/'.implode('/', array_slice($segments, 0, $key + 1)).EXT)) { return require $path; } @@ -51,20 +69,23 @@ class Loader { * To improve performance, this operation will only be performed once. The routes * will be cached and returned on every subsequent call. * - * @param bool $reload + * @param bool $reload + * @param string $path * @return array */ - public static function everything($reload = false) + public static function everything($reload = false, $path = null) { if ( ! is_null(static::$routes) and ! $reload) return static::$routes; - $routes = require APP_PATH.'routes'.EXT; + if (is_null($path)) $path = APP_PATH; - if (is_dir(APP_PATH.'routes')) + $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(APP_PATH.'routes'); + $directoryIterator = new \RecursiveDirectoryIterator($path.'routes'); $recursiveIterator = new \RecursiveIteratorIterator($directoryIterator, \RecursiveIteratorIterator::SELF_FIRST); From bf30ca7238203f224e32b1c88037b5ec774b0f85 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 1 Aug 2011 15:36:49 -0500 Subject: [PATCH 5/8] Pass path to route loader. --- public/index.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/public/index.php b/public/index.php index 214ebdd9..053eb6fa 100644 --- a/public/index.php +++ b/public/index.php @@ -8,6 +8,8 @@ * @link http://laravel.com */ +$t = microtime(true); + // -------------------------------------------------------------- // The path to the application directory. // -------------------------------------------------------------- @@ -160,7 +162,7 @@ $response = System\Routing\Filter::call('before', array(), true); // ---------------------------------------------------------- if (is_null($response)) { - $route = System\Routing\Router::make(System\Request::method(), System\Request::uri(), new System\Routing\Loader)->route(); + $route = System\Routing\Router::make(System\Request::method(), System\Request::uri(), new System\Routing\Loader(APP_PATH))->route(); $response = (is_null($route)) ? System\Response::error('404') : $route->call(); } From ae69149262398640756cc0410cbc6d7adb309dab Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 1 Aug 2011 15:39:34 -0500 Subject: [PATCH 6/8] change Loader::everything to Loader::all. --- system/routing/loader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/routing/loader.php b/system/routing/loader.php index 2f093994..ea202924 100644 --- a/system/routing/loader.php +++ b/system/routing/loader.php @@ -73,7 +73,7 @@ class Loader { * @param string $path * @return array */ - public static function everything($reload = false, $path = null) + public static function all($reload = false, $path = null) { if ( ! is_null(static::$routes) and ! $reload) return static::$routes; From bc7df55f921dc225368ac65b7af2d7a80aa598a6 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 1 Aug 2011 15:39:58 -0500 Subject: [PATCH 7/8] Fix call to Loader::everything. --- system/url.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/url.php b/system/url.php index df1b47fd..20a3c874 100644 --- a/system/url.php +++ b/system/url.php @@ -71,7 +71,7 @@ class URL { */ public static function to_route($name, $parameters = array(), $https = false) { - if ( ! is_null($route = Routing\Finder::find($name, Routing\Loader::everything()))) + if ( ! is_null($route = Routing\Finder::find($name, Routing\Loader::all()))) { $uris = explode(', ', key($route)); From 716a957e938dda6e6c43d9c84f7f0d56b93915c1 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 1 Aug 2011 17:09:10 -0500 Subject: [PATCH 8/8] Refactoring. --- system/routing/loader.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/system/routing/loader.php b/system/routing/loader.php index ea202924..cff3a5db 100644 --- a/system/routing/loader.php +++ b/system/routing/loader.php @@ -37,7 +37,12 @@ class Loader { { $base = require $this->path.'routes'.EXT; - return (is_dir($this->path.'routes') and $uri != '') ? array_merge($this->load_nested_routes($uri), $base) : $base; + if ( ! is_dir($this->path.'routes') or $uri == '') + { + return $base; + } + + return array_merge($this->load_nested_routes($uri), $base); } /**