Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
index.phpの処理を追ってみた / Dive into index.php
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
choco
April 23, 2019
Programming
560
1
Share
index.phpの処理を追ってみた / Dive into index.php
laravel.osaka #14
choco
April 23, 2019
Other Decks in Programming
See All in Programming
Make GenAI Production-Ready with Kubernetes Patterns
bibryam
0
120
CDK Deployのための ”反響定位”
watany
4
750
セグメントとターゲットを意識するプロポーザルの書き方 〜採択の鍵は、誰に刺すかを見極めるマーケティング戦略にある〜
m3m0r7
PRO
0
530
PCOVから学ぶコードカバレッジ #phpcon_odawara
o0h
PRO
0
260
Don't Prompt Harder, Structure Better
kitasuke
0
750
SREに優しいTerraform構成 modulesとstateの組み方
hiyanger
2
120
mruby on C#: From VM Implementation to Game Scripting (RubyKaigi 2026)
hadashia
2
320
AWS re:Invent 2025の少し振り返り + DevOps AgentとBacklogを連携させてみた
satoshi256kbyte
3
160
How We Benchmarked Quarkus: Patterns and anti-patterns
hollycummins
1
140
Laravel Nightwatchの裏側 - Laravel公式Observabilityツールを支える設計と実装
avosalmon
1
330
iOS機能開発のAI環境と起きた変化
ryunakayama
0
180
10 Tips of AWS ~Gen AI on AWS~
licux
5
380
Featured
See All Featured
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
180
ラッコキーワード サービス紹介資料
rakko
1
3M
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
1
350
We Have a Design System, Now What?
morganepeng
55
8.1k
We Are The Robots
honzajavorek
0
210
Making Projects Easy
brettharned
120
6.6k
Ethics towards AI in product and experience design
skipperchong
2
260
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
730
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
62
53k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
27
3.4k
The Cult of Friendly URLs
andyhume
79
6.8k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
160
Transcript
index.php の処理を追ってみた @choco14t 2019/04/23 laravel.osaka #14
About me 増田 雄真(yuma masuda) choco14t(Twitter, GitHub) ブログチョットカイテマス https://choco14t.hatenablog.com works
at 株式会社i-plug Laravel は個人で少し触ったことがある程度
Table of contents index.php bootstrap/app.php Application クラスなどのメソッド コードは5.5 を基にしてます
Q. Laravel の使用頻度 業務でバリバリ使ってます! ちょっと使ったことがあります 全然わからない・PHP 触り始めたばかり etc...
Dive into index.php ......
index.php <?php define('LARAVEL_START', microtime(true)); require __DIR__.'/../vendor/autoload.php'; // 今日話す部分↓↓ $app =
require_once __DIR__.'/../bootstrap/app.php'; $kernel = $app->make( Illuminate\Contracts\Http\Kernel::class ); $response = $kernel->handle( $request = Illuminate\Http\Request::capture() ); // ↑↑ ここまで $response->send(); $kernel->terminate($request, $response);
bootstrap/app.php $app = require_once __DIR__.'/../bootstrap/app.php';
bootstrap/app.php Application のインスタンス生成 サービスプロバイダ エイリアス インスタンス生成 The kernels serve the
incoming requests to this application from both the web and CLI. “ “
<?php $app = new Illuminate\Foundation\Application( realpath(__DIR__.'/../') ); $app->singleton( Illuminate\Contracts\Http\Kernel::class, App\Http\Kernel::class
); $app->singleton( Illuminate\Contracts\Console\Kernel::class, App\Console\Kernel::class ); $app->singleton( Illuminate\Contracts\Debug\ExceptionHandler::class, App\Exceptions\Handler::class ); return $app;
Container::singleton() Container::bind() を呼び出すだけ shared フラグをtrue にしている
Container::bind() public function bind( $abstract, $concrete = null, $shared =
false ) { $this->dropStaleInstances($abstract); if (is_null($concrete)) { $concrete = $abstract; } if (!$concrete instanceof Closure) { $concrete = $this->getClosure( $abstract, $concrete ); }
// 前のスライドの続き $this->bindings[$abstract] = compact( 'concrete', 'shared' ); if ($this->resolved($abstract))
{ $this->rebound($abstract); } }
Application::make() $kernel = $app->make( Illuminate\Contracts\Http\Kernel::class );
Application::make() (あれば)サービスプロバイダの遅延読込 依存オブジェクトの解決
public function make($abstract, array $parameters = []) { $abstract =
$this->getAlias($abstract); if (isset($this->deferredServices[$abstract]) && ! isset($this->instances[$abstract]) ) { $this->loadDeferredProvider($abstract); } // Container::resolve() を実行 return parent::make($abstract, $parameters); }
Container::resolve() 依存オブジェクトの生成 再帰的に依存オブジェクトを生成 Container::make() を再呼び出し
Container::build() 名の通りインスタンス生成 Re ection を使って実現 クラス、インターフェイス、関数、メソッド、そ して拡張モジュールについて リバースエンジニア リングを行うことができます。 https://www.php.net/manual/ja/intro.re
ection. php “ “
Http\Kernel::handle() $response = $kernel->handle( $request = Illuminate\Http\Request::capture() );
Http\Kernel::handle() ブートストラッピング con g facade service provider 対応したルーティングの処理実行 レスポンスの返却
public function handle($request) { try { $request->enableHttpMethodParameterOverride(); $response = $this->sendRequestThroughRouter($request);
} // catch は省略 $this->app['events']->dispatch( new Events\RequestHandled($request, $response) ); return $response; }
Http\Kernel.php // 本来は\Illuminate\Foundation\Bootstrap\ が記述されてます protected $bootstrappers = [ LoadEnvironmentVariables::class, LoadConfiguration::class,
HandleExceptions::class, RegisterFacades::class, RegisterProviders::class, BootProviders::class, ];
まとめ 実行するまでに膨大な処理が実行されている 簡単ではないですが、読むことは出来ます 学びが多いので全能感が得られる(錯覚)
フレームワークのコードを読もう!