Browse Source

cleaning up the auto-loader.

Taylor Otwell 13 years ago
parent
commit
94b4887000
1 changed files with 8 additions and 28 deletions
  1. 8 28
      laravel/autoloader.php

+ 8 - 28
laravel/autoloader.php

@@ -102,31 +102,19 @@ class Autoloader {
 	 */
 	 */
 	protected static function load_psr($class, $directory = null)
 	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);
 		$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);
 		$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))
 			if (file_exists($path = $directory.$lower.EXT))
 			{
 			{
@@ -149,9 +137,6 @@ class Autoloader {
 	{
 	{
 		foreach (static::$namespaces as $namespace => $directory)
 		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))
 			if (starts_with($class, $namespace))
 			{
 			{
 				return compact('namespace', 'directory');
 				return compact('namespace', 'directory');
@@ -162,11 +147,6 @@ class Autoloader {
 	/**
 	/**
 	 * Register an array of class to path mappings.
 	 * Register an array of class to path mappings.
 	 *
 	 *
-	 * <code>
-	 *		// Register a class mapping with the Autoloader
-	 *		Autoloader::map(array('User' => path('app').'models/user.php'));
-	 * </code>
-	 *
 	 * @param  array  $mappings
 	 * @param  array  $mappings
 	 * @return void
 	 * @return void
 	 */
 	 */