ThinkPHP3.0 startup process

Source: Internet
Author: User
Tags autoload php class

Example of a blog
Loading Project Entry File
D:\wamp\www\Examples\Blog\index.php
Defining constants
App_name,blog
App_path,d:\wamp\www\examples\blog\ (App_path is the directory where the project core framework file (LIB) is located)
Loading the thinkphp framework entry file
D:\wamp\www\ThinkPHP\ThinkPHP.php
Logging start run time, recording memory usage
Checks whether the item defines a constant App_path (if not defined as directory D:\wamp\www\ThinkPHP\)
Define constants according to App_path Runtime_path,d:\wamp\www\examples\blog\runtime\
Checks whether the item defines a constant App_debug,false (if not defined as false)
Checks whether the item defines a constant mode_name,~runtime.php (if not defined as ~runtime.php)
Defining Constants Runtime_file,d:\wamp\www\examples\blog\runtime\~runtime.php
If non-debugging coexist in runtime_file, load d:\wamp\www\examples\blog\runtime\~runtime.php directly
If you don't have this file right now,
Defining Constants Think_path,d:\wamp\www\thinkphp\thinkphp\
When you load a runtime file
D:\wamp\www\ThinkPHP\ThinkPHP\Common\runtime.php
Checks whether constant Think_path is defined, terminates the program without definition
Check the PHP version if it is less than 5.2.0 terminating program execution
Defining Constants Think_version,3.0
Defining Constants Think_release,20120323
Set Magic quotes based on PHP version
Defining Constants Magic_quotes_gpc,false
Defining Constants Is_cgi,0
Defining Constants is_win,1
Defining Constants Is_cli,0
Check if app_name is defined
PHP Non-CLI mode
Defining Constants _php_file_,/examples/blog/index.php
Defining Constants __root__,/examples
Defining constants Url_common, 0
Defining Constants Url_pathinfo, 1
Defining Constants Url_rewrite, 2
Defining Constants Url_compat, 3
Path settings you can redefine all path constants in the project or in the thinkphp portal file must end with/
Define Constants Core_path, d:\wamp\www\thinkphp/lib/
Define Constants Extend_path, d:\wamp\www\thinkphp/extend/
Define Constants Mode_path, d:\wamp\www\thinkphp/extend/mode/
Define Constants Engine_path, d:\wamp\www\thinkphp/extend/engine/
Define Constants Vendor_path, d:\wamp\www\thinkphp/extend/vendor/
Defining Constants Library_path,d:\wamp\www\thinkphp/extend/library/
Define Constants Common_path, d:\wamp\www\examples\blog\common/
Define Constants Lib_path, d:\wamp\www\examples\blog\lib/
Define Constants Conf_path, d:\wamp\www\examples\blog\conf/
Define Constants Lang_path, d:\wamp\www\examples\blog\lang/
Define Constants Tmpl_path, d:\wamp\www\examples\blog\tpl/
Define Constants Html_path, d:\wamp\www\examples\blog\html/
Define Constants Log_path, d:\wamp\www\examples\blog\runtime/logs/
Define Constants Temp_path, d:\wamp\www\examples\blog\runtime/temp/
Define Constants Data_path, d:\wamp\www\examples\blog\runtime/data/
Define Constants Cache_path, d:\wamp\www\examples\blog\runtime/cache/
Set Vendor_path directory to Include_path
Defines the initialization method, Build_app_dir,build_first_action,build_runtime_cache,build_tags_cache,check_runtime,load_runtime_file
Calling the Load_runtime_file method
Load the underlying function file common.php,d:\wamp\www\thinkphp\common/common.php
Loading core compilation files
d:\wamp\www\thinkphp/lib/core/think.class.php
d:\wamp\www\thinkphp/lib/core/thinkexception.class.php
d:\wamp\www\thinkphp/lib/core/behavior.class.php
Import alias configuration file into alias static variable $_alias, alias profile is d:\wamp\www\thinkphp\conf/alias.php
Create default project file structure and config.php and IndexAction.class.php files if directory d:\wamp\www\examples\blog\lib/does not exist
Check the project's cache directory d:\wamp\www\examples\blog\runtime/cache/if it exists. Creates a default file structure if it does not exist.
If it is debug mode, delete the runtime_file defined file
Log load file time
Executive Think::start ()
This method is in the core file d:\wamp\www\thinkphp/lib/core/think.class.php class.
Set error and exception handling, apperror,appexception
Register AutoLoad method, AutoLoad
Execute the Think::builapp method
Import the custom configuration file into the configuration static variable $_config, the custom configuration file is d:\wamp\www\thinkphp\conf/convention.php
If you define a constant Mode_name, import the corresponding schema profile to the variable d:\wamp\www\thinkphp/extend/mode/directory $mode
If the mode configuration profile has a config entry, it is imported into the configuration static variable $_config
Configure the project configuration Profile d:\wamp\www\examples\blog\conf/config.php import configuration static variable $_config
Load top-level language pack D:\wamp\www\ThinkPHP\Lang\zh-cn.php to language static variable $_lang
The system behavior is defined as follows:
If there is app_tags_on in the static configuration variable and is true, load the extends key of the variable $mode to the extends of the configuration static variable $_config, the variable $mode has no extends item,
Import the tags.php under the system configuration into the extends configured with the static variable $_config, d:\wamp\www\thinkphp\conf/tags.php
The project behavior is defined as follows:
Load variable $mode extends item to configure static variable $_config under tags, variable $mode no tags item,
Import the tags.php under project configuration to the tags that configure the static variable $_config, d:\wamp\www\examples\blog\conf/tags.php
Read the core compilation file as follows:
If the variable $mode defines the core, the key file is the key, and if there is no definition, the core file is
d:\wamp\www\thinkphp\common/functions.php
d:\wamp\www\thinkphp/lib/core/log.class.php
d:\wamp\www\thinkphp/lib/core/dispatcher.class.php
d:\wamp\www\thinkphp/lib/core/app.class.php
d:\wamp\www\thinkphp/lib/core/action.class.php
d:\wamp\www\thinkphp/lib/core/view.class.php
Save the array of the project core configuration definition d:\wamp\www\examples\blog\conf/core.php and the above file to the variable $list
Load the core file sequentially
In non-debug mode, these core files are written to the variable $compile
Load Project Public file d:\wamp\www\examples\blog\common/common.php
Write project public file to variable $compile when non-debug mode
Import the alias entry of the variable $mode to the aliased static variable $_alias
Non-debug mode writes the alias of the variable $mode to the variable $compile
Import the project alias file into the alias static variable $_alias,d:\wamp\www\examples\blog\conf/alias.php
Non-debug mode writes the alias of the project alias file to the variable $compile
If you are debugging the environment,
Import the System Debug configuration file into the configuration static variable $_config,d:\wamp\www\thinkphp\thinkphp\conf/debug.php
Remove the App_status configuration, load the project configuration Debug configuration file d:\wamp\www\examples\blog\conf/$status. php
If non-debug mode, call the Build_runtime_cache function to generate the compiled file
Basically will language Pack, config, alias, core function, defined variable, d:\wamp\www\thinkphp/lib/behavior/in the class defined by extends, generate a file ~runtime.php
Execute the App::run method
Instantiate behavior based on app_init items recorded by extends and tags
Setting the time zone
If you configure a static variable $_config has a Load_ext_file entry, the file is dynamically loaded in the d:\wamp\www\examples\blog\common/directory
If you configure a static variable $_config has a Load_ext_config entry, the file is dynamically loaded in the d:\wamp\www\examples\blog\conf/directory to a static variable $_config
Execute Dispatcher::d Ispatch method
There is too much code here ~ ~ Not understand
If grouping is set, the configuration and functions are loaded according to the grouping
Defining template-related constants
Instantiate behavior based on app_begin items recorded by extends and tags
The Session_options item session is initialized according to the configuration static variable $_config.
Executes the instance's Execute method by loading the corresponding class and instantiating it from the Session_type to the d:\wamp\www\thinkphp/extend/driver\session/directory
Record application Initialization time
Execute the MVC process,
Involves the __hack_module method and the empty module
Perform action_name behavior
_before_action method for performing the corresponding action of the module
Execute module corresponding action
_after_action method for performing the corresponding action of the module
Instantiate behavior based on app_end items recorded by extends and tags
Save Log records

Appendix:
Auto Load
First from the alias static configuration variable $_alias, if there is a direct load
In the case of the Behavior class, from the d:\wamp\www\thinkphp/lib/behavior/directory, d:\wamp\www\thinkphp/extend/behavior/directory, D:\wamp\www\ examples\blog\lib/behavior/,/behavior/directory lookup for the schema directory
If the Model class, from the d:\wamp\www\examples\blog\lib/model/directory, d:\wamp\www\thinkphp/extend/model/directory lookup
If the Action class is found from the d:\wamp\www\examples\blog\lib/action/directory, the d:\wamp\www\thinkphp/extend/action/directory
Automatic loading of App_autolaod_path items based on configuration of static variable $_config
Configuration file Order
System alias alias.php
System Conventions convention.php
System mode configuration files such as cli.php
Project configuration file config.php
Language Pack Files zh-cn.php
System Behavior File tags.php
Project behavior File tags.php
Project Core Configuration core.php
Project Alias alias.php
System Debug Configuration file debug.php
Project Debug Configuration, $status. php

ThinkPHP3.0 startup process

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.