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

本文详细解析了ThinkPHP框架的启动过程,从核心Think类的start方法入手,介绍了类文件的自动加载机制,并逐步展示了框架初始化阶段加载各类关键组件的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

从核心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的内容。





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值