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

What is the execution process of the laravel framework

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly explains the "laravel framework implementation process is how", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "laravel framework implementation process is how" it!

1.index.php

$app = require_once _ _ DIR__.'/../bootstrap/app.php';$kernel = $app- > make (Illuminate\ Contracts\ Http\ Kernel::class); $response = $kernel- > handle ($request = Illuminate\ Http\ Request::capture ())

two。 Enter app.php

$app = new Illuminate\ Foundation\ Application ($_ ENV ['APP_BASE_PATH']?? Dirname (_ _ DIR__); $app- > singleton (Illuminate\ Contracts\ Http\ Kernel::class, App\ Http\ Kernel::class)

The Application class binds the base class to the container

The Kernel class performs operations such as routing, distributing, loading controllers, etc.

3. Enter Kernel.php

/ / Global routing middleware, each execution will execute protected $middleware = []; / / Middleware routing grouping, protected $middlewareGroups = []; / / Middleware alias, which can be used alone or assigned to group protected $routeMiddleware = []; / / Middleware sort protected $middlewarePriority = []

The kernel class inherits the Illuminate\ Foundation\ Http\ Kernel class

4. Go to the Illuminate\ Foundation\ Http\ Kernel class

/ / http method parameter override, that is, if there are parameters in X-HTTP-METHOD-OVERRIDE, follow this. If not, it is post$request- > enableHttpMethodParameterOverride (); / / send the given request through middleware / router. $response = $this- > sendRequestThroughRouter ($request); / / trigger event and call listeners Han Note: trigger Observer $this- > app ['events']-> dispatch (new Events\ RequestHandled ($request, $response)); return $response

Enter the sendRequestThroughRouter method

/ / register the request class to the container $this- > app- > instance ('request', $request); / / remove the shared instance Facade::clearResolvedInstance (' request') from the facade root instance; / / start the bootstrap class protected $bootstrappers = []; the bootstrap classes are all in this array $this- > bootstrap () / / execute the final result through pipe mode, section programming, aop return (new Pipeline ($this- > app)) / / set the object sent through the pipe-> send ($request) / / set the pipe array. / / shouldSkipMiddleware determines whether middleware should be skipped. Setting $this- > make ('middleware.disable') to true / / $this- > bound (' middleware.disable') to true should skip all middleware. What are the benefits of this? -> through ($this- > app- > shouldSkipMiddleware ()? []: $this- > middleware) / / use the final target callback to run the pipeline, and the final result that needs to be run-> then ($this- > dispatchToRouter ())

Enter the dispatchToRouter route distribution, and finally the dispatch in the route class executes the route and implements the injection

$this- > router- > dispatch ($request)

Using reflection principle to implement dependency injection in Illuminate\ Container\ Container class

Public function make ($abstract, array $parameters = []) {return $this- > resolve ($abstract, $parameters);} public function build ($concrete) / / build $reflector = new ReflectionClass ($concrete)

Dependency injection knows what class it is through $parameter- > getClass ()

Class Demo {public function store (Request $req333, $abc) {}} class Request {} $method = new ReflectionMethod ('Demo',' store'); foreach ($method- > getParameters () as $parameter) {/ / get the type of restriction class of parameter $param_type = $param- > getClass (); / / prompt for getting the type of the current injection object $param_value = $param- > getName () / / get the parameter name if ($param_type) {/ / extract the instance in the container from the type restriction name of the class $avgs [] = $app [$param_type- > name];}} $reflect- > invokeArgs ($app ['demo'], $avgs) Thank you for your reading, the above is the content of "what is the implementation process of laravel framework". After the study of this article, I believe you have a deeper understanding of how the implementation process of laravel framework is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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

Development

Wechat

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

12
Report