PHP/Laravel

[LifeCycle] 라라벨 Public/index.php

DSeung 2021. 3. 3. 13:26

라라벨 애플리케이션은

아파치 .htaccess 파일이나 Nginx의 서버 설정 같은 웹 서버의 설정을 가지고 있는데

이 설정은 url에 상관없이 모든 앱의 요청을 가로채서 public/index.php로 보냅니다.

 

즉 모든 요청에 대한 시작점은 pulbic/index.php 입니다.

 


Public/index.php 의 주요 주요 기능

  • 모든 의존성을 등록해주는 컴포저 오토로드 파일을 불러옵니다.
require __DIR__.'/../vendor/autoload.php';

 

  • 애플리케이션의 컨테이너를 만들어주고 핵심 서비스를 등록해줍니다, 또한 커널 인스턴스를 만들어 사용자의 보내는 Request 객체의 인스턴스를 만들어 커널로 넘기고 커널은 일루네이트 Response 객체를 클라이언트(주로 브라우저)에 반환하고 종료합니다.
$app = require_once __DIR__.'/../bootstrap/app.php';

$kernel = $app->make(Kernel::class);

$response = tap($kernel->handle(
    $request = Request::capture()
))->send();

$kernel->terminate($request, $response);

 

참고 서적

www.hanbit.co.kr/store/books/look.php?p_code=B8468875652

반응형