From 83d927c4f19f266f9afdf632c6afda4b507b75e2 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 1 Nov 2011 19:41:35 -0500 Subject: [PATCH] refactoring. --- application/config/application.php | 2 +- application/filters.php | 2 +- laravel/autoloader.php | 30 +++++++++++++++++------------- laravel/bootstrap/constants.php | 13 +++++++++++-- laravel/bootstrap/core.php | 2 -- laravel/facades.php | 3 +-- laravel/input.php | 10 ++++++++++ laravel/paginator.php | 10 +++++----- laravel/redis.php | 2 ++ laravel/routing/router.php | 3 +-- laravel/security/crypter.php | 15 +++------------ 11 files changed, 52 insertions(+), 40 deletions(-) diff --git a/application/config/application.php b/application/config/application.php index 175b1904..8ce59fa9 100644 --- a/application/config/application.php +++ b/application/config/application.php @@ -83,7 +83,7 @@ | */ - 'packages' => array(), + 'libraries' => array(), /* |-------------------------------------------------------------------------- diff --git a/application/filters.php b/application/filters.php index 4cfe959d..c77ead9c 100644 --- a/application/filters.php +++ b/application/filters.php @@ -52,7 +52,7 @@ { if (Config::get('session.driver') !== '') { - Session::flash(Input::old_input, Input::get()); + Input::flash(); } }, diff --git a/laravel/autoloader.php b/laravel/autoloader.php index 06604828..1ee5abec 100644 --- a/laravel/autoloader.php +++ b/laravel/autoloader.php @@ -19,14 +19,20 @@ class Autoloader { /** * Load the file corresponding to a given class. * + * Laravel loads classes out of three directorys: the core "laravel" directory, + * and the application "models" and "libraires" directories. All of the file + * names are lower cased and the directory structure corresponds with the + * class namespaces. + * + * The application "libraries" directory also supports the inclusion of PSR-0 + * compliant libraries. These libraries will be detected automatically and + * will be loaded according to the PSR-0 naming conventions. + * * @param string $class * @return void */ public static function load($class) { - // Most of the core classes are aliases for convenient access in spite of - // the namespace. If an alias is defined for the class, we will load the - // alias and bail out of the auto-load method. if (array_key_exists($class, Config::$items['application']['aliases'])) { return class_alias(Config::$items['application']['aliases'][$class], $class); @@ -39,7 +45,7 @@ public static function load($class) } /** - * Find the file associated with a given class name. + * Determine the file path associated with a given class name. * * @param string $class * @return string @@ -50,13 +56,11 @@ protected static function find($class) $namespace = substr($class, 0, strpos($class, '\\')); - // If the class namespace exists in the libraries array, it means that the - // library is PSR-0 compliant, and we will load it following those standards. - // This allows us to add many third-party libraries to an application and be - // able to auto-load them automatically. + // If the namespace has been detected as a PSR-0 compliant library, + // we will load the library according to those naming conventions. if (array_key_exists($namespace, static::$libraries)) { - return LIBRARY_PATH.str_replace('_', '/', $file); + return str_replace('_', '/', $file).EXT; } foreach (static::$paths as $path) @@ -67,10 +71,10 @@ protected static function find($class) } } - // If the file exists as-is in the libraries directory, we will assume the - // library is PSR-0 compliant, and will add the namespace to the array of - // libraries and load the class accordingly. - if (file_exists($path = LIBRARY_PATH.str_replace('_', '/', $file))) + // If the file exists according to the PSR-0 naming conventions, + // we will add the namespace to the array of libraries and load + // the class according to the PSR-0 conventions. + if (file_exists($path = str_replace('_', '/', $file).EXT)) { static::$libraries[] = $namespace; diff --git a/laravel/bootstrap/constants.php b/laravel/bootstrap/constants.php index 19b822a9..9a6f99e3 100644 --- a/laravel/bootstrap/constants.php +++ b/laravel/bootstrap/constants.php @@ -1,8 +1,7 @@ realpath($application).'/', 'BASE_PATH' => realpath("$laravel/..").'/', @@ -42,6 +46,11 @@ function constants($constants) constants($constants); +/** + * Register the core framework paths and all of the paths that + * derive from them. If any constant has already been defined, + * we will not attempt to define it again. + */ $environment = (isset($_SERVER['LARAVEL_ENV'])) ? CONFIG_PATH.$_SERVER['LARAVEL_ENV'].'/' : ''; constants(array('ENV_CONFIG_PATH' => $environment)); diff --git a/laravel/bootstrap/core.php b/laravel/bootstrap/core.php index 4a41ab66..ab43bc94 100644 --- a/laravel/bootstrap/core.php +++ b/laravel/bootstrap/core.php @@ -14,8 +14,6 @@ IoC::bootstrap(); -$loader = new Autoloader; - spl_autoload_register(array('Laravel\\Autoloader', 'load')); function e($value) diff --git a/laravel/facades.php b/laravel/facades.php index 7d761db9..4f7d2cbb 100644 --- a/laravel/facades.php +++ b/laravel/facades.php @@ -59,5 +59,4 @@ public static function __callStatic($method, $parameters) } -class Autoloader extends Facade { public static $resolve = 'laravel.autoloader'; } -class Session extends Facade { public static $resolve = 'laravel.session'; } \ No newline at end of file +class Session extends Facade { public static $resolve = 'laravel.session'; } \ No newline at end of file diff --git a/laravel/input.php b/laravel/input.php index 435eb89a..f27e5b7f 100644 --- a/laravel/input.php +++ b/laravel/input.php @@ -74,6 +74,16 @@ public static function had($key) return ( ! is_null(static::old($key)) and trim((string) static::old($key)) !== ''); } + /** + * Flash the input for the current request to the session. + * + * @return void + */ + public static function flash() + { + IoC::container()->core('session')->flash(Input::old_input, static::get()); + } + /** * Get input data from the previous request. * diff --git a/laravel/paginator.php b/laravel/paginator.php index 4de36915..9c039498 100644 --- a/laravel/paginator.php +++ b/laravel/paginator.php @@ -145,7 +145,7 @@ public function links() * @param string $text * @return string */ - protected function status($text) + public function status($text) { return str_replace(array(':current', ':last'), array($this->page, $this->last), $text); } @@ -156,7 +156,7 @@ protected function status($text) * @param string $text * @return string */ - protected function first($text) + public function first($text) { return $this->backwards(__FUNCTION__, $text, 1); } @@ -167,7 +167,7 @@ protected function first($text) * @param string $text * @return string */ - protected function previous($text) + public function previous($text) { return $this->backwards(__FUNCTION__, $text, $this->page - 1); } @@ -178,7 +178,7 @@ protected function previous($text) * @param string $text * @return string */ - protected function next($text) + public function next($text) { return $this->forwards(__FUNCTION__, $text, $this->page + 1); } @@ -189,7 +189,7 @@ protected function next($text) * @param string $text * @return string */ - protected function last($text) + public function last($text) { return $this->forwards(__FUNCTION__, $text, $this->last); } diff --git a/laravel/redis.php b/laravel/redis.php index c71047e6..6108a7bb 100644 --- a/laravel/redis.php +++ b/laravel/redis.php @@ -1,5 +1,7 @@