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
choco
April 23, 2019
Programming
1
560
index.phpの処理を追ってみた / Dive into index.php
laravel.osaka #14
choco
April 23, 2019
Tweet
Share
Other Decks in Programming
See All in Programming
DataformでPythonする / dataform-de-python
snhryt
0
170
書き捨てではなく継続開発可能なコードをAIコーディングエージェントで書くために意識していること
shuyakinjo
1
280
「リーダーは意思決定する人」って本当?~ 学びを現場で活かす、リーダー4ヶ月目の試行錯誤 ~
marina1017
0
220
MCP連携で加速するAI駆動開発/mcp integration accelerates ai-driven-development
bpstudy
0
300
新しいモバイルアプリ勉強会(仮)について
uetyo
1
260
AI時代のドメイン駆動設計-DDD実践におけるAI活用のあり方 / ddd-in-ai-era
minodriven
19
7.5k
一人でAIプロダクトを作るための工夫 〜技術選定・開発プロセス編〜 / I want AI to work harder
rkaga
12
2.6k
あなたとJIT, 今すぐアセンブ ル
sisshiki1969
1
670
The State of Fluid (2025)
s2b
0
170
CEDEC 2025 『ゲームにおけるリアルタイム通信への QUIC導入事例の紹介』
segadevtech
3
890
20250808_AIAgent勉強会_ClaudeCodeデータ分析の実運用〜競馬を題材に回収率100%の先を目指すメソッドとは〜
kkakeru
0
170
『リコリス・リコイル』に学ぶ!! 〜キャリア戦略における計画的偶発性理論と変わる勇気の重要性〜
wanko_it
1
530
Featured
See All Featured
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
The Invisible Side of Design
smashingmag
301
51k
Typedesign – Prime Four
hannesfritz
42
2.8k
Optimizing for Happiness
mojombo
379
70k
Git: the NoSQL Database
bkeepers
PRO
431
65k
Art, The Web, and Tiny UX
lynnandtonic
301
21k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3.4k
Rebuilding a faster, lazier Slack
samanthasiow
83
9.1k
Raft: Consensus for Rubyists
vanstee
140
7.1k
A designer walks into a library…
pauljervisheath
207
24k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
161
15k
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, ];
まとめ 実行するまでに膨大な処理が実行されている 簡単ではないですが、読むことは出来ます 学びが多いので全能感が得られる(錯覚)
フレームワークのコードを読もう!