"In the above article, the instance returned after the make method is executed is analyzed. This article will analyze the invokeClass method in detail.
"
Detailed analysis of the invokeClass method (use of reflection)
Whether you have read the code flow above or the flow chart above, you must know where the final code will go A methodinvokeClass
is this method.
All the knowledge points in this method are based on the use of reflection. If you don’t know how, go read the above or previous articles!
In the invokeClass
method, the most important thing is the method of binding parameters bindParams
. This method also uses reflection.
So there is no need to explain too much about the role of reflection in the container.
Before this, I need to explain this. When I saw this __make method, I remembered it deeply!
This method was temporarily skipped in the previous article about learning config source code configuration, because the knowledge points and framework code execution process accumulated at that time were not yet at the stage of explaining the __make method.
In order to explain in detail the role of the __make method in the container.
When you print the value of the reflect variable, two reflection class objects will be returned, as shown below.
Code$reflect->hasMethod('__make')
It is to determine whether there is a __make function in this reflection class
Code$method = new ReflectionMethod($class, '__make');
It is a method to execute the reflection class. Here it refers to the __make method
When the breakpoint is reached, this method will return two existing __make reflections Class, this is because only two reflection classes are displayed due to breakpoints.
Here we mainly talk about think\Config.
The last line of code$method->isPublic() && $method->isStatic()
is the judgment Whether the method is public Determine whether the method is static
This line will not be entered until $args = $this->bindParams($method, $vars);
bindParams
method, this method will also give a detailed analysis below.
The detailed analysis of the invokeClass method ends here. It mainly uses the reflection mechanism to implement a series of functions, uses reflection to perform dependency injection, and executes the __make method in the class
“Persistence in learning, persistence in blogging, and persistence in sharing are the beliefs that Kaka has always upheld since his career. 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 The use of reflection in ThinkPHP containers. For more information, please follow other related articles on the PHP Chinese website!