博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
12-31--Mage.php分析----Varien_Autoload::register()
阅读量:4199 次
发布时间:2019-05-26

本文共 1625 字,大约阅读时间需要 5 分钟。

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)!!!!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

转载地址:http://cgdli.baihongyu.com/

你可能感兴趣的文章
鼠标DarkField技术
查看>>
傻傻的我
查看>>
paypal 沙盒账号注册
查看>>
ebay 沙盒账号注册
查看>>
linux -8 Linux磁盘与文件系统的管理
查看>>
linux -8 Linux磁盘与文件系统的管理
查看>>
linux 9 -文件系统的压缩与打包 -dump
查看>>
PHP在变量前面加&是什么意思?
查看>>
ebay api - GetUserDisputes 函数
查看>>
ebay api GetMyMessages 函数
查看>>
wdlinux
查看>>
关于mysql升级到5.5报错问题
查看>>
magento - 通过storeid,分类id,天数(几天内)得到产品
查看>>
一个很不错的bash脚本编写教程,至少没接触过BASH的也能看懂!
查看>>
Redis和Memcache对比及选择
查看>>
用谷歌账号登陆magento、
查看>>
php oauth 模块在linux下安装
查看>>
代替nginx的服务器 - The Tengine Web Server
查看>>
nginx 升级成 tengine 的代码
查看>>
magento rest api 调用
查看>>