SlideShare une entreprise Scribd logo
1  sur  21
라라벨 Request LifeCyle
2017.07.31 이호진 infohojin@naver.com
직접 PHP를 통하여 웹페이지를 개발을 하다가 프레임워크를 처음 접할때 프레임워크를 정확하게 이
해하고 시작하는 것은 앞으로서 개발을 하는데 매우 유용합니다.
라라벨 스터디 : 이호진 infohojin@naver.com
라라벨 Request 라라벨의 동작방식
Apache / Nginx 와 웹서버들은 웹서비스의 초기 시작포인트를 설정합니다. 통상적으로
문서폴더의 index 이름을 가진 파일로 지정을 합니다.
1. 첫번째
라라벨 어플리케이션의 모든 요청에 대한 시작점은 public/index.php 파일입니다.
모든 요청들의 시작은 index.php 파일 입니다.
라라벨 스터디 : 이호진 infohojin@naver.com
Index.php 파일 라라벨의 동작방식
라라벨의 시작포인트인 index.php 파일은 public 폴더 안에 있습니다.
Index.php 파일은 매우 간결하게 작성이 되어 있습니다. 주로 프레임워크를 시작하고 각종 클래스나 파일들
을 로딩하는 동작들을 합니다.
① Index.php 파일은 패키지의존성 관리 도구
인 컴포저가 생성한 오토로더를 정의합니다.
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels great to relax.
|
*/
require __DIR__.'/../bootstrap/autoload.php';
/*
|--------------------------------------------------------------------------
| Register The Composer Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader
| for our application. We just need to utilize it! We'll require it
| into the script here so we do not have to manually load any of
| our application's PHP classes. It just feels great to relax.
|
*/
require __DIR__.'/../vendor/autoload.php';
bootstrap/autoload.php
bootstrap/autoload.php 파일은 컴포저에서
제공하는 오토로드를 다시 호출하는 형태로
되어 있습니다.
public/index.php
라라벨 스터디 : 이호진 infohojin@naver.com
Index.php 파일 라라벨의 동작방식
라라벨 처음 index.php 에서 호출하는 bootstrap/autoload.php 파일안에는 컴포저 오토로드 파일을 전처리
파일결합을 하기전에 라라벨의 시간을 측정할 수 있는시작 시간을 define() 함수를 이용하여 상수 형태로 저
장을 합니다.
define('LARAVEL_START', microtime(true));
② 라라벨의 핵심기능인 bootstrap/app.php
에서 라라벨 인스턴스를 가지고 옵니다.
/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/
$app = require_once __DIR__.'/../bootstrap/app.php';
public/index.php
라라벨 스터디 : 이호진 infohojin@naver.com
Index.php 파일 라라벨의 동작방식
bootstrap/app.php
/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| The first thing we will do is create a new Laravel application instance
| which serves as the "glue" for all the components of Laravel, and is
| the IoC container for the system binding all of the various parts.
|
*/
$app = new IlluminateFoundationApplication(
realpath(__DIR__.'/../')
);
bootstrap/app.php 의 첫번째는 $app 인스턴스의 생성
입니다.
IlluminateFoundationApplication 클래스는 1개의
Container 상속과 ApplicationContract,
HttpKernelInterface 2개의 인터페이스를 적용받습니다.
IlluminateFoundationApplication 클래스는
vendorlaravelframeworksrcIlluminateFoundation 위치
에 있습니다.
라라벨 스터디 : 이호진 infohojin@naver.com
Index.php 파일 라라벨의 동작방식
class Application extends Container implements ApplicationContract, HttpKernelInterface
{
}
vendorlaravelframeworksrcIlluminateContainer
IlluminateFoundationApplication 클래스
라라벨 스터디 : 이호진 infohojin@naver.com
Index.php 파일 라라벨의 동작방식
/*
|--------------------------------------------------------------------------
| Bind Important Interfaces
|--------------------------------------------------------------------------
|
| Next, we need to bind some important interfaces into the container so
| we will be able to resolve them when needed. The kernels serve the
| incoming requests to this application from both the web and CLI.
|
*/
$app->singleton(
IlluminateContractsHttpKernel::class,
AppHttpKernel::class
);
$app->singleton(
IlluminateContractsConsoleKernel::class,
AppConsoleKernel::class
);
$app->singleton(
IlluminateContractsDebugExceptionHandler::class,
AppExceptionsHandler::class
);
bootstrap/app.php
/**
* Register a shared binding in the container.
*
* @param string|array $abstract
* @param Closure|string|null $concrete
* @return void
*/
public function singleton($abstract, $concrete = null)
{
$this->bind($abstract, $concrete, true);
}
vendorlaravelframeworksrcIlluminateContainer
라라벨 스터디 : 이호진 infohojin@naver.com
Index.php 파일 라라벨의 동작방식
③ 라라벨의 첫번째 동작은 서비스 컨테이너
인스턴스의 처리 동작 입니다.
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/
$kernel = $app->make(IlluminateContractsHttpKernel::class);
$response = $kernel->handle(
$request = IlluminateHttpRequest::capture()
);
$response->send();
$kernel->terminate($request, $response);
Once we have the application, we can handle
the incoming request through the kernel, and
send the associated response back to the
client's browser allowing them to enjoy the
creative and wonderful application we have
prepared for them.
라라벨 스터디 : 이호진 infohojin@naver.com
Index.php 파일 라라벨의 동작방식
다음으로 어플리케이션이 시작된 유형에 따라
전송된 요청을 HTTP 커널이나 콘솔 커널
둘 중 하나로 보냅니다.
요청
HTTP 커널
콘솔 커널
이 두가지의 커널은 모든 요청의 흐름 중심에서 작동하게 됩니다.
우리는 대부분 웹서비스를 목표로 하고 있기 때문에 콘솔 커널 보
다는 HTTP 커널 요청 처리를 중심으로 알아봅니다.
HTTP 커널은 app/Http/Kernel.php 에 있습니다.
라라벨 스터디 : 이호진 infohojin@naver.com
2. 두번째 HTTP / Console 커널 라라벨의 동작방식
이 시작 코드들은 에러 처리, 로그 설정, 어플리케이션
동작 환경의 감지 등 실제로 요청이 처리되기 전에
수행해야 되는 작업들을 의미합니다.
HTTP 커널은 IlluminateFoundationHttpKernel
클래스를 상속 받습니다.
요청을 실행하기 전에 처리되는 bootstrappers (시작
코드)의 배열을 정의하고 있습니다.
HTTP 커널은 요청을 처리하기 위한 미들웨어들
을 배열 형태로 설정되어 있습니다.
라라벨 스터디 : 이호진 infohojin@naver.com
2. 두번째 HTTP / Console 커널 라라벨의 동작방식
HTTP 커널은 요청된 처리를 하기전에 사전 또는 사후에 동작할 미들웨어를 배열로 정의합니다.
/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array
*/
protected $middleware = [
IlluminateFoundationHttpMiddlewareCheckForMaintenanceMode::class,
IlluminateFoundationHttpMiddlewareValidatePostSize::class,
AppHttpMiddlewareTrimStrings::class,
IlluminateFoundationHttpMiddlewareConvertEmptyStringsToNull::class,
];
이 미들웨어들은 HTTP 세션을 읽고/쓰고,
어플리케이션이 유지 관리 모드인지
확인하고, CSRF 토큰을 확인 하는 작업들을
처리합니다.
라라벨 스터디 : 이호진 infohojin@naver.com
2. 두번째 HTTP / Console 커널 라라벨의 동작방식
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
AppHttpMiddlewareEncryptCookies::class,
IlluminateCookieMiddlewareAddQueuedCookiesToResponse::class,
IlluminateSessionMiddlewareStartSession::class,
// IlluminateSessionMiddlewareAuthenticateSession::class,
IlluminateViewMiddlewareShareErrorsFromSession::class,
AppHttpMiddlewareVerifyCsrfToken::class,
IlluminateRoutingMiddlewareSubstituteBindings::class,
],
'api' => [
'throttle:60,1',
'bindings',
],
];
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array
*/
protected $routeMiddleware = [
'auth' => IlluminateAuthMiddlewareAuthenticate::class,
'auth.basic' => IlluminateAuthMiddlewareAuthenticateWithBasicAuth::class,
'bindings' => IlluminateRoutingMiddlewareSubstituteBindings::class,
'can' => IlluminateAuthMiddlewareAuthorize::class,
'guest' => AppHttpMiddlewareRedirectIfAuthenticated::class,
'throttle' => IlluminateRoutingMiddlewareThrottleRequests::class,
];
HTTP 커널의 handle 메소드의 사용법은 매우 간단합니다.
단순하게는 Request 를 받고 Response를 반환합니다
커널을 어플리케이션 전체를 나타내는 하나의 큰
블랙 박스라고 생각해봅시다. HTTP 요청이 입력되면
HTTP 응답이 반환됩니다
라라벨 스터디 : 이호진 infohojin@naver.com
2. 두번째 HTTP / Console 커널 라라벨의 동작방식
커널 부팅(부트스트래핑) 과정의 가장 중요한 것 중
의 하나는 어플리케이션의 서비스 프로바이더를 로
딩하는 것입니다.
어플리케이션의 모든 서비스 프로바이더
는 config/app.php 파일의 providers 배열에 설정되
어 있습니다.
/*
|--------------------------------------------------------------------------
| Autoloaded Service Providers
|--------------------------------------------------------------------------
|
| The service providers listed here will be automatically loaded on the
| request to your application. Feel free to add your own services to
| this array to grant expanded functionality to your applications.
|
*/
'providers' => [
/*
* Laravel Framework Service Providers...
*/
/*
* Package Service Providers...
*/
/*
* Application Service Providers...
*/
],
라라벨 스터디 : 이호진 infohojin@naver.com
2. 두번째 서비스 프로바이더 라라벨의 동작방식
/*
* Laravel Framework Service Providers...
*/
IlluminateAuthAuthServiceProvider::class,
IlluminateBroadcastingBroadcastServiceProvider::class,
IlluminateBusBusServiceProvider::class,
IlluminateCacheCacheServiceProvider::class,
IlluminateFoundationProvidersConsoleSupportServiceProvider::class,
IlluminateCookieCookieServiceProvider::class,
IlluminateDatabaseDatabaseServiceProvider::class,
IlluminateEncryptionEncryptionServiceProvider::class,
IlluminateFilesystemFilesystemServiceProvider::class,
IlluminateFoundationProvidersFoundationServiceProvider::class,
IlluminateHashingHashServiceProvider::class,
IlluminateMailMailServiceProvider::class,
IlluminateNotificationsNotificationServiceProvider::class,
IlluminatePaginationPaginationServiceProvider::class,
IlluminatePipelinePipelineServiceProvider::class,
IlluminateQueueQueueServiceProvider::class,
IlluminateRedisRedisServiceProvider::class,
IlluminateAuthPasswordsPasswordResetServiceProvider::class,
IlluminateSessionSessionServiceProvider::class,
IlluminateTranslationTranslationServiceProvider::class,
IlluminateValidationValidationServiceProvider::class,
IlluminateViewViewServiceProvider::class,
/*
* Package Service Providers...
*/
LaravelTinkerTinkerServiceProvider::class,
/*
* Application Service Providers...
*/
AppProvidersAppServiceProvider::class,
AppProvidersAuthServiceProvider::class,
// AppProvidersBroadcastServiceProvider::class,
AppProvidersEventServiceProvider::class,
AppProvidersRouteServiceProvider::class,
Service Providers
라라벨 스터디 : 이호진 infohojin@naver.com
2. 두번째 서비스 프로바이더 라라벨의 동작방식
프레임워크가 제공하는 모든 기능을 초기화 하고 설정하는 것으로, 서비스 프로바이더는 라라벨의
부팅(부트스트래핑) 과정에서 가장 중요한 기능이라고 할 수 있습니다.
먼저, 모든 서비스
프로바이더의 register 메소드가
호출됩니다.
이후에 등록 된 모든 서비스 프로바이더
의 boot 메소드가 호출되어 집니다.
서비스 프로바이더는 프레임워크의 데이터베이스, 큐, validation,
라우팅 컴포넌트와 같은 다양한 컴포넌트의 부트스트래핑(부팅
과 같은 기초 작업들)의 처리를 책임집니다.
라라벨 스터디 : 이호진 infohojin@naver.com
2. 두번째 서비스 프로바이더 라라벨의 동작방식
Request는
라우터 처리를 위해서 전달
요청 처리-디스패칭
라우터는 라우팅 또는 컨트롤러로 요청-request을 전달할
뿐만 아니라, 임의의 특정 라우트에 지정된 미들웨어도 실
행합니다.
어플리케이션이 부팅(부트스트래핑)되고
모든 서비스 프로바이더가 등록된 후
Request
컨트롤러 미들웨어
라라벨 스터디 : 이호진 infohojin@naver.com
2. 두번째 서비스 프로바이더 라라벨의 동작방식
Laravel 요청 사이클은 아주 간단합니다.
② 라우트에 대한 응답은 브라우져로
다시 전송되고 화면에 표시됩니다.
① 어플리케이션에 요청이 들어오면
적절한 라우트나 컨트롤러로 전달됩니다. 라우트
컨트롤러
Request
라라벨 스터디 : 이호진 infohojin@naver.com
2. 두번째 서비스 프로바이더 라라벨의 동작방식
2. 두번째 서비스 프로바이더
서비스 프로바이더는 라라벨 어플리케이션의 부팅(부트스트래핑) 단계의 주요한
핵심입니다.
어플리케이션의 인스턴스가 생성되고, 서비스 프로바이더가 등록된후 부트스트래
핑 과정을 마친 프로그램이 요청을 처리합니다.
라라벨 어플리케이션이 어떻게 구성되어 있는지, 서비스 프로바이더를 통
해 부트스트랩되는 과정을 구체적으로 이해하는 것은 매우 중요합니다.
사용자 어플리케이션을 위한 기본 서비스 프로바이더는
app/Providers 디렉토리에 있습니다.
라라벨 스터디 : 이호진 infohojin@naver.com
라라벨의 동작방식
이 프로바이더는 여러분의 고유한 부트스트래핑과
서비스 컨테이너 바인딩 코드를 추가하기 위한
곳입니다.
기본적으로 AppServiceProvider 는 거의 비어 있습니다.
물론 보다 큰 어플리케이션의 경우, 보다 세부적인 유형으
로 구분된 종류별로 서비스 프로바이더를 만들 수도 있습
니다.
라라벨 스터디 : 이호진 infohojin@naver.com
2. 두번째 서비스 프로바이더 라라벨의 동작방식
라라벨 스터디 : 이호진 infohojin@naver.com
라라벨의 동작방식
감사합니다.

