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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
choco
April 23, 2019
Programming
570
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
index.phpの処理を追ってみた / Dive into index.php
laravel.osaka #14
choco
April 23, 2019
Other Decks in Programming
See All in Programming
タクシーアプリ『GO』の バックエンド開発のおける AI利活用と若者のすべて
pyama86
3
1.9k
Developing with AI Agents — Codex, Claude Code & Cowork Practical Guide
x5gtrn
PRO
0
1.1k
New "Type" system on PicoRuby
pocke
1
810
運用エージェントは "作る" から "育てる" へ - 記憶と自己進化の3層設計パターン / self-evolving-agents-three-layer-agent-design
gawa
12
3.6k
Lessons from Spec-Driven Development
simas
PRO
0
150
RTSPクライアントを自作してみた話
simotin13
0
520
A2UI という光を覗いてみる
satohjohn
1
120
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
250
脅威をエンジニアリングの糧にして――現場編 / Turning Threats into Engineering Fuel — Field Edition
nrslib
0
270
正しくソフトウェアを作る、前提を疑うための認知の視点 / doubt-premise
minodriven
20
6.4k
Java × distroless で 軽量なコンテナイメージを / Java on Distroless
contour_gara
0
520
軽量Java基盤の設計 DIコンテナに頼らない、長期保守と1秒起動の実現 JJUG CCC 2026 Spring
macha64
0
490
Featured
See All Featured
The browser strikes back
jonoalderson
0
1.2k
Prompt Engineering for Job Search
mfonobong
0
340
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
540
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
380
YesSQL, Process and Tooling at Scale
rocio
174
15k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
200
A Tale of Four Properties
chriscoyier
163
24k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
300
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
390
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, ];
まとめ 実行するまでに膨大な処理が実行されている 簡単ではないですが、読むことは出来ます 学びが多いので全能感が得られる(錯覚)
フレームワークのコードを読もう!