Home  >  Article  >  PHP Framework  >  ThinkPHP configuration source code execution process

ThinkPHP configuration source code execution process

咔咔
咔咔Original
2020-10-09 15:11:051562browse

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.

6. Config source code execution process

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 to public/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 the run method is the initialize application initialization function

and then initialize 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 ultimately D:\phpstudy_pro\WWW\ThinkPHPSourceCodeAnalysis\config\

##The next step is to take out all the files in the config directory.

Passed to the load method of the config class

There are a few knowledge points to mention here, just review them

  • scandir: Return all files in a directory in ascending order, and there is a second parameter 1 , indicating that all files in a directory are returned in descending order.
  • pathinfo: Returns file information in the form of an array, which are directory name, file name, and extension. Several of the parameters are mentioned in the code. You can see the picture below. .

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn