laravel 프레임 워 크 실행 절차 와 원리 에 대한 간단 한 분석
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()
);
2.app.php 에 들 어가 기
$app = new Illuminate\Foundation\Application(
$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
);
$app->singleton(
Illuminate\Contracts\Http\Kernel::class,
App\Http\Kernel::class
);
응용 프로그램 클래스 바 인 딩 기본 클래스 용기Kernel 클래스 실행 경로 배포 로드 컨트롤 러 등 작업
3.Kernel.php 진입
// ,
protected $middleware = [];
// ,
protected $middlewareGroups = [];
// ,
protected $routeMiddleware = [];
//
protected $middlewarePriority = [];
kernel 클래스 계승 Illuminate\Foundation\Http\\Kernel 클래스4.Illuminate\Foundation\Http\\Kernel 클래스 에 들 어가 기
//http , X-HTTP-METHOD-OVERRIDE , , , post
$request->enableHttpMethodParameterOverride();
// / 。
$response = $this->sendRequestThroughRouter($request);
// :
$this->app['events']->dispatch(
new Events\RequestHandled($request, $response)
);
return $response;
sendRequestThrough Router 에 들 어 가 는 방법
//
$this->app->instance('request', $request);
// facade
Facade::clearResolvedInstance('request');
// protected $bootstrappers = [];
$this->bootstrap();
// , ,aop
return (new Pipeline($this->app))
//
->send($request)
// 。
// shouldSkipMiddleware ,$this->make('middleware.disable') true
// $this->bound('middleware.disable') true , ?
->through($this->app->shouldSkipMiddleware() ? [] : $this->middleware)
// ,
->then($this->dispatchToRouter());
dispatchToRouter 경로 에 들 어가 배포 하고 최종 적 으로 경로 류 에서 dispatch 실행 경로 에 들 어가 주입 을 실현 합 니 다.
$this->router->dispatch($request);
반사 원 리 를 이용 하여 Illuminate\Container\\Container 류 에 의존 하 는 것 을 실현 합 니 다.
public function make($abstract, array $parameters = []){
return $this->resolve($abstract, $parameters);
}
public function build($concrete)
// build
$reflector = new ReflectionClass($concrete);
의존 주입 은$parameter->getClass()를 통 해 어떤 종류 인지 알 수 있 습 니 다.
class Demo{
public function store(Request $req333, $abc){
}
}
class Request{}
$method = new ReflectionMethod('Demo', 'store');
foreach ($method->getParameters() as $parameter) {
//
$param_type = $param->getClass(); //
$param_value = $param->getName(); //
if ($param_type) {
//
$avgs[] = $app[$param_type->name];
}
}
$reflect->invokeArgs($app['demo'], $avgs);
X-HTTP-METHOD-OVERRIDE 는 laravel 의 요청 을 덮어 쓸 수 있 습 니 다.예 를 들 어 restful 요청,put delete 등 특수 한 요청 을 수행 할 수 있 습 니 다.Laravel 관련 내용 에 관심 이 있 는 독자 들 은 본 사이트 의 주 제 를 볼 수 있다.
본 고 는 Laravel 프레임 워 크 를 바탕 으로 하 는 PHP 프로 그래 밍 에 도움 이 되 기 를 바 랍 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Laravel - 변환된 유효성 검사 규칙으로 API 요청 제공동적 콘텐츠를 위해 API를 통해 Laravel CMS에 연결하는 모바일 앱(또는 웹사이트) 구축을 고려하십시오. 이제 앱은 CMS에서 번역된 콘텐츠를 받을 것으로 예상되는 다국어 앱이 될 수 있습니다. 일반적으로 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.