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
「わたしたちのコード」を安定させるためにフレームワークとの距離を保つ / phperkaig...
Search
blue_goheimochi
March 08, 2024
Technology
5
1.7k
「わたしたちのコード」を安定させるために フレームワークとの距離を保つ / phperkaigi2024
PHPerKaigi 2024の登壇資料です。
https://phperkaigi.jp/2024/
blue_goheimochi
March 08, 2024
Tweet
Share
More Decks by blue_goheimochi
See All by blue_goheimochi
コミュニケーションを「パス」のやりとりと捉え大切にしていること / dai-kichijojipm-2024
blue_goheimochi
2
2.4k
「手動オペレーションに定評がある」と言われた私が心がけていること / phpcon_odawara2024
blue_goheimochi
4
1k
芝生の障害対応・メンテナンスについて語る / ya8-2024
blue_goheimochi
1
44
コードを計測することで捉える問題点 / phpcondo2024
blue_goheimochi
4
980
Laravelのコードとわたしたちのコードとの距離を保つ / phpcon2023
blue_goheimochi
1
1.9k
リンケージにおけるアプリケーションコードとの付き合い方とそれを支えるコミュニケーション / drobe_pixiv_linkage-20230905
blue_goheimochi
1
500
推測しないで、計測し、判断する! 〜カイゼンのためのステップ考察〜 / phpconfuk2023
blue_goheimochi
3
2k
iOS, iPadOSにもWeb Pushがきたのでさわってみた
blue_goheimochi
1
410
計測できるレガシーさを捉え、コード改善に対処する / phperkaigi2023
blue_goheimochi
0
1.8k
Other Decks in Technology
See All in Technology
不動産tech Product Night#2_AIことはじめ_GA橋本
takehikohashimoto
0
190
フルカイテン株式会社 採用資料
fullkaiten
0
32k
QAに対する超個人的な解釈 / Personal Take on QA
toma_sm
1
140
Next.js のページ遷移を全力で止める
ypresto
8
3.5k
AIで変わるテスト自動化:最新ツールの多様なアプローチ/ 20240910 Takahiro Kaneyama
shift_evolve
0
250
「認証認可」という体験をデザインする ~Nekko Cloud認証認可基盤計画
logica0419
2
450
Technical Writing Meetup vol.35
soracom
PRO
2
130
Cloud Run と GitHub Template Repository による軽量なアプリケーションプラットフォーム/ #nikkei_tech_talk
nikkei_engineer_recruiting
0
110
「家族アルバム みてね」における運用管理・ オブザーバビリティの全貌 / Overview of Operation Management and Observability in FamilyAlbum
isaoshimizu
4
160
ネットワークだけ隔離されたコンテナ作成デモ / Kichijoji.pm36
tenforward
1
240
JTCや セキュリティチェックリストが夢の跡
nikinusu
1
760
OSTという文化を組織に根付かせてみた
sansantech
PRO
2
400
Featured
See All Featured
Music & Morning Musume
bryan
46
6k
Typedesign – Prime Four
hannesfritz
39
2.3k
Optimising Largest Contentful Paint
csswizardry
31
2.8k
Why Our Code Smells
bkeepers
PRO
334
56k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
166
48k
Statistics for Hackers
jakevdp
794
220k
Designing Experiences People Love
moore
138
23k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2k
Docker and Python
trallard
39
3k
10 Git Anti Patterns You Should be Aware of
lemiorhan
653
58k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.3k
Clear Off the Table
cherdarchuk
91
320k
Transcript
PHPerKaigi 2024 2024.03.08 Yuta Ohashi
/ @blue_goheimochi , , , , PUBG MOBILE,
3 • Laravel • Laravel • •
Laravel
5 Laravel PHP Web • 2010 6 1 • 10
2023 2 • 2 • 2024 3 12 11 • • 2024 •
6 Laravel [ ] Google Trends Laravel Symfony CakePHP
7 Laravel Laravel - 3 - • • • •
• •
Laravel
9 Laravel • Eloquent • Facede • • Artisan •
10 Laravel Route::post('/tsubuyaki', function (Request $request) { $text = $request->text;
$tsubuyaki = new Tsubuyaki; $tsubuyaki->text = $text; $tsubuyaki->save(); return redirect('tsubuyaki/complete'); }); routes/web.php
11 Laravel Route Route::post('/tsubuyaki', function ( ) { }); routes/web.php
12 Laravel Route Route::post('/tsubuyaki', function ( ) { }); routes/web.php
/tsubuyaki
13 Laravel Route Route::post('/tsubuyaki', function ( ) { }); routes/web.php
/tsubuyaki POST
14 Laravel Route Route::post('/tsubuyaki', function ( ) { }); routes/web.php
/tsubuyaki POST function
15 Laravel Dependency Injection Request Request $request $text = $request->text;
routes/web.php
16 Laravel Dependency Injection Request Request $request $text = $request->text;
routes/web.php Request DI
17 Laravel Dependency Injection Request Request $request $text = $request->text;
routes/web.php Request DI <input value= text name= text value= /> $request->text
18 Laravel Eloquent $tsubuyaki = new Tsubuyaki; $tsubuyaki->text = $text;
$tsubuyaki->save(); routes/web.php
19 Laravel Eloquent $tsubuyaki = new Tsubuyaki; $tsubuyaki->text = $text;
$tsubuyaki->save(); routes/web.php Eloquent artisan
20 Laravel Eloquent $tsubuyaki = new Tsubuyaki; $tsubuyaki->text = $text;
$tsubuyaki->save(); routes/web.php $text $tsubuyaki->text text Eloquent artisan
21 Laravel Eloquent $tsubuyaki = new Tsubuyaki; $tsubuyaki->text = $text;
$tsubuyaki->save(); routes/web.php $text $tsubuyaki->text text save() Eloquent artisan
22 Laravel redirect return redirect('tsubuyaki/complete'); routes/web.php
23 Laravel redirect return redirect('tsubuyaki/complete'); routes/web.php
24 Laravel Route::post('/tsubuyaki', function (Request $request) { $text = $request->text;
$tsubuyaki = new Tsubuyaki; $tsubuyaki->text = $text; $tsubuyaki->save(); return redirect('tsubuyaki/complete'); }); routes/web.php
25 Laravel Mailer $mailer $mailer->send(new TsubuyakiCreated()); routes/web.php
26 Laravel Mailer $mailer $mailer->send(new TsubuyakiCreated()); routes/web.php Mailer DI
27 Laravel Mailer $mailer $mailer->send(new TsubuyakiCreated()); routes/web.php Mailer DI Mailable
TsubuyakiCreated artisan
28 Laravel Route::post('/tsubuyaki', function (Request $request, Mailer $mailer) { $text
= $request->text; $tsubuyaki = new Tsubuyaki; $tsubuyaki->text = $text; $tsubuyaki->save(); $mailer->send(new TsubuyakiCreated()); return redirect('tsubuyaki/complete'); }); routes/web.php
29 Laravel Route::post('/tsubuyaki', function (Request $request, Mailer $mailer) { $text
= $request->text; $tsubuyaki = new Tsubuyaki; $tsubuyaki->text = $text; $tsubuyaki->save(); $mailer->send(new TsubuyakiCreated()); return redirect('tsubuyaki/complete'); }); routes/web.php /tsubuyaki POST function <input name= text value= /> $request->text $text $tsubuyaki->text text save() Mailer DI Mailable TsubuyakiCreated artisan Request DI Eloquent artisan
30 Laravel Route::post('/tsubuyaki', function (Request $request, Mailer $mailer) { $text
= $request->text; $tsubuyaki = new Tsubuyaki; $tsubuyaki->text = $text; $tsubuyaki->save(); $mailer->send(new TsubuyakiCreated()); return redirect('tsubuyaki/complete'); }); routes/web.php /tsubuyaki POST function <input name= text value= /> $request->text Eloquent $text $tsubuyaki->text text save() Mailer DI Request DI Mailable TsubuyakiCreated artisan
31 Laravel • • • Laravel Way 1 •
32 Laravel • • • • 範 • Eloquent ActiveRecode
• • • •
フレームワークとわたしたちのコードの 距離を保つために
34 Laravel • • Laravel • Laravel • Laravel •
• • Interface
35 Laravel Laravel
36 class TsubuyakiController extends Controller { public function store(Request $request,
Mailer $mailer): RedirectResponse { $text = $request->text; $tsubuyaki = new Tsubuyaki(); $tsubuyaki->text = $text; $tsubuyaki->save(); $mailer->send(new TsubuyakiCreated()); return redirect('tsubuyaki/complete'); } } app/Http/Controllers/TsubuyakiController.php routes/web.php
37 Mailer $mailer $mailer->send(new TsubuyakiCreated()); app/Http/Controllers/TsubuyakiController.php Illuminate¥Mail¥Mailer
38 app/Http/Controllers/TsubuyakiController.php lib TsubuyakiCreatedSenderInterface namespace Lib¥Mail; interface TsubuyakiCreatedSenderInterface { public
function send(): void; } lib/Mail/TsubuyakiCreatedSenderInterface.php
39 use Lib¥Mail¥TsubuyakiCreatedSenderInterface as SenderInterface; SenderInterface $sender $sender->send(); app/Http/Controllers/TsubuyakiController.php namespace
Lib¥Mail; interface TsubuyakiCreatedSenderInterface { public function send(): void; } lib/Mail/TsubuyakiCreatedSenderInterface.php Interface
40 use Lib¥Mail¥TsubuyakiCreatedSenderInterface as SenderInterface; SenderInterface $sender $sender->send(); app/Http/Controllers/TsubuyakiController.php Interface
Mailer namespace Lib¥Mail; interface TsubuyakiCreatedSenderInterface { public function send(): void; } lib/Mail/TsubuyakiCreatedSenderInterface.php
41 class TsubuyakiCreatedSender implements TsubuyakiCreatedSenderInterface { public function __construct(private readonly
Mailer $mailer) {} public function send(): void { $this->$mailer->send(new TsubuyakiCreated()); } } app/Mail/TsubuyakiCreatedSender.php TsubuyakiCreatedSenderInterface app
42 class TsubuyakiCreatedSender implements TsubuyakiCreatedSenderInterface { public function __construct(private readonly
Mailer $mailer) {} public function send(): void { $this->$mailer->send(new TsubuyakiCreated()); } } app/Mail/TsubuyakiCreatedSender.php class AppServiceProvider extends ServiceProvider { public array $bindings = [ Lib¥Mail¥TsubuyakiCreatedSenderInterface::class => ¥App¥Mail¥TsubuyakiCreatedSender::class, ]; } app/Providers/AppServiceProvider.php
43 use Lib¥Mail¥TsubuyakiCreatedSenderInterface as SenderInterface; class TsubuyakiController extends Controller {
public function store(Request $request, SenderInterface $sender): RedirectResponse { $text = $request->text; $tsubuyaki = new Tsubuyaki(); $tsubuyaki->text = $text; $tsubuyaki->save(); $sender->send(); return redirect('tsubuyaki/complete'); } } app/Http/Controllers/TsubuyakiController.php
44 $tsubuyaki = new Tsubuyaki(); $tsubuyaki->text = $text; $tsubuyaki->save(); app/Http/Controllers/TsubuyakiController.php
Eloquent
45 app/Http/Controllers/TsubuyakiController.php namespace Lib¥Tsubuyaki; interface TsubuyakiUseCaseInterface { public function save(string
$text): void; } lib/Tsubuyaki/TsubuyakiUseCaseInterface.php lib TsubuyakiUseCaseInterface
46 ; use Lib¥Tsubuyaki¥TsubuyakiUseCaseInterface; TsubuyakiUseCaseInterface $useCase $useCase->save($text); app/Http/Controllers/TsubuyakiController.php namespace Lib¥Tsubuyaki;
interface TsubuyakiUseCaseInterface { public function save(string $text): void; } lib/Tsubuyaki/TsubuyakiUseCaseInterface.php Interface Eloquent
47 class TsubuyakiUseCase implements TsubuyakiUseCaseInterface { public function save(string $text):
void { $tsubuyaki = new Tsubuyaki(); $tsubuyaki->text = $text; $tsubuyaki->save(); } } app/Tsubuyaki/TsubuyakiUseCase.php TsubuyakiUseCaseInterface app
48 class TsubuyakiUseCase implements TsubuyakiUseCaseInterface { public function __construct(private readonly
EntityManager $em) {} public function save(string $text): void { $tsubuyaki = new Tsubuyaki(); $tsubuyaki->setText($text); $em->persist($tsubuyaki); $em->flush(); } } app/Tsubuyaki/TsubuyakiUseCase.php Doctrine
49 Interface • • app Laravel • lib Laravel •
Laravel app • lib • • DB
50 1 • lib Doctrine • Doctrine ORM Eloquent •
Doctrine • • Eloquent DB
51 2 1 • • • UseCase Service • •
DI •
52 3 2 • • Mailgun SendGrid • Interface •
MailerResolver • • MailerResolver • • 1
53 • Laravel Way • • PoC • • •
• •
54 • • SOLID etc • • • •
None
56 • Laravel • Laravel PHP • [ ] •
Laravel • Facade Eloquent • • • Interface • •