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
Laravel × レイヤードアーキテクチャをやってみている話 / Trying Larave...
Search
Shohei Okada
May 30, 2018
Programming
480
0
Share
Laravel × レイヤードアーキテクチャをやってみている話 / Trying Laravel with layered architecture
2018-05-30 開催の「第126回 PHP勉強会@東京」におけるLT資料です
https://phpstudy.doorkeeper.jp/events/74677
Shohei Okada
May 30, 2018
More Decks by Shohei Okada
See All by Shohei Okada
Symfony + NelmioApiDocBundle を使った スキーマ駆動開発 / Schema Driven Development with NelmioApiDocBundle
okashoi
0
290
たった 1 枚の PHP ファイルで実装する MCP サーバ / MCP Server with Vanilla PHP
okashoi
1
920
どうして手を動かすよりもチーム内のコードレビューを優先するべきなのか
okashoi
3
2.3k
パスワードのハッシュ、ソルトってなに? - What is hash and salt for password?
okashoi
3
390
設計の考え方 - インターフェースと腐敗防止層編 #phpconfuk / Interface and Anti Corruption Layer
okashoi
11
6.1k
"config" ってなんだ? / What is "config"?
okashoi
0
1.8k
ファイル先頭の use の意味、説明できますか? 〜PHP の namespace と autoloading の関係を正しく理解しよう〜 / namespace and autoloading in php
okashoi
4
2.2k
MySQL のインデックスの種類をおさらいしよう! / overviewing indexes in MySQL
okashoi
0
1.3k
PHP における静的解析(あるいはそもそも静的解析とは) / #phpcondo_yasai static analysis for PHP
okashoi
1
1.5k
Other Decks in Programming
See All in Programming
Signal Forms: Beyond the Basics @ngBaguette 2026 in Paris
manfredsteyer
PRO
0
170
RTSPクライアントを自作してみた話
simotin13
0
320
Why Laravel apps break—Mastering the fundamentals to keep them maintainable
kentaroutakeda
1
310
AI時代の仕事技芸論 — ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ
kuranuki
1
520
今さら聞けないCancellationToken
htkym
0
200
CSC307 Lecture 17
javiergs
PRO
0
270
Inside Stream API
skrb
1
380
サーバーレスで作る、動画データ管理基盤
oyasumipants
0
320
AIとRubyの静的型付け
ukin0k0
0
450
LLM Plugin for Node-REDの利用方法と開発について
404background
0
140
Talking to terminals (and how they talk back) (KotlinConf 2026)
jakewharton
PRO
1
160
プラグインで拡張される Context をtype-safe にする難しさと設計判断
kazupon
2
470
Featured
See All Featured
Facilitating Awesome Meetings
lara
57
6.9k
Skip the Path - Find Your Career Trail
mkilby
1
130
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.5k
The Cult of Friendly URLs
andyhume
79
6.9k
First, design no harm
axbom
PRO
2
1.2k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
590
Building Adaptive Systems
keathley
44
3k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.5k
Un-Boring Meetings
codingconduct
0
300
It's Worth the Effort
3n
188
29k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
760
Practical Orchestrator
shlominoach
191
11k
Transcript
Laravel × レイヤードアーキテクチャ をやってみている話 第126回 PHP勉強会@東京
岡田 正平(おかだ しょうへい)@okashoi • 株式会社ウィルゲート 2015年新卒入社 • 開発室 ソリューションユニット 所属
• PHP, Laravel, Vue.js 2 自己紹介 Slides:
• これまで CakePHP で開発してきたが、今回はじめて Laravel を採用 • 技術のキャッチアップ • チームを越えられる人材育成
• 別チームで Laravel をメインに使っていた私 に白羽の矢が立つ 3 背景|とあるチームの新規開発プロジェクト
4 背景|とあるチームの新規開発プロジェクト プロジェクト リーダー 実装者 2 名 インフラ担当 • 別チームから兼任
(稼動の 40%) • 実装方針の策定 • Laravel の知見 伝搬するマン
自分が提供できる価値を考える 「チームはわざわざ『Laravel に切り替える』 というコストを払っている……」
自分が提供できる価値を考える 「なのに Laravel をただの MVC フレームワーク として使うのではメリットが薄いよね?」
「レイヤードアーキテクチャやろう」
8 レイヤードアーキテクチャ? 出典:DDDパターンを活用した Laravelアプリケーション開発/ddd-with-laravel https://speakerdeck.com/shin1x1/ddd-with-laravel (めちゃくちゃ参考にさせてもらってます )
9 レイヤードアーキテクチャ ※DDD(ドメイン駆動設計)と 一緒に語られることが多いが 今回は DDD はやっていない Domain 層はプレーンな PHP
オブジェクトで実装 Laravel 固有の知識・実際のデータ形式の情報などは Application, Infrastructure 層に寄せていく
• Laravel 固有の知識がビジネスロジックに漏れ出ない(=関心の分離) • 例)Eloquent ORM の記述は Infrastructure 層で完結している •
Laravel の ServiceContaner と相性がいい(後述) 10 うまくいっている点
出典:DDDパターンを活用した Laravelアプリケーション開発/ddd-with-laravel by shin1x1 https://speakerdeck.com/shin1x1/ddd-with-laravel?slide=40 11 うまくいっている点|Laravel との相性の良さ
• ServiceProvider 内(UserImageRepository は interface) • 利用箇所(環境に依存しないコードになる) • DI になっているのでテストも書きやすい!
12 うまくいっている点|Laravel との相性の良さ if (app()->environment('production') || app()->environment('staging')) { // 本番環境・ステージング環境のみ、S3 に保存 $this->app->bind(UserImageRepository::class, S3UserImageRepository::class); } else { // それ以外はローカルファイルストレージに保存 $this->app->bind(UserImageRepository::class, LocalUserImageRepository::class); } public function __construct(UserRepository $userRepository, UserImageRepository $userImageRepository) { $this->userRepository = $userRepository; $this->userImageRepository = $userImageRepository; }
• class 数が多くなるので煩雑に感じがち • 勘所を掴むまでは極端すぎるくらいでもいいかな、とも • うまく集約が使いこなせていない感 • User という
Domain Model のコンストラクタの引数が 26 個に • ユーザ名、性別、プロフィール画像、email などなど…… 13 悩んでいる点
• 今後、ビジネスロジックが増えてきたときに Domain 層に寄せていくようにチームの意識をすり合わせていく • 運用保守も始まったときに考え方が守られるかどうか ➢ 個人が考え、チームで議論できる土台・文化づくり 14 これから