Location: PHPKode > projects > Blackwolf CMF > projectBlackWolf/lib/System/Autoloader.class.php
<?php
/* Please see the README and LICENSE files. */

/**
 * Takes care of all of the including of classes, automagically.
 */
class System_Autoloader implements System_Component {    
    /**
     * @see Core_Component
     */
    public function start() {
        return spl_autoload_register(array(__CLASS__, 'load_class'));
    }
    /**
     * @see Core_Component
     */
    public function stop() {
        return spl_autoload_unregister(array(__CLASS__,'load_class'));
    }
    
    /**
     * Loads file for requests class
     * 
     * @param String $class_name The name of the class to load
     * @return bool True if class loads, false otherwise
     */
    public static function load_class($class_name){
        if(self::is_loaded($class_name)){ return true;}
        $failed = false;
        $class_name_r = str_replace("_","/",$class_name);
	$class_name_r = str_replace("..","",$class_name_r);
	if(file_exists(LIB_DIR."/".$class_name_r.".class.php")){
		require_once(LIB_DIR."/".$class_name_r.".class.php");                
	} else {
		trigger_error("Autoloader: Unable to load file ".$class_name_r.".class.php",E_USER_WARNING);
                return false;
	}
	return self::is_loaded($class_name) ?
                true :
                trigger_error("Autoloader: Unable to load class $class_name",
                    E_USER_ERROR);
    }
    
    /**
     * Checks if a class or interface was loaded or not
     * @param String $class_name
     * @return Boolean True if the class/interface was loaded
     */
    protected static function is_loaded($class_name){
        return class_exists($class_name) || interface_exists($class_name);
    }
}

?>
Return current item: Blackwolf CMF