From 94b4887000e9eb0a9fc72c935072046044f4afab Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 6 Feb 2012 12:58:51 -0600 Subject: [PATCH] cleaning up the auto-loader. --- laravel/autoloader.php | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/laravel/autoloader.php b/laravel/autoloader.php index 5c05b551..c1bd0ad3 100644 --- a/laravel/autoloader.php +++ b/laravel/autoloader.php @@ -102,31 +102,19 @@ class_alias(static::$aliases[$class], $class); */ protected static function load_psr($class, $directory = null) { - // The PSR-0 standard indicates that class namespace slashes or - // underscores should be used to indicate the directory tree in - // which the class resides, so we'll convert the namespace - // slashes to directory slashes. + // The PSR-0 standard indicates that class namespaces and underscores + // shoould be used to indcate the directory tree in which the class + // resides, so we'll convert them to directory slashes. $file = str_replace(array('\\', '_'), '/', $class); - if (is_null($directory)) - { - $directories = static::$psr; - } - else - { - $directories = array($directory); - } + $directories = $directory ?: static::$psr; - // Once we have formatted the class name, we will simply spin - // through the registered PSR-0 directories and attempt to - // locate and load the class into the script. - // - // We will check for both lowercase and CamelCase files as - // Laravel uses a lowercase version of PSR-0, while true - // PSR-0 uses CamelCase for all file names. $lower = strtolower($file); - foreach ($directories as $directory) + // Once we have formatted the class name, we'll simply spin through + // the registered PSR-0 directories and attempt to locate and load + // the class file into the script. + foreach ((array) $directories as $directory) { if (file_exists($path = $directory.$lower.EXT)) { @@ -149,9 +137,6 @@ protected static function namespaced($class) { foreach (static::$namespaces as $namespace => $directory) { - // If the class begins with one of the registered namespaces, - // we'll return both the namespace and the directory, which - // will allow us to use PSR-0 to load the class. if (starts_with($class, $namespace)) { return compact('namespace', 'directory'); @@ -162,11 +147,6 @@ protected static function namespaced($class) /** * Register an array of class to path mappings. * - * - * // Register a class mapping with the Autoloader - * Autoloader::map(array('User' => path('app').'models/user.php')); - * - * * @param array $mappings * @return void */