This article mainly analyzes the source code of Config in depth, mainly analyzes the code in the config file, and annotates it step by step, so that you can better see the execution process of the code.
After parsing the previous code execution process, the last step will come to the config file, and then the load method will be introduced.
Then you need to go to the filethinkphp/library/think/Config.php
. In the app file, load in the config class is finally called.
Let’s take a look at what we have experienced
In the load method, the final direction of the process will be in theloadFile
method. As for why the elseif code does not Go, or this code is redundant.
Because when Yaconf is installed, the corresponding configuration file will be loaded directly after PHP is started.
If you don’t know about yaconf, please read the previous article
After coming to the loadFile file
We all know that in the ThinkPHP framework, all files in the config directory are of PHP type
So after judging the type, we directly enter the set for data processing
include directly introduces the configuration files in the config directory, and all configuration files directly return an array
In the set method, this code is the core
Keep merging arrays in a loop, and finally return all configuration information to the config attribute
Up to this point, all configurations in the config directory have been loaded.
The above is the loading process of config. In fact, after you finish reading, it doesn’t feel that difficult. It just depends on coding skills and ideas.
When we read the source code, we do not see how the code is written, but learn its coding ideas and finally implement them in our own projects.
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 In-depth analysis of ThinkPHP configuration source code. For more information, please follow other related articles on the PHP Chinese website!