Home > Article > PHP Framework > ThinkPHP container registration tree mode
Before learning the container source code, you must learn another design pattern, the registration tree pattern. This design pattern is also a core of the container.
Why do we say this registration tree mode here, because in the framework The mid-registration tree pattern is a dominant position, so you must understand it!
So what is a registration demonstration!
It definitely won’t be better understood if you say this. Next, Kaka will show you a simple case to have a simple understanding.
A registration tree mode requires four things: the pool of the registration tree, mounting the object to the registration pool, obtaining the object from the registration pool, and unloading the object from the registration pool.
The picture below is a simple registration tree model written by Kaka.
If you don’t understand the code, you need to go and make up the basics!
Next create a TestTree file in the same directory
Come to the controller to test whether there is any problem with the registration tree mode written.
Be sure to pay attention to the namespace issue when testing! The kaka directory here was previously configured in the automatic loading of classes. If you don’t know how to do it, you can check it out in the first issue of the article.
This is equivalent to instantiating the TestTree class first
Then use the registration tree mode to register this instance into the object tree pool
Finally use the get method to register this instance Once the class is obtained, you can directly call the methods in TestTree.
Finally, take a look at the final print result. The result is the return value of the getTreeContent method in the TestTree class.
The registration tree mode is what Kaka explained above. It means that we don’t have to study the source code. These contents are also what we must learn to use.
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 container registration tree mode. For more information, please follow other related articles on the PHP Chinese website!