Thinkphp框架的源码通读2——核心Think类从开始到加载方法

来源:互联网 发布:紫青双剑仙羽进阶数据 编辑:程序博客网 时间:2024/06/09 17:51

从核心Think类Think.class.php文件中的start方法开始

设定了自动加载类文件的__autoload方法

先用此方式加载storage类——文件存储方式

Storage::connect(STORAGE_TYPE);
Storage类文件与核心Think类在同目录下

storage类的connect方法用于实例化其storage类的子类——File.class.php,由此可以Storage::方法名的方式来使用File类中的方法,参见前一篇父类调用子类方法的博文


如果debug没开且存在Application/Runtime/Common~runtim.php

就加载此文件。目前不知道此文件的来历

$runtimefile  = RUNTIME_PATH.APP_MODE.'~runtime.php'; //Application/Runtime/Common~runtim.php      if(!APP_DEBUG && Storage::has($runtimefile)){          Storage::load($runtimefile);      }else{



否则引入一系列的文件:

先引入这些文件的文件名:在./ThinkPHP/Mode/Common.php中

$mode   =   include is_file(CONF_PATH.'core.php')?CONF_PATH.'core.php':MODE_PATH.APP_MODE.'.php'; // .../ThinkPHP/Mode/Common.php
先引入函数和类文件,

Common.php的Core是这样的:

  'core'      =>  array(        THINK_PATH.'Common/functions.php',//./ThinkPHP/Common/functions.php        COMMON_PATH.'Common/function.php',//./Application/Common/function.php        CORE_PATH . 'Hook'.EXT,//./ThinkPHP/Library/Think/Hook.class.php        CORE_PATH . 'App'.EXT,//./ThinkPHP/Library/Think/App.class.php        CORE_PATH . 'Dispatcher'.EXT,//./ThinkPHP/Library/Think/Dispatcher.class.php        //CORE_PATH . 'Log'.EXT,        CORE_PATH . 'Route'.EXT,//./ThinkPHP/Library/Think/Route.class.php        CORE_PATH . 'Controller'.EXT,//./ThinkPHP/Library/Think/Controller.class.php        CORE_PATH . 'View'.EXT,//./ThinkPHP/Library/Think/View.class.php        BEHAVIOR_PATH . 'BuildLiteBehavior'.EXT,//./ThinkPHP/Library/Behavior/BuildLiteBehavior.class.php        BEHAVIOR_PATH . 'ParseTemplateBehavior'.EXT,//./ThinkPHP/Library/Behavior/ParseTemplateBehavior.class.php        BEHAVIOR_PATH . 'ContentReplaceBehavior'.EXT,//./ThinkPHP/Library/Behavior/ContentReplaceBehavior.class.php    ),
引入方法则是这样的:

foreach ($mode['core'] as $file){              if(is_file($file)) {                include $file;                if(!APP_DEBUG) $content   .= compile($file);//这里的compile方法在core[0]中,即./ThinkPHP/Common/functions.php中}}
第一个引入的是./ThinkPHP/Common/functions.php

按着顺序来的话,下一篇先看/ThinkPHP/Common/functions.php的内容。





0 0