(引用自ThinkPHP.php)
// 记录开始运行时间
$GLOBALS['_beginTime'] = microtime(TRUE);
// 记录内存初始使用
define('MEMORY_LIMIT_ON',function_exists('memory_get_usage'));
if(MEMORY_LIMIT_ON) $GLOBALS['_startUseMems'] = memory_get_usage();5. 系统常量判断及定义(引用自ThinkPHP.php)
// 系统常量定义
defined('THINK_PATH') or define('THINK_PATH', __DIR__.'/');
defined('APP_PATH') or define('APP_PATH', dirname($_SERVER['SCRIPT_FILENAME']).'/');
defined('APP_STATUS') or define('APP_STATUS', ''); // 应用状态 加载对应的配置文件
defined('APP_DEBUG') or define('APP_DEBUG', false); // 是否调试模式6. 载入框架引导类(Think\Think)并执行Think::start方法进行应用初始化(引用自ThinkPHP.php)
// 应用初始化
Think\Think::start();7. 设置错误处理机制和自动加载机制(引用Think.class.php)
// 注册AUTOLOAD方法
spl_autoload_register('Think\Think::autoload');
// 设定错误和异常处理
register_shutdown_function('Think\Think::fatalError');
set_error_handler('Think\Think::appError');
set_exception_handler('Think\Think::appException');8. 调用Think\Storage类进行存储初始化(由STORAGE_TYPE常量定义存储类型)(引用Think.class.php)
// 初始化文件存储方式
Storage::connect(STORAGE_TYPE);9. 部署模式下如果存在应用编译缓存文件则直接加载(直接跳转到步骤22)(引用Think.class.php)
if(!APP_DEBUG && Storage::has($runtimefile)){
Storage::load($runtimefile);
}10. 读取应用模式(由APP_MODE常量定义)的定义文件(以下以普通模式为例说明)(引用Think.class.php)
// 读取应用模式
$mode = include is_file(CONF_PATH.'core.php')?CONF_PATH.'core.php':MODE_PATH.APP_MODE.'.php';11. 加载当前应用模式定义的核心文件(普通模式是 ThinkPHP/Mode/common.php)(common.php)
THINK_PATH.'Conf/convention.php', // 系统惯例配置
CONF_PATH.'config'.CONF_EXT, // 应用公共配置12. 加载惯例配置文件(普通模式是 ThinkPHP/Conf/convention.php)(common.php)
// 别名定义
'alias' => array(
'Think\Log' => CORE_PATH . 'Log'.EXT,
'Think\Log\Driver\File' => CORE_PATH . 'Log/Driver/File'.EXT,
'Think\Exception' => CORE_PATH . 'Exception'.EXT,
'Think\Model' => CORE_PATH . 'Model'.EXT,
'Think\Db' => CORE_PATH . 'Db'.EXT,
'Think\Template' => CORE_PATH . 'Template'.EXT,
'Think\Cache' => CORE_PATH . 'Cache'.EXT,
'Think\Cache\Driver\File' => CORE_PATH . 'Cache/Driver/File'.EXT,
'Think\Storage' => CORE_PATH . 'Storage'.EXT,
),15. 判断并读取应用别名定义文件(普通模式是 Application/Common/Conf/alias.php)(tags.php)
'app_init'=>array('Common\Behavior\InitHookBehavior')18. 加载框架底层语言包(普通模式是 ThinkPHP/Lang/zh-cn.php)(think.class.php)
// 读取当前应用状态对应的配置文件
if(APP_STATUS && is_file(CONF_PATH.APP_STATUS.CONF_EXT))
C(include CONF_PATH.APP_STATUS.CONF_EXT); 23. 检测应用目录结构并自动生成(如果CHECK_APP_DIR配置开启并且RUNTIME_PATH目录不存在的情况下)think.class.php
// 检查应用目录结构 如果不存在则自动创建
if(C('CHECK_APP_DIR')) {
$module = defined('BIND_MODULE') ? BIND_MODULE : C('DEFAULT_MODULE');
if(!is_dir(APP_PATH.$module) || !is_dir(LOG_PATH)){
// 检测应用目录结构
Build::checkDir($module);
}
}24. 调用Think\App类的run方法启动应用think.class.php
// 运行应用
App::run();25. 应用初始化(app_init)标签位侦听并执行绑定行为App.class.php
Dispatcher::dispatch();28. 自动识别兼容URL模式和命令行模式下面的$_SERVER['PATH_INFO']参数Dispatcher.class.php
$_SERVER['PATH_INFO'] = $_GET[$varPath];29. 检测域名部署以及完成模块和控制器的绑定操作(APP_SUB_DOMAIN_DEPLOY参数开启)Dispatcher.class.php30. 分析URL地址中的PATH_INFO信息Dispatcher.class.php31. 获取请求的模块信息Dispatcher.class.php37. PATH_INFO处理(path_info)标签位侦听并执行绑定行为App.class.php
static public function run() {
// 应用初始化标签
Hook::listen('app_init');
App::init();
// 应用开始标签
Hook::listen('app_begin');42. 调用SESSION_OPTIONS配置参数进行Session初始化(如果不是命令行模式)// Session初始化
if(!IS_CLI){
session(C('SESSION_OPTIONS'));
}43. 根据请求执行控制器方法Controller.class.php
public function __construct() {
Hook::listen('action_begin',$this->config);
//实例化视图类
$this->view = Think::instance('Think\View');
//控制器初始化
if(method_exists($this,'_initialize'))
$this->_initialize();
}46. 默认调用系统的ReadHtmlCache行为读取静态缓存(HTML_CACHE_ON参数开启)Controller.class.php
if(method_exists($this,'_initialize'))
$this->_initialize();48. 判断操作方法是否存在,如果不存在则检测是否定义空操作方法View.class.php54. 自动识别当前主题以及定位模版文件View.class.php
Hook::listen('view_parse',$params);
common.php
'view_parse' => array(
'Behavior\ParseTemplateBehavior', // 模板解析 支持PHP、内置模板引擎和第三方模板引擎
),56. 默认调用内置ParseTemplate行为解析模版(普通模式下面)View.class.php
public function parseTemplate($template='') 57. 模版引擎解析模版内容后生成模版缓存Template.class.php
Hook::listen('template_filter',$tmplContent);59. 默认调用系统的ContentReplace行为进行模版替换'template_filter'=> array(
'Behavior\ContentReplaceBehavior', // 模板输出替换
),
ContentReplaceBehavior.class.php
class ContentReplaceBehavior {60. 输出内容过滤(view_filter)标签位侦听并执行绑定行为'view_filter' => array(
'Behavior\WriteHtmlCacheBehavior', // 写入静态缓存
),61. 默认调用系统的WriteHtmlCache行为写入静态缓存(HTML_CACHE_ON参数开启)WriteHtmlCacheBehavior.class.php
class WriteHtmlCacheBehavior {62. 调用Think\View类的render方法输出渲染内容view.class.php64. 判断后置操作方法是否定义,有的话执行Controller.class.php66. 应用结束(app_end)标签位侦听并执行绑定行为App.class.php
Hook::listen('app_end');67. 执行系统的ShowPageTrace行为(SHOW_PAGE_TRACE参数开启并且不是AJAX请求)ThinkPHP 是一个免费开源的,快速、简单的面向对象的 轻量级PHP开发框架 ,创立于2006年初,遵循Apache2开源协议发布,是为了敏捷WEB应用开发和简化企业应用开发而诞生的。ThinkPHP从诞生以来一直秉承简洁实用的设计原则,在保持出色的性能和至简的代码的同时,也注重易用性。并且拥有众多的原创功能和特性,在社区团队的积极参与下,在易用性、扩展性和性能方面不断优化和改进,已经成长为国内最领先和最具影响力的WEB应用开发框架,众多的典型案例确保可以稳定用于商业以及门户级的开发。