In this blog post I talk about Laravel's Service Providers and about its life cycles.
In brief, a Laravel application is bootstrapped (started) whenever a webrequest hits index.php
in the public
folder, or when an artisan
command is executed. Tough both the index.php
and artisan
file work very similarly, I will only talk about index.php
.
When the index.php
file is called it registers the autoloader. After that Laravel's Application is initiated and stored in the $app
variable which is used to construct a kernel that manages the input and output of our app.
After handling the input by our $kernel
it returns a $response
object which is send back to our visitor.
Let's rewind a bit, there are four1 important things that are done in the index.php
:
- The autoloader is registered
- Laravel's
Application
class is initiated and stored in$app
- A kernel is constructed using the
$app
's Service Container. - The kernel handles our input and returns a response.
The goal of this blog post is to explain the inner workings of Laravel's life cycle. The next section describes how the Applicaiton
class works
When a Laravel application is bootstrapped a Applicaiton
object is made in bootstrap/app.php
. This object can be found in vendor/laravel/framework/src/Illuminate/Foundation/Application
.
There are two important bits about this class: it extends the Illuminate\Container\Container
and implements a ApplicationContract
.
Footnotes:
- Actually there is a fifth step where we terminate the kernel which will call the
terminate
method on any activeTerminableMiddleware
and terminates the$app
instance.
Any updates on this ?