Contenu connexe

Similaire à Laravel 06.Request LifeCyle

04.실행환경 교육교재(화면처리)
04.실행환경 교육교재(화면처리)04.실행환경 교육교재(화면처리)
04.실행환경 교육교재(화면처리)Hankyo
 
XECon2015 :: [2-1] 정광섭 - 처음 시작하는 laravel
XECon2015 :: [2-1] 정광섭 - 처음 시작하는 laravelXECon2015 :: [2-1] 정광섭 - 처음 시작하는 laravel
XECon2015 :: [2-1] 정광섭 - 처음 시작하는 laravelXpressEngine
 
처음 시작하는 라라벨
처음 시작하는 라라벨처음 시작하는 라라벨
처음 시작하는 라라벨KwangSeob Jeong
 
Catalyst Framework 살펴보기
Catalyst Framework 살펴보기Catalyst Framework 살펴보기
Catalyst Framework 살펴보기corund
 
#22.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#22.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...#22.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#22.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...탑크리에듀(구로디지털단지역3번출구 2분거리)
 
[Hello world 오픈세미나]open api client개발
[Hello world 오픈세미나]open api client개발[Hello world 오픈세미나]open api client개발
[Hello world 오픈세미나]open api client개발NAVER D2
 
Application Monitoring 신규 기능 소개 (서영일)
Application Monitoring 신규 기능 소개 (서영일)Application Monitoring 신규 기능 소개 (서영일)
Application Monitoring 신규 기능 소개 (서영일)WhaTap Labs
 
