Framework bootstrap File source code (/thinkphp/start.php) 1. Introducing the underlying file (/thinkphp/base.php)
// loading the underlying file require __dir__. '/base.php ';
Base file (/thinkphp/base.php) 2. Defining system constants
1 Define(' Think_version ', ' 5.0.9 ');2 Define(' Think_start_time ',Microtime(true));3 Define(' Think_start_mem ',memory_get_usage ());4 Define(' EXT ', '. php ');5 Define(' DS ',directory_separator);6 defined(' Think_path ') orDefine(' Think_path ', __dir__.DS);7 Define(' Lib_path ', Think_path. ' Library '.DS);8 Define(' Core_path ', Lib_path. ' Think '.DS);9 Define(' Trait_path ', Lib_path. ' Traits '.DS);Ten defined(' App_path ') orDefine(' App_path ',dirname($_server[' Script_filename ']) .DS); One defined(' Root_path ') orDefine(' Root_path ',dirname(Realpath(App_path)) .DS); A defined(' Extend_path ') orDefine(' Extend_path ', Root_path. ' Extend '.DS); - defined(' Vendor_path ') orDefine(' Vendor_path ', Root_path. ' Vendor '.DS); - defined(' Runtime_path ') orDefine(' Runtime_path ', Root_path. ' Runtime '.DS); the defined(' Log_path ') orDefine(' Log_path ', Runtime_path. ' Log '.DS); - defined(' Cache_path ') orDefine(' Cache_path ', Runtime_path. ' Cache '.DS); - defined(' Temp_path ') orDefine(' Temp_path ', Runtime_path. ' Temp '.DS); - defined(' Conf_path ') orDefine(' Conf_path ', app_path);//Configuration file Directory + defined(' Conf_ext ') orDefine(' Conf_ext ', EXT);//configuration file suffix - defined(' Env_prefix ') orDefine(' Env_prefix ', ' php_ ');//configuration prefixes for environment variables + //Environment Constants A Define(' is_cli ', Php_sapi = = ' CLI '?true:false); at Define(' Is_win ',Strpos(Php_os, ' WIN ')!==false);3. Loading Loader class (/thinkphp/library/think/loader.php)
// Load Loader class require Core_path. ' loader.php ';
4. Load environment variable configuration file (/.env)
1 //load environment variable configuration file2 if(Is_file(Root_path. '. Env ')) {3 $env=Parse_ini_file(Root_path. '. Env ',true);4 foreach($env as $key=$val) {5 $name= Env_prefix.Strtoupper($key);6 if(Is_array($val)) {7 foreach($val as $k=$v) {8 $item=$name. ‘_‘ .Strtoupper($k);9 putenv("$item=$v");Ten } One}Else { A putenv("$name=$val"); - } - } the}5. Registration Automatic loading
// Register Auto-load \think\loader::register ();
Loader Class (/thinkphp/library/think/loader.php)
6. Automatic loading of registration system
// registration system automatically loads spl_autoload_register ($autoloadtruetrue);
7. Registering a Namespace definition
1 // Registering namespace Definitions 2 Self::addnamespace ([3 ' think ' = Lib_path. ' Think '. DS,4 ' behavior ' = Lib_path. ' Behavior '. DS,5 ' traits ' = Lib_path. ' Traits '. DS,6 ]);
Registered namespaces
8. Loading the Class library mapping file (/runtime/classmap.php)
1 // loading a class library mapping file 2 if (is_file(Runtime_path. ' Classmap '. EXT)) {3 self::addclassmap (__include_file (Runtime_path). ' Classmap '. EXT)); 4 }
9. Composer Automatic loading (/vendor/composer/)
1 // Composer Auto-load support 2 if (is_dir(Vendor_path. ' composer '){3self ::registercomposerloader (); 4 }
10. Load extend directory automatically (/extend)
// Auto Load EXTEND directory self ::$fallbackDirsPsr 4RTrim(Extend_path, DS);
11. Registration error and exception handling mechanism (/thinkphp/library/think/error.php)
1 //Report All Errors2 error_reporting(E_all);3 //set user-defined error handlers4 Set_error_handler([__class__, ' Apperror ']);5 //set user-defined exception handling functions6 Set_exception_handler([__class__, ' Appexception ']);7 //defines a function that executes after the completion of a PHP program execution8 register_shutdown_function([__class__, ' Appshutdown ');
12. Load the custom configuration file (/thinkphp/convention.php)
1 // loading a custom configuration file 2 \think\config::set (include Think_path. ' Convention '. EXT);
THINKPHP5 Source Analysis Two-frame boot