00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00019 class PEIP_Simple_Autoload {
00020
00021 protected
00022 $baseDir = null,
00023 $classPaths = array();
00024
00025 static protected
00026 $instance;
00027
00033 protected function __construct(){
00034 $this->init();
00035 }
00036
00043 protected function init(){
00044 $this->baseDir = realpath(dirname(__FILE__).'/..');
00045 ini_set('unserialize_callback_func', 'spl_autoload_call');
00046 if (false === spl_autoload_register(array($this, 'autoload'))){
00047 throw new RuntimeException(sprintf('Unable to register %s::autoload as an autoloading method.', get_class($this)));
00048 }
00049 }
00050
00058 static public function getInstance(){
00059 if (!isset(self::$instance)){
00060 static::doGetInstance();
00061 }
00062 return self::$instance;
00063 }
00064
00072 protected static function doGetInstance(){
00073 return self::$instance = new PEIP_Simple_Autoload();;
00074 }
00075
00084 public function setClassPath($class, $path){
00085 $this->classPaths[$class] = $path;
00086 }
00087
00095 public function setClassPaths(array $classPaths){
00096 $this->classPaths = $classPaths;
00097 }
00098
00106 public function getClassPath($class){
00107 if (!isset($this->classPaths[$class])){
00108 return null;
00109 }
00110 return $this->baseDir.'/'.$this->classPaths[$class];
00111 }
00112
00120 public function autoload($class){
00121 if ($path = $this->getClassPath($class)){
00122 require $path;
00123 if(class_exists($class)){
00124 return true;
00125 }
00126 }
00127 return false;
00128 }
00129 }
00130
00131