Laravel 로 배우는 서버사이드 #2
Laravel 로 배우는 서버사이드 #2Laravel 로 배우는 서버사이드 #2
Laravel 로 배우는 서버사이드 #2성일 한
 
Apache 핵심 프로젝트 camel 엿보기
Apache 핵심 프로젝트 camel 엿보기Apache 핵심 프로젝트 camel 엿보기
Apache 핵심 프로젝트 camel 엿보기Hwang Sun Oh Kelly
 
Design pattern 4
Design pattern 4Design pattern 4
Design pattern 4Daniel Lim
 
스프링군살없이세팅하기(The way to setting the Spring framework for web.)
스프링군살없이세팅하기(The way to setting the Spring framework for web.)스프링군살없이세팅하기(The way to setting the Spring framework for web.)
스프링군살없이세팅하기(The way to setting the Spring framework for web.)EunChul Shin
 
Angular 2 rc5 조사
Angular 2 rc5 조사Angular 2 rc5 조사
Angular 2 rc5 조사Rjs Ryu
 
How to build a web server on Linux.
How to build a web server on Linux.How to build a web server on Linux.
How to build a web server on Linux.은석 김은석
 
Oracle Application Performance Monitoring Cloud Service 소개
Oracle Application Performance Monitoring Cloud Service 소개Oracle Application Performance Monitoring Cloud Service 소개
Oracle Application Performance Monitoring Cloud Service 소개Mee Nam Lee
 
