Objective:
Due to the relatively lazy, but a bit obsessive-compulsive disorder, so still want to continue to ThinkPHP3.2 loading process this rotten tail building to complement the complete.
======================================== Split Line =================================
Last article says load App:run ()----under thinkphp/library/think/thinkclass.php
Here is a description of when the app will be defined and loaded
Configuration file thinkphp/mode/common.php When thinkphp/library/think/thinkclass.php was introduced, the app class was introduced at the same time
Functions and class files
function and class file ' core ' = = Array ( Think_path. Common/functions.php ', common_path. ' Common/function.php ', core_path. ' Hook '. EXT, Core_path. ' App '. EXT, Core_path. ' Dispatcher '. EXT, //core_path. ' Log '. EXT, Core_path. ' Route '. EXT, Core_path. ' Controller '. EXT, Core_path. ' View '. EXT, Behavior_path. ' Buildlitebehavior '. EXT, Behavior_path. ' Parsetemplatebehavior '. EXT, Behavior_path. ' Contentreplacebehavior '. EXT, ),
So we know that the APP's class file address is thinkphp/library/think/app.class.php and the Run method is executed
/** * Shortcut method used to run the application instance Portal file * @access public * @return void * /static public function run () { //application First Start labeling hook::listen (' App_init '); App::init (); Apply start tag hook::listen (' App_begin '); Session Initialization if (!IS_CLI) { session (C (' session_options ')); } Log application initialization time G (' inittime '); App::exec (); Apply end tag hook::listen (' app_end '); return; }
Analysis of the code under the Run method
First paragraph:
Apply Initialize tag hook::listen (' app_init ');
Hook this thinkphp called system hooks (should be like fishing, use this to hook up the fish)
Introduced time: Should he be included in the commom.php this core array is introduced
File Location: thinphp/library/think/hook.class.php
First line: Hook::Listen (' app_init ');
Simplify Your code:
/** * Monitor tag plug-in * @param string $tag tag name * @param mixed $params incoming parameter * @return void */ static Publi C function Listen ($tag, & $params =null) { if (Isset (self:: $tags [$tag])) { foreach:: $tags [$tag] as $ Name) { $result = self::exec ($name, $tag, $params); if (false = = = $result) { //If return false then break plug-in execution return; }}} return;}
where self:: theexec() code is below
/** * Execute a plugin * @param string $name plug-in name * @param string $tag method Name (sign) * @param Mixed $params passed in parameter * @ return void */ static public function exec ($name, $tag,& $params =null) { if (' Behavior ' = = substr ($name, -8) { ///The behavior extension must be $tag = ' run ' using the Run entry method;} $addon = new $name (); Return $addon $tag ($params);
About when the parameter app_init was passed to the self: :$tags() for a brief explanation
The configured file is also the tags array under thinkphp/mode/common.php
by thinkphp/library/think/thinkclass.php
The load mode behavior defines if (isset ($mode [' tags ')]) {Hook::import (the is_array ($mode [' tags '])? $mode [' Tags ']:include $mode [' tags ']); }
Tags that are configured to the system hooks
Through the configuration file we see App_init for the class is Buildlitebehavior
The first piece of code summarizes:
Instantiate the Buildlitebehavior class that addresses thinkphp/library/bechavior/buildlitebeavior.class.php and runs the Run method
The approximate code for BuildLiteBeavior.class.php is to put the previously running code together, including the definition of the parameters in it, which is turned off by default, so you don't need to bother
Second paragraph
App::init ();
Collective code:
/** * Application Initialization * @access public * @return void */static publicly function init () {//Load Dynamic application Common File and Configuration load_ext_file (Common_path); The log directory is converted to an absolute path by default to the public module under C (' Log_path ', Realpath (log_path). ' /common/'); Defines the system constants for the current request define (' Now_time ', $_server[' request_time ']); Define (' Request_method ', $_server[' request_method '); Define (' Is_get ', request_method = = ' GET '? true:false); Define (' Is_post ', request_method = = ' POST '? true:false); Define (' Is_put ', request_method = = ' PUT '? true:false); Define (' Is_delete ', request_method = = ' DELETE '? true:false); URL dispatch Dispatcher::d ispatch (); if (C (' Request_vars_filter ')) {//Global security filter array_walk_recursive ($_get, ' think_filter '); array_walk_recursive ($_POST, ' Think_filter '); array_walk_recursive ($_request, ' think_filter ');} URL Dispatch end tag hook::listen (' Url_dispatch '); Define (' Is_ajax ', ((Isset ($_server[' Http_x_requested_with ')) && strtolower ($_server[' http_x_requested_with ']) = = ' Xmlhttpre Quest ') | | !empty ($_post[c (' Var_ajax_submit ')]) | | !empty ($_get[c (' Var_ajax_submit ')))? True:false); Tmpl_exception_file changed to absolute address C (' Tmpl_exception_file ', Realpath (C (' Tmpl_exception_file '))); return; }
Here the approximate content, through the URL gets the module name: Controller name: Method name
Third paragraph:
Apply start tag hook::listen (' App_begin ');
More with previous experience, App_begin's files are in thinkphp/library/behavior/readhtmlcachebehavior.php
And the Run method that runs the file
Run Method code
The execution entry for the behavior extension must be run public function run (& $params) { //Turn on static cache if (is_get && C (' html_cache_on ')) { $cacheTime = $this->requirehtmlcache (); if (false!== $cacheTime && $this->checkhtmlcache (Html_file_name, $cacheTime)) {//static page valid// read static page output Echo storage::read (html_file_name, ' HTML '); Exit ();}} }
If a cache file rule is defined, the cache file is used, because by default it is turned off
Part III:
Session Initialization if (!IS_CLI) { session (C (' session_options ')); } Log application initialization time G (' inittime ');
If it is a request from a Web page, the session is initialized with the session_options rule in the configuration file.
Record initialization time
Part IV:
App::exec ();
Specific code in the/thinkphp/library/think/app.class.php file exec ()
This method and the basic function is to enable the framework to find the corresponding controller and method.
About Routing and app::exec (); method, next separate specific description
Summarize:
/** * Shortcut method used to run the application instance Portal file * @access public * @return void * /static public function run () { //application First Initialize the label hook::listen (' app_init ');//Invalid App::init by default (); the module name controller name and method name are found through the URL //Application start tag hook::listen (' App_begin '); Static cache page, default off //session Initialization if (!IS_CLI) { session (C (' session_options ')); Session initialization According to session_options in the configuration file } //Record application initialization time G (' inittime '); Do record app::exec (); Know for the controller and method name and run //apply end tag hook::listen (' app_end ');//default off This function is to display some SQL execution, response time and other parameters of Web page request return; }
ThinkPHP3.2 loading Process (iv)