<?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;
?>
spl标准库自动加载文件和类
最新推荐文章于 2023-10-25 17:22:41 发布