I'm still learning PHP, and I assume it is not so hard to understand that I'm not a native speaker.
At this moment, after reading a lot of documentations, I jumped into the deep water, so I opened Laravel source files and went file after file, trying understand better how the whole implementation of MVC include routing, Middlewares getting together into a high level piece of code.
I've seen a lot of terms I never knew before, but some were easy to understand, while the term "Resolved" and "Resolving" break a little bit my head.
What does it really mean?
Few examples from the documentations in the files:
"Flush the container of all bindings and resolved instances."
"An array of the types that have been resolved."
"All of the global resolving callbacks."
"All of the after resolving callbacks by class type."
"All of the after resolving callbacks by class type."
Now I'm a bit confused, resolved and resolving in a simple translation to my language means to settle down, to decide, to determine, to separate, to breakdown, but nothing of them making any sense for me at the code.
Can you please clarify a bit about the resolving meaning? as I feel once I will understand this term, all will go more smoothly.
so I opened Laravel source files and went file after file, trying understand better how the whole implementation of MVC include routing, Middlewares getting together into a high level piece of code.
There is a better way to understand the framework source. Use the debugger.
Take any simple application example, setup the XDebug and go through the whole process of the request handling.
First jump over the details and find out which classes and methods are involved into the request processing, then you can go deeper and deeper.
At least for me this way works much better than just reading the source. You'll quickly find what is important and what is less important and will be able to concentrate on the essential parts.
Now let's get back to your resolution
questions:
"Flush the container of all bindings and resolved instances."
Here is the source file - Illuminate/Container/Container.php. And the related documentation: https://laravel.com/docs/5.0/container.
Actually, to understand the source, you first need to understand the concepts in the documentation. In this case they are talking about the dependency injection container and you need to understand how it works:
public function __construct(FooBar $dependency)
$foo = new FooBar; $object = new MyObject($foo);
; instead we configure the Laravel's service container and it resolves
these dependencies for usresolution
here is the process when we ask the service container: "give us FooBar, please" and it goes through it's internal registry and finds out (resolves) what object should actually be createdWhy do we do this? Because we don't want to hard code the dependencies.
For example, you can have a class which depends on Mailer
.
On production you want this Mailer
to be SMTPMailer
and while testing you want to use MockMailer
which writes emails to the file.
So you configure Laravel service container to resolve Mailer
as MockMailer
locally and to resolve it as SMTPMailer
on production.
--- resolution process ------
| |
---------------------
| | ----------------
-------------------------------- | Container | ---->| SMTPMailer |
| MyObject | | | / ----------------
| | | | internal | | /
| __construct(Mailer $mailer) -|---->| | registry |------- ----------------
| | | | | | | MockMailer |
------------------------------- | | ----------------
---------------------
In MyObject
we define some abstract Mailer
dependency which is then resolved by the Container
into SMTPMailer
or MockMailer
, depending on the configuration.
Check more usage examples and explanations in the Laravel docs.
"An array of the types that have been resolved."
This is an array of the types (like FooBar) we requested before, which have been already resolved (we already know what actual class maps to FooBar
).
"All of the global resolving callbacks."
This is an array of callbacks which are used to resolve dependencies - this is a part of the Laravel's internal registry.
"All of the after resolving callbacks by class type."
These are callbacks which are called when the resolution complete. Probably this is related to this section in the documentation - container events.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With