This article mainly focuses on simple execution analysis of Config source code. I hope you will have a deeper understanding from diagrams to code. The yaconf mentioned above is reflected here, and every article is to pave the way for what follows.
Although the above Yaconf does not do much for config source code analysis It's helpful, but it's also broadening your thinking. You can try to use Yaconf in your work in the future.
Let’s get to the point. If you want to know how Config loads and parses, let’s draw a picture first. Let’s take a look at the execution process of loading config.
Go back topublic/index.php
, as mentioned in the previous issue that the automatic loading of classes is executed during the process of loading the base.php file. of.
Then the loading of config is framed in the picture below. Containers are involved here, and there will be a separate topic to analyze the containers.
I won’t explain too much here. This code goes back to execute the run method of the file D:\phpstudy_pro\WWW\ThinkPHPSourceCodeAnalysis\thinkphp\library\think\App.php.
And what needs to be tracked in therun
method is theinitialize
application initialization function
and theninitialize
In this method, you will see clues of the configuration file, followed by an initialization applicationinit
It is not until you reach the init method that you enter the topic.
The automatic loading of the configuration file has started, and the load method in the config class has also been called, which also needs to be read together.
After coming here, you need to briefly interpret it
This code will go directly to elseif, because there is no config directory set up in the app directory
And there is a configPath attribute here that you are familiar with! This value is ultimatelyD:\phpstudy_pro\WWW\ThinkPHPSourceCodeAnalysis\config\
There are a few knowledge points to mention here, just review them
There is an attribute configExt in this code. This value is read out from the environment variable. The given value is php
Persistence in learning, persistence in blogging, and persistence in sharing are the beliefs that Kaka has always adhered to since its beginning. I hope that Kaka’s articles on the huge Internet can bring you a little bit of help. I’m Kaka, see you next time.
The above is the detailed content of ThinkPHP configuration source code execution process. For more information, please follow other related articles on the PHP Chinese website!