[TOC]
* * * * *
## 1 框架入口
### 1-1安装入口 (install.php)
~~~
if(version_compare(PHP_VERSION,'5.3.0','<')) die('require PHP > 5.3.0 !');
~~~
> 检查php版本信息
~~~
define ( 'APP_DEBUG', true );
~~~
> 开始调试模式
`define ( 'BIND_MODULE','Install');`
>[info] 设置绑定模块为Install,路由解析是模块解析到安装模块
`define ( 'APP_PATH', './Application/' );`
> 应用目录
`define ( 'RUNTIME_PATH', './Runtime/' );`
> 缓存目录
`require './ThinkPHP/ThinkPHP.php';`
> 加载框架引导文件,启动框架
### 默认入口 (index.php)
~~~
if(version_compare(PHP_VERSION,'5.3.0','<')) die('require PHP > 5.3.0 !');
define('APP_DEBUG', true );
define ( 'APP_PATH', './Application/' );
~~~
> 同上。
> 检查php版本,
> 开启调试模式,
> 设置应用目录
~~~
if(!is_file(APP_PATH . 'User/Conf/config.php')){
header('Location: ./install.php');
exit;
}
~~~
>[info] 检查是否需要安装,
~~~
define ( 'RUNTIME_PATH', './Runtime/' );
require './ThinkPHP/ThinkPHP.php';
~~~
> 同上。
> 设置缓存目录,
> 加载框架引导文件,启动框架
### 后台入口 (admin.php)
~~~
if(version_compare(PHP_VERSION,'5.3.0','<')) die('require PHP > 5.3.0 !');
define('APP_DEBUG', true );
~~~
> 同上
检查php版本
开启调试模式
`define('BIND_MODULE','Admin');`
>[info] 设置绑定模块为Admin,路由解析到后台模块
`define ( 'APP_PATH', './Application/' );`
> 设置应用目录
~~~
if(!is_file(APP_PATH . 'User/Conf/config.php')){
header('Location: ./install.php');
exit;
}
~~~
>[info] 检查是否需要安装,跳转到安装入口
~~~
define ( 'RUNTIME_PATH', './Runtime/' );
~~~
> 设置缓存目录
~~~
require './ThinkPHP/ThinkPHP.php';
~~~
> 加载框架引导文件,启动框架
## 2 框架流程
### 1 框架引导(ThinkPHP.php)
~~~
$GLOBALS['_beginTime'] = microtime(TRUE);
define('MEMORY_LIMIT_ON',function_exists('memory_get_usage'));
if(MEMORY_LIMIT_ON) $GLOBALS['_startUseMems'] = memory_get_usage();
~~~
> 记录统计信息
~~~
const THINK_VERSION = '3.2.3';
~~~
> 框架版本常量
~~~
const URL_COMMON = 0; //普通模式
const URL_PATHINFO = 1; //PATHINFO模式
const URL_REWRITE = 2; //REWRITE模式
const URL_COMPAT = 3; // 兼容模式
~~~
> Url模式常量
~~~
const EXT = '.class.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);
if(function_exists('saeAutoLoader')){
defined('APP_MODE') or define('APP_MODE', 'sae');
defined('STORAGE_TYPE') or define('STORAGE_TYPE', 'Sae');
}else{
defined('APP_MODE') or define('APP_MODE', 'common');
defined('STORAGE_TYPE') or define('STORAGE_TYPE', 'File');
}
defined('RUNTIME_PATH') or define('RUNTIME_PATH', APP_PATH.'Runtime/');
defined('LIB_PATH') or define('LIB_PATH', realpath(THINK_PATH.'Library').'/');
defined('CORE_PATH') or define('CORE_PATH', LIB_PATH.'Think/');
defined('BEHAVIOR_PATH')or define('BEHAVIOR_PATH', LIB_PATH.'Behavior/');
defined('MODE_PATH') or define('MODE_PATH', THINK_PATH.'Mode/');
defined('VENDOR_PATH') or define('VENDOR_PATH', LIB_PATH.'Vendor/');
defined('COMMON_PATH') or define('COMMON_PATH', APP_PATH.'Common/');
defined('CONF_PATH') or define('CONF_PATH', COMMON_PATH.'Conf/');
defined('LANG_PATH') or define('LANG_PATH', COMMON_PATH.'Lang/');
defined('HTML_PATH') or define('HTML_PATH', APP_PATH.'Html/');
defined('LOG_PATH') or define('LOG_PATH', RUNTIME_PATH.'Logs/');
defined('TEMP_PATH') or define('TEMP_PATH', RUNTIME_PATH.'Temp/');
defined('DATA_PATH') or define('DATA_PATH', RUNTIME_PATH.'Data/');
defined('CACHE_PATH') or define('CACHE_PATH', RUNTIME_PATH.'Cache/');
defined('CONF_EXT') or define('CONF_EXT', '.php');
defined('CONF_PARSE') or define('CONF_PARSE', '');
defined('ADDON_PATH') or define('ADDON_PATH', APP_PATH.'Addon');
if(version_compare(PHP_VERSION,'5.4.0','<')) {
ini_set('magic_quotes_runtime',0);
define('MAGIC_QUOTES_GPC',get_magic_quotes_gpc()?True:False);
}else{
define('MAGIC_QUOTES_GPC',false);
}
define('IS_CGI',(0 === strpos(PHP_SAPI,'cgi') || false !== strpos(PHP_SAPI,'fcgi')) ? 1 : 0 );
define('IS_WIN',strstr(PHP_OS, 'WIN') ? 1 : 0 );
define('IS_CLI',PHP_SAPI=='cli'? 1 : 0);
if(!IS_CLI) {
if(!defined('_PHP_FILE_')) {
if(IS_CGI) {
$_temp = explode('.php',$_SERVER['PHP_SELF']);
define('_PHP_FILE_', rtrim(str_replace($_SERVER['HTTP_HOST'],'',$_temp[0].'.php'),'/'));
}else {
define('_PHP_FILE_', rtrim($_SERVER['SCRIPT_NAME'],'/'));
}
}
if(!defined('__ROOT__')) {
$_root = rtrim(dirname(_PHP_FILE_),'/');
define('__ROOT__', (($_root=='/' || $_root=='\\')?'':$_root));
}
}
~~~
>[info] 框架常量定义
~~~
require CORE_PATH.'Think'.EXT;
Think\Think::start();
~~~
>[info] 加载框架核心,并启动。
### 2 框架初始化(Think\Think::start())
### 3 应用调度(Think\App::run())