From bc1a7d07716bcef3c4c4781e608c3ce98c844861 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 6 Feb 2012 11:40:18 -0600 Subject: [PATCH] improving namespace autoloading support. --- laravel/autoloader.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/laravel/autoloader.php b/laravel/autoloader.php index 036585df..61826de7 100644 --- a/laravel/autoloader.php +++ b/laravel/autoloader.php @@ -64,10 +64,8 @@ class_alias(static::$aliases[$class], $class); // using the PSR-0 standards from that directory; however, we will trim // off the beginning of the namespace to account for files in the root // of the mapped directory. - if (isset(static::$namespaces[$namespace])) + if ( ! is_null($directory = static::directory($class))) { - $directory = static::$namespaces[$namespace]; - return static::load_psr(substr($class, $slash + 1), $directory); } @@ -93,6 +91,23 @@ class_alias(static::$aliases[$class], $class); static::load_psr($class); } + /** + * Get the directory associated with a given namespaced class. + * + * @param string $class + * @return string + */ + protected static function directory($class) + { + foreach (static::$namespaces as $namespace => $directory) + { + if (starts_with($class, $namespace)) + { + return $directory; + } + } + } + /** * Attempt to resolve a class using the PSR-0 standard. *