JCO 11th 클라우드 환경에서 Java EE 운영 환경 구축하기
JCO 11th 클라우드 환경에서 Java EE 운영 환경 구축하기JCO 11th 클라우드 환경에서 Java EE 운영 환경 구축하기
JCO 11th 클라우드 환경에서 Java EE 운영 환경 구축하기Ted Won
 
톰캣 운영 노하우
톰캣 운영 노하우톰캣 운영 노하우
톰캣 운영 노하우jieunsys
 

Similaire à Laravel 06.Request LifeCyle (20)

04.실행환경 교육교재(화면처리)
04.실행환경 교육교재(화면처리)04.실행환경 교육교재(화면처리)
04.실행환경 교육교재(화면처리)
 
RHAMT 소개
RHAMT 소개RHAMT 소개
RHAMT 소개
 
(스프링프레임워크 강좌)스프링부트개요 및 HelloWorld 따라하기
(스프링프레임워크 강좌)스프링부트개요 및 HelloWorld 따라하기(스프링프레임워크 강좌)스프링부트개요 및 HelloWorld 따라하기
(스프링프레임워크 강좌)스프링부트개요 및 HelloWorld 따라하기
 
XECon2015 :: [2-1] 정광섭 - 처음 시작하는 laravel
XECon2015 :: [2-1] 정광섭 - 처음 시작하는 laravelXECon2015 :: [2-1] 정광섭 - 처음 시작하는 laravel
XECon2015 :: [2-1] 정광섭 - 처음 시작하는 laravel
 
