“This article is mainly about learning how the __make method is executed in each method, and now that we have learned about the container, how can we use the container to call the configuration to obtain the configuration information? .
”
Analyze the bindParams method
Next, let’s analyze the bindParams
method.
Regarding parameter passing, it is a reflection class. The second parameter will not be explained for the time being. There is no response scenario yet.
The first parameter value$reflect
##Use the reflection method$reflect->getNumberOfParameters( )
Get the number of parameters in the corresponding method in the reflection class. According to the above, it is the __make method. The number of parameters of only two methods has been obtained in the container code, one is the __make method, and the other is the constructor in the reflection class.
Code$params = $reflect->getParameters();
also uses reflection to obtain the parameters of the method.
The results you can see when printing are two sets of data.
So where does this set of data come from? Scroll up and take a look at what the
$reflect
parameter is and you will understand.
think\App This reflection class does not have a __make method, so the parameters in the constructor will be obtained.
Then there is a __make method in the think\Log reflection class, so the parameters of __make will be returned, as shown below.
Just like a class like think\Log, which has both a __make method and a constructor, it will go twice bindParams
method , you should all understand this, it is exactly the logic in the picture below.
The next step is the parameters obtained in the loop reflection class.
Get the parameter name, and get the corresponding reflection class
Finally, pass the obtained reflection class to the getObjectParam
method.
There is not much content in this
getObjectParam
method.
Since $vars
is an empty array from beginning to end, the operation of removing the first element of the array and determining whether it is a closure will not be executed.
The make method will eventually be executed upon return
Then the make method will return the instance directly from the container
When a reflection class exists __make method,
return $method->invokeArgs(null, $args);
will eventually be executed, and the reflection class method will be executed with parameters
Use the container to call Configuration class
Now that I have read the container source code once, can I use the container to implement it?
Of course it is possible. Here you need to pay attention to the namespace of Kaka. For the convenience of future review, the class name is also named Container, so I added an alias. The one you are using Time is not needed!
As of now, the source code of the container is almost explained. Later, Kaka will make a complete flow chart for everyone to view.
“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 ThinkPHP container binding parameters. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Zend Studio 13.0.1
Powerful PHP integrated development environment

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
