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
Shohei Okada
May 30, 2018
Programming
500
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
400
たった 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.6k
Other Decks in Programming
See All in Programming
Jetpack Compose Mechanisms
skydoves
2
660
SalesForceを内製化!? ~ HR事業を支える顧客管理基盤のインフラを大公開 ~
oku053
0
160
JRuby: Past, Present, and Future
headius
0
230
すこし踏み込む CancellationToken
htkym
2
1.7k
パズルゲームの作り方 / how to make puzzle games
kaityo256
PRO
2
280
Kubernetes祭り #2 OP/ED
bells17
0
110
SREの越境 / SRE Collaboration
y0hgi
2
300
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
680
AI が書く Go コードの品質を劇的に向上させる Linter: “declscope”
mpyw
0
490
Domain-Driven Transformation
hschwentner
2
2.3k
GemmaをJevのように使ってみる / Use Gemma like Jev
kishida
5
740
CodeRabbitの効果検証と過ごしてみた3ヶ月
armondando
0
200
Featured
See All Featured
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3.2k
BBQ
matthewcrist
90
10k
Testing 201, or: Great Expectations
jmmastey
46
8.3k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
320
Facilitating Awesome Meetings
lara
57
7.2k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.8k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
58k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Abbi's Birthday
coloredviolet
4
10k
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 これから