1Varien_Autoload::register();

 

2

class Varien_Autoload

 

   static public function register()

    {

        spl_autoload_register(array(self::instance(), 'autoload'));

    }

 

3

 static public function instance()

    {

        if (!self::$_instance) {

            self::$_instance = new Varien_Autoload();

        }

        return self::$_instance;

    }

 

 

4

public function __construct()

    {

        $this->_isIncludePathDefined = defined('COMPILER_INCLUDE_PATH');

        if (defined('COMPILER_COLLECT_PATH')) {

            $this->_collectClasses  = true;

            $this->_collectPath     = COMPILER_COLLECT_PATH;

        }

        self::registerScope(self::$_scope);

    }

 

5

 

self::registerScope(self::$_scope);

    }

 static protected $_scope = 'default';

 

6

  /**

     * Register autoload scope

     * This process allow include scope file which can contain classes

     * definition which are used for this scope

     *

     * @param string $code scope code

     */

    static public function registerScope($code)

    {

        self::$_scope = $code;

        if (defined('COMPILER_INCLUDE_PATH')) {

            @include_once self::SCOPE_FILE_PREFIX.$code.'.php';

        }

    }

 

 

3,4,5,6一些值的赋值,This process allow include scope file which can contain classes

 

回到2

 spl_autoload_register(array(self::instance(), 'autoload'));

self::instance()是Varien_Autoload的实例!

 

7。

 public function autoload($class)

    {

        if ($this->_collectClasses) {

            $this->_arrLoadedClasses[self::$_scope][] = $class;

        }

        if ($this->_isIncludePathDefined) {

            $classFile = $class;

        } else {

            $classFile = str_replace(' ', DIRECTORY_SEPARATOR, ucwords(str_replace('_', ' ', $class)));

        }

        $classFile.= '.php';

        //echo $classFile;die();

        return include $classFile;

    }

 

 

 

本质就是,对一些对象变量赋值,有条件的对scope文件加载,然后将__autoload函数覆盖,使用spl_autoload_register函数,

spl_autoload_register(Varien_Autoload,autoload)!!!!