Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Laravel × レイヤードアーキテクチャをやってみている話 / Trying Larave...
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Shohei Okada
May 30, 2018
Programming
490
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
380
たった 1 枚の PHP ファイルで実装する MCP サーバ / MCP Server with Vanilla PHP
okashoi
1
1.1k
どうして手を動かすよりもチーム内のコードレビューを優先するべきなのか
okashoi
3
2.4k
パスワードのハッシュ、ソルトってなに? - What is hash and salt for password?
okashoi
3
450
設計の考え方 - インターフェースと腐敗防止層編 #phpconfuk / Interface and Anti Corruption Layer
okashoi
11
6.6k
"config" ってなんだ? / What is "config"?
okashoi
0
2k
ファイル先頭の use の意味、説明できますか? 〜PHP の namespace と autoloading の関係を正しく理解しよう〜 / namespace and autoloading in php
okashoi
4
2.3k
MySQL のインデックスの種類をおさらいしよう! / overviewing indexes in MySQL
okashoi
0
1.5k
PHP における静的解析(あるいはそもそも静的解析とは) / #phpcondo_yasai static analysis for PHP
okashoi
1
1.5k
Other Decks in Programming
See All in Programming
Streamlitで実現する自然言語データアプリ開発
ayumu_yamaguchi
1
320
選挙速報を多くのユーザーへ 届ける Live Activities 設計
hamayokokuririn
0
160
アクセシビリティから考える情報設計
high_g_engineer
0
400
AI が書く Go コードの品質を劇的に向上させる Linter: “declscope”
mpyw
0
400
モデルのリファクタリングが難しいと思ったら、そもそも複雑だったのはビジネス仕様だった ? / is-the-business-domain-the-real-complexity
hatsu38
0
390
すこし踏み込む CancellationToken
htkym
2
1k
IBM Bob Dojo #1 仕様駆動開発入門
oniak3ibm
PRO
0
220
Vue Fes Japan 2026 タイムテーブル徹底解説
448jp
1
510
The Good Stuff, Not the Slop: Engineering High-Quality Android Apps with Modern AI Tooling
danybony
1
260
速く作れる。その次は、速く確かめられる開発へ 〜AIネイティブ開発を支える、Shift Down〜 / Can build fast. Next, moving to development where we can verify fast.
rkaga
6
4.6k
海上で動くGoサーバー: goroutineとchannelでさばく航行データストリーム
atsuki_seo
0
930
UPDATE をやめる — EF Core でマスタをバージョン管理する
panda728
PRO
0
620
Featured
See All Featured
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
250
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
540
Heart Work Chapter 1 - Part 1
lfama
PRO
10
36k
Exploring anti-patterns in Rails
aemeredith
4
510
Building Applications with DynamoDB
mza
96
7.2k
Typedesign – Prime Four
hannesfritz
42
3.2k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
290
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
2k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
18k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
370
Google's AI Overviews - The New Search
badams
0
1.6k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
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 これから