123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- class PropelAutoloader
- {
- static protected $instance = null;
- protected $classes = array();
-
- static public function getInstance()
- {
- if (!isset(self::$instance)) {
- self::$instance = new PropelAutoloader();
- }
- return self::$instance;
- }
-
- static public function register()
- {
- ini_set('unserialize_callback_func', 'spl_autoload_call');
- if (false === spl_autoload_register(array(self::getInstance(), 'autoload'))) {
- throw new Exception(sprintf('Unable to register %s::autoload as an autoloading method.', get_class(self::getInstance())));
- }
- }
-
- static public function unregister()
- {
- spl_autoload_unregister(array(self::getInstance(), 'autoload'));
- }
-
- public function addClassPaths($classMap)
- {
- $this->classes = array_merge($this->classes, $classMap);
- }
-
-
- public function addClassPath($class, $path)
- {
- $this->classes[$class] = $path;
- }
-
- public function getClassPath($class)
- {
- return isset($this->classes[$class]) ? $this->classes[$class] : null;
- }
-
- public function autoload($class)
- {
- if (isset($this->classes[$class])) {
- require $this->classes[$class];
- return true;
- }
- return false;
- }
- }
|