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.初期稼働時間とメモリオーバーヘッドの記録
  1. ( ThinkPHP.php)
  2. // 
  3. $GLOBALS['_beginTime'] = microtime(TRUE);
  4. // 
  5. define('MEMORY_LIMIT_ON',function_exists('memory_get_usage'));
  6. if(MEMORY_LIMIT_ON) $GLOBALS['_startUseMems'] = memory_get_usage();
5.
  1. ( ThinkPHP.php)
  2. // 
  3. defined('THINK_PATH')   or define('THINK_PATH',     __DIR__.'/');
  4. defined('APP_PATH')     or define('APP_PATH',       dirname($_SERVER['SCRIPT_FILENAME']).'/');
  5. defined('APP_STATUS')   or define('APP_STATUS',     ''); //   
  6. defined('APP_DEBUG')    or define('APP_DEBUG',      false); // 
6. (Think\Think) Think::start
  1. ( ThinkPHP.php)
  2. //   
  3. Think\Think::start();
7.
  1. ( Think.class.php)
  2. //  AUTOLOAD
  3.       spl_autoload_register('Think\Think::autoload');      
  4.       // 
  5.       register_shutdown_function('Think\Think::fatalError');
  6.       set_error_handler('Think\Think::appError');
  7.       set_exception_handler('Think\Think::appException');
8. Think\Storage ( STORAGE_TYPE )
  1. ( Think.class.php)
  2. // 
  3.    Storage::connect(STORAGE_TYPE);
9. ( 22)
  1. ( Think.class.php)
  2. if(!APP_DEBUG && Storage::has($runtimefile)){
  3.           Storage::load($runtimefile);
  4.       }
10. ( APP_MODE ) ( )
Thinkphp 。
  1. ( Think.class.php)
  2. // 
  3.           $mode   =   include is_file(CONF_PATH.'core.php')?CONF_PATH.'core.php':MODE_PATH.APP_MODE.'.php';
11. ( ThinkPHP/Mode/common.php)
  1. (common.php)
  2. THINK_PATH.'Conf/convention.php',   // 
  3. CONF_PATH.'config'.CONF_EXT,      // 
12. ( ThinkPHP/Conf/convention.php)

13. ( Application/Common/Conf/config.php) 

14.
  1. (common.php)
  2. // 
  3.     'alias'     =>  array(
  4.         'Think\Log'               => CORE_PATH . 'Log'.EXT,
  5.         'Think\Log\Driver\File'   => CORE_PATH . 'Log/Driver/File'.EXT,
  6.         'Think\Exception'         => CORE_PATH . 'Exception'.EXT,
  7.         'Think\Model'             => CORE_PATH . 'Model'.EXT,
  8.         'Think\Db'                => CORE_PATH . 'Db'.EXT,
  9.         'Think\Template'          => CORE_PATH . 'Template'.EXT,
  10.         'Think\Cache'             => CORE_PATH . 'Cache'.EXT,
  11.         'Think\Cache\Driver\File' => CORE_PATH . 'Cache/Driver/File'.EXT,
  12.         'Think\Storage'           => CORE_PATH . 'Storage'.EXT,
  13.     ),
15. ( Application/Common/Conf/alias.php)
16.
17. ( Application/Common/Conf/tags.php)
  1. (tags.php)
  2. '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 )
  1. think.class.php
  2. // 
  3.    if(APP_STATUS && is_file(CONF_PATH.APP_STATUS.CONF_EXT))
  4.    C(include CONF_PATH.APP_STATUS.CONF_EXT);   
23. ( CHECK_APP_DIR RUNTIME_PATH )
  1. think.class.php
  2. //   
  3.       if(C('CHECK_APP_DIR')) {
  4.           $module     =   defined('BIND_MODULE') ? BIND_MODULE : C('DEFAULT_MODULE');
  5.           if(!is_dir(APP_PATH.$module) || !is_dir(LOG_PATH)){
  6.               // 
  7.               Build::checkDir($module);
  8.           }
  9.       }
24. Think\App run
  1. think.class.php
  2. // 
  3.       App::run();
25. (app_init)
26.
27. Think\Dispatcher::dispatch URL
  1. App.class.php
  2. Dispatcher::dispatch();
28. URL $_SERVER['PATH_INFO']
  1. Dispatcher.class.php
  2.             $_SERVER['PATH_INFO'] = $_GET[$varPath];
29. (APP_SUB_DOMAIN_DEPLOY )
  1. Dispatcher.class.php
30. URL PATH_INFO
  1. Dispatcher.class.php
31.
32.
33. 、 、
34.
35. URL
36. (URL_ROUTER_ON )
  1. 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)
  1. App.class.php    
  2. static public function run() {
  3.         // 
  4.         Hook::listen('app_init');
  5.         App::init();
  6.         // 
  7.         Hook::listen('app_begin');
42. SESSION_OPTIONS Session ( )
  1. // Session
  2.         if(!IS_CLI){
  3.             session(C('SESSION_OPTIONS'));
  4.         }
43.
44.
45. (action_begin)
  1. Controller.class.php
  2. public function __construct() {
  3.         Hook::listen('action_begin',$this->config);
  4.         //
  5.         $this->view     = Think::instance('Think\View');
  6.         //
  7.         if(method_exists($this,'_initialize'))
  8.             $this->_initialize();
  9.     }
46. ReadHtmlCache (HTML_CACHE_ON )
47. _initialize
  1. Controller.class.php
  2. if(method_exists($this,'_initialize'))
  3.             $this->_initialize();
48. ,
49. ,
50. Action ,
51. ( display )
52. (view_begin)
53. Think\View fetch
  1. View.class.php
54.
55. (view_parse)
  1. View.class.php
  2.                
  3.             Hook::listen('view_parse',$params);
  4. common.php
  5. 'view_parse'    =>  array(
  6.             'Behavior\ParseTemplateBehavior', //    PHP、
  7.         ),
56. ParseTemplate ( )
  1. View.class.php
  2.     public function parseTemplate($template='') 
57.

58. (template_filter)
  1. Template.class.php
  2.         Hook::listen('template_filter',$tmplContent);
59. ContentReplace
  1. 'template_filter'=> array(
  2.             'Behavior\ContentReplaceBehavior', // 
  3.         ),
  4. ContentReplaceBehavior.class.php
  5. class ContentReplaceBehavior {
60. (view_filter)
  1. 'view_filter'   =>  array(
  2.             'Behavior\WriteHtmlCacheBehavior', // 
  3.         ),
61. WriteHtmlCache (HTML_CACHE_ON )
  1. WriteHtmlCacheBehavior.class.php
  2. class WriteHtmlCacheBehavior {
62. Think\View render
63. (view_end)
  1. view.class.php
64. ,
65. (action_end)
  1. Controller.class.php
66. (app_end)
  1. App.class.php        
  2. Hook::listen('app_end');
67. ShowPageTrace (SHOW_PAGE_TRACE AJAX )
68.