Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The working principle of Laravel Framework

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

The following describes the operation of the Laravel framework, I hope it will be helpful to you.

Using any framework, it will be easier to apply if you understand the principle of the framework.

I. Life cycle

1. Entry file:

All request entries of the Laravel framework enter the / public/index.php file uniformly, and the request points to the file through Ngxin/Apache.

The index.php file is the entry for loading other files, and there is not much code itself. The index.php file is loaded into the auto-load configuration produced through Composer, and then the application instance is obtained from bootstrap/app.php to create a service container.

2.Http/Console kernel

Then, the request is sent to the HTTP kernel or the Console kernel, depending on the type of application request (described in the next article). These two cores are the central processors that all requests must go through.

The HTTP kernel of App\ Http\ Kernel is described below:

The HTTP kernel inherits from the Illuminate\ Foundation\ Http\ Kernel class, which defines an array of bootstrappers whose classes run before the request is executed. Bootstrappers configures error handling, logging, detection of the application environment, and other tasks that need to be processed before the request is processed.

The HTTP kernel also defines that HTTP middleware is needed before request processing. The middleware handles the reading and writing of HTTP sessions, determines whether the application is in maintenance mode, verifies CSRF tokens (to prevent CSRF attacks) and so on.

The HTTP kernel tag method handle: gets a Request, returns a Response, enters a HTTP request, and returns a HTTP response.

3. Service provider

The kernel startup loads the service provider for the application, which is configured in the providers array of the config/app.php configuration file. After the service provider is registered, the boot method is called.

The service provider is responsible for starting all components of the framework, such as databases, queues, validators, routing components, and so on. Because they launch and configure all the features provided by the framework, the service provider is the most important part of the entire Laravel startup process.

"delay" provider: that is, most of the services in the providers array are loaded only when the actual services provided are required.

4. Distribute request

Once the application is started and all service providers are registered, the Request will be handed over to the router for distribution, and the router will distribute the request to the route or controller, running all routing-specified middleware at the same time.

II. Service provider

Service provision is the key part of starting Laravel, the application instance is created, the service provider is registered, and the application after the request is started is processed.

It is stored in the app/Providers directory by default.

"PHP7 Advanced to Architecture-Laravel/Redis/Swoole/ highly concurrent distributed [six Star Education]" from the core principle of TP5/Laravel framework, to PHP performance optimization, to swoole network communication engine, micro-service architecture, large-scale commercial enterprise project practice, from artificial intelligence technology to highly concurrent distributed architecture, follow teachers to solve the problems of high-paid employment and entrepreneurship.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report