처음 시작하는 라라벨
처음 시작하는 라라벨처음 시작하는 라라벨
처음 시작하는 라라벨
 
Catalyst Framework 살펴보기
Catalyst Framework 살펴보기Catalyst Framework 살펴보기
Catalyst Framework 살펴보기
 
#22.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#22.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...#22.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#22.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
 
[Hello world 오픈세미나]open api client개발
[Hello world 오픈세미나]open api client개발[Hello world 오픈세미나]open api client개발
[Hello world 오픈세미나]open api client개발
 
5.Spring IoC&DI(DI와 관련된 어노테이션)
5.Spring IoC&DI(DI와 관련된 어노테이션)5.Spring IoC&DI(DI와 관련된 어노테이션)
5.Spring IoC&DI(DI와 관련된 어노테이션)
 
Application Monitoring 신규 기능 소개 (서영일)
Application Monitoring 신규 기능 소개 (서영일)Application Monitoring 신규 기능 소개 (서영일)
Application Monitoring 신규 기능 소개 (서영일)
 
Laravel 로 배우는 서버사이드 #2
Laravel 로 배우는 서버사이드 #2Laravel 로 배우는 서버사이드 #2
Laravel 로 배우는 서버사이드 #2
 
Apache 핵심 프로젝트 camel 엿보기
Apache 핵심 프로젝트 camel 엿보기Apache 핵심 프로젝트 camel 엿보기
Apache 핵심 프로젝트 camel 엿보기
 
Design pattern 4
Design pattern 4Design pattern 4
Design pattern 4
 
스프링군살없이세팅하기(The way to setting the Spring framework for web.)
스프링군살없이세팅하기(The way to setting the Spring framework for web.)스프링군살없이세팅하기(The way to setting the Spring framework for web.)
스프링군살없이세팅하기(The way to setting the Spring framework for web.)
 
Angular 2 rc5 조사
Angular 2 rc5 조사Angular 2 rc5 조사
Angular 2 rc5 조사
 
okspring3x
okspring3xokspring3x
okspring3x
 
How to build a web server on Linux.
How to build a web server on Linux.How to build a web server on Linux.
How to build a web server on Linux.
 
Oracle Application Performance Monitoring Cloud Service 소개
Oracle Application Performance Monitoring Cloud Service 소개Oracle Application Performance Monitoring Cloud Service 소개
Oracle Application Performance Monitoring Cloud Service 소개
 
JCO 11th 클라우드 환경에서 Java EE 운영 환경 구축하기
JCO 11th 클라우드 환경에서 Java EE 운영 환경 구축하기JCO 11th 클라우드 환경에서 Java EE 운영 환경 구축하기
JCO 11th 클라우드 환경에서 Java EE 운영 환경 구축하기
 
톰캣 운영 노하우
톰캣 운영 노하우톰캣 운영 노하우
톰캣 운영 노하우
 

