Request Lifecycle Trong Laravel

Tram Ho

Introduce

  • Please welcome everyone back to the next post about Request Lifecycle in laravel here. (hihi)

1. Request Lifecycle

  • Using any tool, we feel more confident if we can understand how it works, so does application development when you understand how the tools work. Feel more confident using them. The purpose of this sequel I want you to have an overview of how laravel works. By having a more holistic view, you will feel that everything feels less "magical" and more confident when building your applications. If you do not understand all the terms immediately, don't get discouraged! Try to understand each of the most basic, your knowledge will increase as you explore each part of this document.

2. Overview of Lifecycle

Like all frameworks, every request of a Laravel application is started from the public / index.php file. All requests to this file are from your Web Server (Apache / Nginx). The file ndex.php will not include a lot of code. Instead it is the starting point for loading the rest of the framework.

In the index.php file will load the packages installed from Composer and initialize Autoloader , and then initialize the framework of the Laravel framework from bootstrap / app.php script. The first is that Laravel generates its own service container application instances.

HTTP / Console Kernels

Next, requests will be sent to the HTTP kernel or console kernel, depending on the type of request updating the application. These two kernels will act as the control center that all requests will have to go through, but in this article let's just focus on understanding the HTTP kernel, its location located in the app / Http / Kernel. php .

The HTTP kernel is extended from the Illuminate Foundation Http Kernel class, which defines an array of bootstrappers that will be run before requests are made. The bootstrappers configure error handling, logging configuration, and the next, requests are sent to the HTTP kernel or console kernel, depending on the type of request updating the application. These two kernels will act as the control center that all requests will have to go through, but in this article let's just focus on understanding the HTTP kernel, its location located in the app / Http / Kernel. php.

The HTTP kernel is extended from the Illuminate Foundation Http Kernel class, which defines an array of bootstrappers that will be run before requests are made. Bootstrappers configure error handling, logging configuration, detect the application environment, and perform other tasks that need to be performed before the request is actually processed.

The HTTP kernel also defines a list of HTTP middleware that all requests must go through before being processed by the application. These middleware handle read and write HTTP sessions, determine if the application is in maintenance mode, verify the CSRF token, and more.

The signature method for the HTTP kernel handle method is very simple: receive a Request and return a Response. Think of the Kernel as an operating center that represents your entire application. Provide it with HTTP requests and it will return HTTP responses. Next, the requests will be sent to the HTTP kernel or console kernel, depending on the type of request updating the application. These two kernels will act as the control center that all requests will have to go through, but in this article let's just focus on understanding the HTTP kernel, its location located in the app / Http / Kernel. php.

The HTTP kernel is extended from the Illuminate Foundation Http Kernel class, which defines an array of bootstrappers that will be run before requests are made. Bootstrappers configure error handling, logging configuration, detect the application environment, and perform other tasks that need to be performed before the request is actually processed.

The HTTP kernel also defines a list of HTTP middleware that all requests must go through before being processed by the application. These middleware handle read and write HTTP sessions , determine if the application is in maintenance mode, verify the CSRF token , and more.

The signature method for the HTTP kernel handle method is very simple: receive a Request and return a Response . Think of the Kernel as an operating center that represents your entire application. Give it HTTP requests and it will return HTTP responses ., And perform other tasks that need to be done before the request can actually be processed.

The HTTP kernel also defines a list of HTTP middleware that all requests must go through before being processed by the application. These middleware handle read and write HTTP sessions, determine if the application is in maintenance mode, verify the CSRF token , and more.

The signature method for the HTTP kernel handle method is very simple: receive a Request and return a Response . Think of the Kernel as an operating center that represents your entire application. Give it HTTP requests and it will return HTTP responses.

Service Providers

One of the most important actions is to download service providers for your application. All service providers for the application are configured in config / app.php in the providers array. First, the register method will be called in all providers, then, when all providers are registered, the boot method will be called.

Service providers are responsible for starting up all the different components of the framework such as database , queue , validation , and routing components . Because they start and configure all of the features provided by the framework, service providers are the most important component of the entire Laravel boot process.

Dispatch Request

Once the application has finished booting and all service providers have been registered, requests are sent to the routers . Routers check requests that are routed to a route or controller , as well as running through any middleware .

3. Service Providers

Service providers are the key to installing a Laravel application. Instances will be created , service providers are registered, and requests are processed. It is simple =))

There is an awareness of how important a Laravel application is built and how it is installed through service providers . Of course, the default values ​​of s ervice providers in your application are stored in the app / Providers directory.

AppServiceProvider is completely blank. Providers are the ideal place to add settings to your application. Of course, for a large application, you can create service providers, each corresponding to a configuration type of installation.

Source: https://laravel.com/docs/6.x/lifecycle

4 Finish

  • Hope the above article will help you who have been working with FW laravel nhe ^. ^. The next article I will write about Service Container and Service Providers in detail. Thank you. – To be Continue –
Share the news now

Source : Viblo