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
技術同人誌をMCP Serverにしてみた
74th
1
450
#QiitaBash MCPのセキュリティ
ryosukedtomita
0
500
関数型まつりレポート for JuliaTokai #22
antimon2
0
160
AIプログラマーDevinは PHPerの夢を見るか?
shinyasaita
1
180
童醫院敏捷轉型的實踐經驗
cclai999
0
210
PicoRuby on Rails
makicamel
2
110
プロダクト志向なエンジニアがもう一歩先の価値を目指すために意識したこと
nealle
0
120
GraphRAGの仕組みまるわかり
tosuri13
8
500
“いい感じ“な定量評価を求めて - Four Keysとアウトカムの間の探求 -
nealle
0
350
なぜ適用するか、移行して理解するClean Architecture 〜構造を超えて設計を継承する〜 / Why Apply, Migrate and Understand Clean Architecture - Inherit Design Beyond Structure
seike460
PRO
1
710
データの民主化を支える、透明性のあるデータ利活用への挑戦 2025-06-25 Database Engineering Meetup#7
y_ken
0
330
生成AIコーディングとの向き合い方、AIと共創するという考え方 / How to deal with generative AI coding and the concept of co-creating with AI
seike460
PRO
1
340
Featured
See All Featured
Java REST API Framework Comparison - PWX 2021
mraible
31
8.7k
Adopting Sorbet at Scale
ufuk
77
9.4k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
Navigating Team Friction
lara
187
15k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
29
9.5k
Docker and Python
trallard
44
3.5k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
45
7.5k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
20
1.3k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
229
22k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
331
22k
Thoughts on Productivity
jonyablonski
69
4.7k
The Straight Up "How To Draw Better" Workshop
denniskardys
234
140k
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, ];
まとめ 実行するまでに膨大な処理が実行されている 簡単ではないですが、読むことは出来ます 学びが多いので全能感が得られる(錯覚)
フレームワークのコードを読もう!