thinkphp View after detailed (1)

Source: Internet
Author: User
Tags rtrim

Recently interviewed some companies, found their lack of architectural ability, so decided to start from the most basic code. Let's take a look at how Daniel architectures the entire framework. In view of the foreign framework is more difficult to understand, so chose the domestic more popular thinkphp to carry out research.

I will update the content below, all of my own personal views.

1. First we look at the entrance file index.php

if (Version_compare (php_version, ' 5.3.0 ', ' < ') die  (' Require PHP > 5.3.0! '); /Open debug mode recommend the development phase to open the deployment phase note or set to Falsedefine (' App_debug ', True);//define the application directory define (' App_path ', './application/');// Introduction of the thinkphp entry file require './thinkphp/thinkphp.php ';

The code is simple enough to determine if PHP is greater than 5.3, not terminate. Defines the App_path path, which contains the core file thinkphp.php

2. Next follow the code to see the contents of thinkphp.php.

Record start run time $globals[' _begintime '] = Microtime (TRUE);//record memory initial use define (' memory_limit_on ', function_exists (' Memory_ Get_usage ')); if (memory_limit_on) $GLOBALS [' _startusemems '] = Memory_get_usage ();

Define the program run time and memory usage, I think it might be used for debugging purposes. This data is recorded in the $global of the super variable.

System constants define defined (' Think_path ') or define (' Think_path ', __dir__. ') /');d efined (' App_path ') or define (' App_path ', dirname ($_server[' script_filename ']). ' /');d efined (' app_status ') or define (' app_status ', '); Apply state to load the corresponding configuration file defined (' App_debug ') or define (' App_debug ', false);    Whether debug mode if (Function_exists (' Saeautoloader ')) {//auto-Identify SAE environment 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 ');//Application Mode defaults to normal mode defined (' Storage_type ') or Define (' Storage_type ', ' File '); The storage type defaults to file}defined (' Runtime_path ') or define (' Runtime_path ', App_path. ')   runtime/'); System runtime directory defined (' Lib_path ') or define (' Lib_path ', Realpath (Think_path. ') Library '). ' /‘); System core Class Library directory defined (' Core_path ') or define (' Core_path ', Lib_path. ' think/'); Think class library directory defined (' Behavior_path ') or define (' Behavior_path ', Lib_path. ' Behavior/'); Behavior Class Library Directory defined (' Mode_path ') or define (' Mode_path ', Think_path. ') mode/'); System Application Mode directory defined (' Vendor_path ') or define (' Vendor_path ', Lib_path. ' vendor/'); Third-party class library directory defined (' Common_path ') or define (' Common_path ', App_path. ') Common/'); Apply public directory defined (' Conf_path ') or define (' Conf_path ', Common_path. ') conf/'); Application configuration directory defined (' Lang_path ') or define (' Lang_path ', Common_path. ' lang/'); Application language directory defined (' Html_path ') or define (' Html_path ', App_path. ') Html/'); Apply static directory defined (' Log_path ') or define (' Log_path ', Runtime_path. ') Logs/'); Application log directory defined (' Temp_path ') or define (' Temp_path ', Runtime_path. ' temp/'); Apply cache directory defined (' Data_path ') or define (' Data_path ', Runtime_path. ') data/'); Application Data Catalog defined (' Cache_path ') or define (' Cache_path ', Runtime_path. ') cache/'); Apply template cache directory defined (' Conf_ext ') or define (' Conf_ext ', '. php ');    Config file suffix defined (' conf_parse ') or define (' Conf_parse ', '); Configuration file parsing method defined (' ADdon_path ') or define (' Addon_path ', App_path. ' Addon ');

The definition of system constants, which all record the core folders in the framework in constants.

System Information 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);d efine (' Is_win ', Strstr (php_ OS, ' WIN ')? 1:0);d efine (' is_cli ', php_sapi== ' CLI '? 1   :   0);

The operating system and PHP run environment information are also set constants

if (!IS_CLI) {    ///Current file name    if (!defined (' _php_file_ ')) {        if (is_cgi) {            //cgi/fastcgi mode            $_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));}    }

Distinguishes between CGI and non-CGI script URL addresses or server address _php_file_, and records the server path _root_ for an item.

Load core think class require Core_path. ' Think '. ext;//application Initialization of Think\think::start ();

Load the core think class and launch the entire application.

The code above is the preparation of the application and is the foundation of the framework. The basic idea is that the entire frame structure, PHP running server information are recorded in constant. Easy to invoke when debugging later.

  

thinkphp View after detailed (1)

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.