All configuration file types in the framework are PHP files, so how do we enable it to load other types of extensions! This article is only an extension and it is not recommended to change the framework source code.
The loadFile method we saw before If the file type is PHP or yaml, the program will be interrupted and the subsequent pares method will not be executed.
So what does this parse method do?
After entering the paras method, first read the comments
Then use a factory mode to load the files under think/config/driver
After entering the factory method, there is no need to explain too much that this content belongs to the container.
You only need to know that an instance will eventually be returned to the $object variable of the paras
method.
In the end, the set method mentioned above will be used, and The internal object->parse() is an internal method that executes the returned object. For example, the following figure shows three types. The same methods exist in the three types of ini, json, and xm
This is the ini type. The other two types are exactly the same, that is, they will have the same method to implement the corresponding functions.
Briefly sort out the different types of configurations loaded by the factory mode
Here Kaka will publish a separate article later to imitate this to achieve another function, and the map will have links to all articles!
I saw a method parse_ini_file
in ini.php. In fact, based on previous study, you can probably understand this method to convert the ini type configuration file into an array form. I won’t do a demonstration here, it’s very simple!
The other two types are for converting file data into arrays.
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 How to load other types of configuration files in ThinkPHP. For more information, please follow other related articles on the PHP Chinese website!