Laravel 06.Request LifeCyle

  • 1. 라라벨 Request LifeCyle 2017.07.31 이호진 infohojin@naver.com
  • 2. 직접 PHP를 통하여 웹페이지를 개발을 하다가 프레임워크를 처음 접할때 프레임워크를 정확하게 이 해하고 시작하는 것은 앞으로서 개발을 하는데 매우 유용합니다. 라라벨 스터디 : 이호진 infohojin@naver.com 라라벨 Request 라라벨의 동작방식
  • 3. Apache / Nginx 와 웹서버들은 웹서비스의 초기 시작포인트를 설정합니다. 통상적으로 문서폴더의 index 이름을 가진 파일로 지정을 합니다. 1. 첫번째 라라벨 어플리케이션의 모든 요청에 대한 시작점은 public/index.php 파일입니다. 모든 요청들의 시작은 index.php 파일 입니다. 라라벨 스터디 : 이호진 infohojin@naver.com Index.php 파일 라라벨의 동작방식
  • 4. 라라벨의 시작포인트인 index.php 파일은 public 폴더 안에 있습니다. Index.php 파일은 매우 간결하게 작성이 되어 있습니다. 주로 프레임워크를 시작하고 각종 클래스나 파일들 을 로딩하는 동작들을 합니다. ① Index.php 파일은 패키지의존성 관리 도구 인 컴포저가 생성한 오토로더를 정의합니다. /* |-------------------------------------------------------------------------- | Register The Auto Loader |-------------------------------------------------------------------------- | | Composer provides a convenient, automatically generated class loader for | our application. We just need to utilize it! We'll simply require it | into the script here so that we don't have to worry about manual | loading any of our classes later on. It feels great to relax. | */ require __DIR__.'/../bootstrap/autoload.php'; /* |-------------------------------------------------------------------------- | Register The Composer Auto Loader |-------------------------------------------------------------------------- | | Composer provides a convenient, automatically generated class loader | for our application. We just need to utilize it! We'll require it | into the script here so we do not have to manually load any of | our application's PHP classes. It just feels great to relax. | */ require __DIR__.'/../vendor/autoload.php'; bootstrap/autoload.php bootstrap/autoload.php 파일은 컴포저에서 제공하는 오토로드를 다시 호출하는 형태로 되어 있습니다. public/index.php 라라벨 스터디 : 이호진 infohojin@naver.com Index.php 파일 라라벨의 동작방식
  • 5. 라라벨 처음 index.php 에서 호출하는 bootstrap/autoload.php 파일안에는 컴포저 오토로드 파일을 전처리 파일결합을 하기전에 라라벨의 시간을 측정할 수 있는시작 시간을 define() 함수를 이용하여 상수 형태로 저 장을 합니다. define('LARAVEL_START', microtime(true)); ② 라라벨의 핵심기능인 bootstrap/app.php 에서 라라벨 인스턴스를 가지고 옵니다. /* |-------------------------------------------------------------------------- | Turn On The Lights |-------------------------------------------------------------------------- | | We need to illuminate PHP development, so let us turn on the lights. | This bootstraps the framework and gets it ready for use, then it | will load up this application so that we can run it and send | the responses back to the browser and delight our users. | */ $app = require_once __DIR__.'/../bootstrap/app.php'; public/index.php 라라벨 스터디 : 이호진 infohojin@naver.com Index.php 파일 라라벨의 동작방식
  • 6. bootstrap/app.php /* |-------------------------------------------------------------------------- | Create The Application |-------------------------------------------------------------------------- | | The first thing we will do is create a new Laravel application instance | which serves as the "glue" for all the components of Laravel, and is | the IoC container for the system binding all of the various parts. | */ $app = new IlluminateFoundationApplication( realpath(__DIR__.'/../') ); bootstrap/app.php 의 첫번째는 $app 인스턴스의 생성 입니다. IlluminateFoundationApplication 클래스는 1개의 Container 상속과 ApplicationContract, HttpKernelInterface 2개의 인터페이스를 적용받습니다. IlluminateFoundationApplication 클래스는 vendorlaravelframeworksrcIlluminateFoundation 위치 에 있습니다. 라라벨 스터디 : 이호진 infohojin@naver.com Index.php 파일 라라벨의 동작방식
  • 7. class Application extends Container implements ApplicationContract, HttpKernelInterface { } vendorlaravelframeworksrcIlluminateContainer IlluminateFoundationApplication 클래스 라라벨 스터디 : 이호진 infohojin@naver.com Index.php 파일 라라벨의 동작방식
  • 8. /* |-------------------------------------------------------------------------- | Bind Important Interfaces |-------------------------------------------------------------------------- | | Next, we need to bind some important interfaces into the container so | we will be able to resolve them when needed. The kernels serve the | incoming requests to this application from both the web and CLI. | */ $app->singleton( IlluminateContractsHttpKernel::class, AppHttpKernel::class ); $app->singleton( IlluminateContractsConsoleKernel::class, AppConsoleKernel::class ); $app->singleton( IlluminateContractsDebugExceptionHandler::class, AppExceptionsHandler::class ); bootstrap/app.php /** * Register a shared binding in the container. * * @param string|array $abstract * @param Closure|string|null $concrete * @return void */ public function singleton($abstract, $concrete = null) { $this->bind($abstract, $concrete, true); } vendorlaravelframeworksrcIlluminateContainer 라라벨 스터디 : 이호진 infohojin@naver.com Index.php 파일 라라벨의 동작방식
  • 9. ③ 라라벨의 첫번째 동작은 서비스 컨테이너 인스턴스의 처리 동작 입니다. /* |-------------------------------------------------------------------------- | Run The Application |-------------------------------------------------------------------------- | | Once we have the application, we can handle the incoming request | through the kernel, and send the associated response back to | the client's browser allowing them to enjoy the creative | and wonderful application we have prepared for them. | */ $kernel = $app->make(IlluminateContractsHttpKernel::class); $response = $kernel->handle( $request = IlluminateHttpRequest::capture() ); $response->send(); $kernel->terminate($request, $response); Once we have the application, we can handle the incoming request through the kernel, and send the associated response back to the client's browser allowing them to enjoy the creative and wonderful application we have prepared for them. 라라벨 스터디 : 이호진 infohojin@naver.com Index.php 파일 라라벨의 동작방식
  • 10. 다음으로 어플리케이션이 시작된 유형에 따라 전송된 요청을 HTTP 커널이나 콘솔 커널 둘 중 하나로 보냅니다. 요청 HTTP 커널 콘솔 커널 이 두가지의 커널은 모든 요청의 흐름 중심에서 작동하게 됩니다. 우리는 대부분 웹서비스를 목표로 하고 있기 때문에 콘솔 커널 보 다는 HTTP 커널 요청 처리를 중심으로 알아봅니다. HTTP 커널은 app/Http/Kernel.php 에 있습니다. 라라벨 스터디 : 이호진 infohojin@naver.com 2. 두번째 HTTP / Console 커널 라라벨의 동작방식
  • 11. 이 시작 코드들은 에러 처리, 로그 설정, 어플리케이션 동작 환경의 감지 등 실제로 요청이 처리되기 전에 수행해야 되는 작업들을 의미합니다. HTTP 커널은 IlluminateFoundationHttpKernel 클래스를 상속 받습니다. 요청을 실행하기 전에 처리되는 bootstrappers (시작 코드)의 배열을 정의하고 있습니다. HTTP 커널은 요청을 처리하기 위한 미들웨어들 을 배열 형태로 설정되어 있습니다. 라라벨 스터디 : 이호진 infohojin@naver.com 2. 두번째 HTTP / Console 커널 라라벨의 동작방식
  • 12. HTTP 커널은 요청된 처리를 하기전에 사전 또는 사후에 동작할 미들웨어를 배열로 정의합니다. /** * The application's global HTTP middleware stack. * * These middleware are run during every request to your application. * * @var array */ protected $middleware = [ IlluminateFoundationHttpMiddlewareCheckForMaintenanceMode::class, IlluminateFoundationHttpMiddlewareValidatePostSize::class, AppHttpMiddlewareTrimStrings::class, IlluminateFoundationHttpMiddlewareConvertEmptyStringsToNull::class, ]; 이 미들웨어들은 HTTP 세션을 읽고/쓰고, 어플리케이션이 유지 관리 모드인지 확인하고, CSRF 토큰을 확인 하는 작업들을 처리합니다. 라라벨 스터디 : 이호진 infohojin@naver.com 2. 두번째 HTTP / Console 커널 라라벨의 동작방식
  • 13. /** * The application's route middleware groups. * * @var array */ protected $middlewareGroups = [ 'web' => [ AppHttpMiddlewareEncryptCookies::class, IlluminateCookieMiddlewareAddQueuedCookiesToResponse::class, IlluminateSessionMiddlewareStartSession::class, // IlluminateSessionMiddlewareAuthenticateSession::class, IlluminateViewMiddlewareShareErrorsFromSession::class, AppHttpMiddlewareVerifyCsrfToken::class, IlluminateRoutingMiddlewareSubstituteBindings::class, ], 'api' => [ 'throttle:60,1', 'bindings', ], ]; /** * The application's route middleware. * * These middleware may be assigned to groups or used individually. * * @var array */ protected $routeMiddleware = [ 'auth' => IlluminateAuthMiddlewareAuthenticate::class, 'auth.basic' => IlluminateAuthMiddlewareAuthenticateWithBasicAuth::class, 'bindings' => IlluminateRoutingMiddlewareSubstituteBindings::class, 'can' => IlluminateAuthMiddlewareAuthorize::class, 'guest' => AppHttpMiddlewareRedirectIfAuthenticated::class, 'throttle' => IlluminateRoutingMiddlewareThrottleRequests::class, ]; HTTP 커널의 handle 메소드의 사용법은 매우 간단합니다. 단순하게는 Request 를 받고 Response를 반환합니다 커널을 어플리케이션 전체를 나타내는 하나의 큰 블랙 박스라고 생각해봅시다. HTTP 요청이 입력되면 HTTP 응답이 반환됩니다 라라벨 스터디 : 이호진 infohojin@naver.com 2. 두번째 HTTP / Console 커널 라라벨의 동작방식
  • 14. 커널 부팅(부트스트래핑) 과정의 가장 중요한 것 중 의 하나는 어플리케이션의 서비스 프로바이더를 로 딩하는 것입니다. 어플리케이션의 모든 서비스 프로바이더 는 config/app.php 파일의 providers 배열에 설정되 어 있습니다. /* |-------------------------------------------------------------------------- | Autoloaded Service Providers |-------------------------------------------------------------------------- | | The service providers listed here will be automatically loaded on the | request to your application. Feel free to add your own services to | this array to grant expanded functionality to your applications. | */ 'providers' => [ /* * Laravel Framework Service Providers... */ /* * Package Service Providers... */ /* * Application Service Providers... */ ], 라라벨 스터디 : 이호진 infohojin@naver.com 2. 두번째 서비스 프로바이더 라라벨의 동작방식
  • 15. /* * Laravel Framework Service Providers... */ IlluminateAuthAuthServiceProvider::class, IlluminateBroadcastingBroadcastServiceProvider::class, IlluminateBusBusServiceProvider::class, IlluminateCacheCacheServiceProvider::class, IlluminateFoundationProvidersConsoleSupportServiceProvider::class, IlluminateCookieCookieServiceProvider::class, IlluminateDatabaseDatabaseServiceProvider::class, IlluminateEncryptionEncryptionServiceProvider::class, IlluminateFilesystemFilesystemServiceProvider::class, IlluminateFoundationProvidersFoundationServiceProvider::class, IlluminateHashingHashServiceProvider::class, IlluminateMailMailServiceProvider::class, IlluminateNotificationsNotificationServiceProvider::class, IlluminatePaginationPaginationServiceProvider::class, IlluminatePipelinePipelineServiceProvider::class, IlluminateQueueQueueServiceProvider::class, IlluminateRedisRedisServiceProvider::class, IlluminateAuthPasswordsPasswordResetServiceProvider::class, IlluminateSessionSessionServiceProvider::class, IlluminateTranslationTranslationServiceProvider::class, IlluminateValidationValidationServiceProvider::class, IlluminateViewViewServiceProvider::class, /* * Package Service Providers... */ LaravelTinkerTinkerServiceProvider::class, /* * Application Service Providers... */ AppProvidersAppServiceProvider::class, AppProvidersAuthServiceProvider::class, // AppProvidersBroadcastServiceProvider::class, AppProvidersEventServiceProvider::class, AppProvidersRouteServiceProvider::class, Service Providers 라라벨 스터디 : 이호진 infohojin@naver.com 2. 두번째 서비스 프로바이더 라라벨의 동작방식
  • 16. 프레임워크가 제공하는 모든 기능을 초기화 하고 설정하는 것으로, 서비스 프로바이더는 라라벨의 부팅(부트스트래핑) 과정에서 가장 중요한 기능이라고 할 수 있습니다. 먼저, 모든 서비스 프로바이더의 register 메소드가 호출됩니다. 이후에 등록 된 모든 서비스 프로바이더 의 boot 메소드가 호출되어 집니다. 서비스 프로바이더는 프레임워크의 데이터베이스, 큐, validation, 라우팅 컴포넌트와 같은 다양한 컴포넌트의 부트스트래핑(부팅 과 같은 기초 작업들)의 처리를 책임집니다. 라라벨 스터디 : 이호진 infohojin@naver.com 2. 두번째 서비스 프로바이더 라라벨의 동작방식
  • 17. Request는 라우터 처리를 위해서 전달 요청 처리-디스패칭 라우터는 라우팅 또는 컨트롤러로 요청-request을 전달할 뿐만 아니라, 임의의 특정 라우트에 지정된 미들웨어도 실 행합니다. 어플리케이션이 부팅(부트스트래핑)되고 모든 서비스 프로바이더가 등록된 후 Request 컨트롤러 미들웨어 라라벨 스터디 : 이호진 infohojin@naver.com 2. 두번째 서비스 프로바이더 라라벨의 동작방식
  • 18. Laravel 요청 사이클은 아주 간단합니다. ② 라우트에 대한 응답은 브라우져로 다시 전송되고 화면에 표시됩니다. ① 어플리케이션에 요청이 들어오면 적절한 라우트나 컨트롤러로 전달됩니다. 라우트 컨트롤러 Request 라라벨 스터디 : 이호진 infohojin@naver.com 2. 두번째 서비스 프로바이더 라라벨의 동작방식
  • 19. 2. 두번째 서비스 프로바이더 서비스 프로바이더는 라라벨 어플리케이션의 부팅(부트스트래핑) 단계의 주요한 핵심입니다. 어플리케이션의 인스턴스가 생성되고, 서비스 프로바이더가 등록된후 부트스트래 핑 과정을 마친 프로그램이 요청을 처리합니다. 라라벨 어플리케이션이 어떻게 구성되어 있는지, 서비스 프로바이더를 통 해 부트스트랩되는 과정을 구체적으로 이해하는 것은 매우 중요합니다. 사용자 어플리케이션을 위한 기본 서비스 프로바이더는 app/Providers 디렉토리에 있습니다. 라라벨 스터디 : 이호진 infohojin@naver.com 라라벨의 동작방식
  • 20. 이 프로바이더는 여러분의 고유한 부트스트래핑과 서비스 컨테이너 바인딩 코드를 추가하기 위한 곳입니다. 기본적으로 AppServiceProvider 는 거의 비어 있습니다. 물론 보다 큰 어플리케이션의 경우, 보다 세부적인 유형으 로 구분된 종류별로 서비스 프로바이더를 만들 수도 있습 니다. 라라벨 스터디 : 이호진 infohojin@naver.com 2. 두번째 서비스 프로바이더 라라벨의 동작방식
  • 21. 라라벨 스터디 : 이호진 infohojin@naver.com 라라벨의 동작방식 감사합니다.