spl标准库自动加载文件和类

<?php
define('MPATH','mpath');
define('CPATH','cpath');
define('VPATH','vpath');
define('LPATH','lpath');
class Loader{
	protected $_controllerDirectoryPath=array();
	protected $_modelDirectoryPath=array();
	protected $_libraryDirectoryPath=array();
	
	public function __construct(){
		$this->modelDirectoryPath=MPATH;
		$this->viewDirectoryPath=VPATH;
		$this->controllerDirectoryPath=CPATH;
		$this->libraryDirectoryPath=LPATH;
		spl_autoload_register(array($this,'load_controller'));
		spl_autoload_register(array($this,'load_models'));
		spl_autoload_register(array($this,'load_library'));
		spl_autoload_register(array($this,'load_librarys'));
	}
	function load_library($library,$param=null){
		if(is_string($library)){
			return $this->initialize_class($library);
		}
		if(is_array($library)){
			foreach($library as $key){
				return $this->initialize_class($library);
			}
		}
	}
	public function initialize_class($library){
		try{
			if(is_array($library)){
				foreach($library as $class){
					$arrayObject=new $class;
				}
				return $this;
			}
			if(is_string($library)){
				$stringObject=new $library;
			}else{
				throw new ISException('Class name must be string.');
			}
			if(null==$library){
				throw new ISException('you must enter the name of the class');
			}
		}catch(Exception $e){
			echo $e;
		}
	}
	function load_controller($controller){
		if($controller){
			set_include_path($this->controllerDirectoryPath);
			spl_autoload_extensions('.php');
			spl_autoload($controller);
		}
	}
	function load_models($model){
		if($model){
			set_include_path($this->modelDirectoryPath);
			spl_autoload_extensions('.php');
			spl_autoload($model);
		}
	}
	function load_librarys($library){
		if($library){
			set_include_path($this->libraryDirectoryPath);
			spl_autoload_extensions('.php');
			spl_autoload($library);
		}
	}
}
$loader=new Loader();
$loader->load_controller('extender');
$base=new Extender();
$b=serialize($base);
echo $b;

?>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值