ThinkPHPフレームワーク実行フロー分析
全体的に、アプリケーションのプロセスはいくつかのファイルに関連しています.
Index.php
ThinkPHP.php
Think.class.php
App.class.php
Dispatcher.class.php
ThinkPHP/Mode/common.php
ReadHtmlBehavior.class.php
Route.class.php
Hook.class.php
ContentReplaceBehavior.class.php
WriteHtmlCacheBehavior.class.php
ThinkPHPフレームワーク開発のアプリケーションの標準実行フローは以下の通りである.
1.ユーザURL要求
2.アプリケーションエントリファイルを呼び出す(通常はウェブサイトのindex.php)
3.フレームエントリファイルの読み込み(ThinkPHP.php)
4.初期稼働時間とメモリオーバーヘッドの記録
Index.php
ThinkPHP.php
Think.class.php
App.class.php
Dispatcher.class.php
ThinkPHP/Mode/common.php
ReadHtmlBehavior.class.php
Route.class.php
Hook.class.php
ContentReplaceBehavior.class.php
WriteHtmlCacheBehavior.class.php
ThinkPHPフレームワーク開発のアプリケーションの標準実行フローは以下の通りである.
1.ユーザURL要求
2.アプリケーションエントリファイルを呼び出す(通常はウェブサイトのindex.php)
3.フレームエントリファイルの読み込み(ThinkPHP.php)
4.初期稼働時間とメモリオーバーヘッドの記録
- ( 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 ) ( )
Thinkphp 。
- ( 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)
13. ( Application/Common/Conf/config.php)
14.
- (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)
16.
17. ( Application/Common/Conf/tags.php)
- (tags.php)
- 'app_init'=>array('Common\Behavior\InitHookBehavior')
18. ( ThinkPHP/Lang/zh-cn.php)
19.
20. (ThinkPHP/Conf/debug.php)
21. ( Application/Common/Conf/debug.php)
22. ( APP_STATUS )
- (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)
26.
27. Think\Dispatcher::dispatch URL
- 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.php
30. URL PATH_INFO
- Dispatcher.class.php
31.
32.
33. 、 、
34.
35. URL
36. (URL_ROUTER_ON )
- Dispatcher.class.php
37. PATH_INFO (path_info)
38. URL (URL_DENY_SUFFIX URL_HTML_SUFFIX )
39. , URL
40. URL (url_dispatch)
41. (app_begin)
- 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.
44.
45. (action_begin)
- 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 )
47. _initialize
- Controller.class.php
- if(method_exists($this,'_initialize'))
- $this->_initialize();
48. ,
49. ,
50. Action ,
51. ( display )
52. (view_begin)
53. Think\View fetch
- View.class.php
54.
55. (view_parse)
- 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.
58. (template_filter)
- 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
63. (view_end)
- view.class.php
64. ,
65. (action_end)
- Controller.class.php
66. (app_end)
- App.class.php
- Hook::listen('app_end');
67. ShowPageTrace (SHOW_PAGE_TRACE AJAX )
68.