Location: PHPKode > projects > Thought Push PHP Framework > system/utilities/system/Autoloader.php
<?
///Simple autoloader based on folder list.  Add memcached for heavy load sites.
class Autoloader{
	///folders to be checked recursively for class file
	/**@attention feel free to modify this variable to alter autoloader functionality on the fly*/
	static $resourceFolders;
	
	///load a class based on current autoloader resourceFolders
	/**
	@param	className	name of the class and the name of the file without the ".php" extension
	*/
	static function load($className){
		$location = self::findClass($className,self::$resourceFolders);
		if($location){
			require $location;
		}else{
			$error = 'Attempt to autoload class "'.$className.'" has failed';
			Debug::throwError($error,null,E_USER_ERROR);
		}
	}
	///finds a class looking in folders recursively
	/**
	@param	name	name of the class
	@param	folders	array of folders to check in
	*/
	static function findClass($name,$folders){
		foreach($folders as $folder){
			$location = self::findClassInFolder($name,$folder);
			if($location){
				return $location;
			}
		}
	}
	///recursively checks a folder for a class
	/**
	@param	name	class name
	@param	folder	folder path
	*/
	static function findClassInFolder($name,$folder){
		if(is_file($folder.$name.'.php')){
			return $folder.$name.'.php';
		}
		foreach(scandir($folder) as $entry){
			if($entry != '.' && $entry != '..'){
				$newFolder = $folder.$entry;
				if(is_dir($newFolder)){
					$location = self::findClassInFolder($name,$newFolder.'/');
					if($location){
						return $location;
					}
				}
			}
		}
	}
}
Autoloader::$resourceFolders = Config::$x['autoloadIncludes'];
Return current item: Thought Push PHP Framework