Upgrade to Pro — share decks privately, control downloads, hide ads and more …

「わたしたちのコード」を安定させるために フレームワークとの距離を保つ / phperkaig...

「わたしたちのコード」を安定させるために フレームワークとの距離を保つ / phperkaigi2024

PHPerKaigi 2024の登壇資料です。
https://phperkaigi.jp/2024/

blue_goheimochi

March 08, 2024
Tweet

More Decks by blue_goheimochi

Other Decks in Technology

Transcript

  1. 5 Laravel PHP Web • 2010 6 1 • 10

    2023 2 • 2 • 2024 3 12 11 • • 2024 •
  2. 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
  3. 17 Laravel Dependency Injection Request Request $request $text = $request->text;

    routes/web.php Request DI <input value= text name= text value= /> $request->text
  4. 19 Laravel Eloquent $tsubuyaki = new Tsubuyaki; $tsubuyaki->text = $text;

    $tsubuyaki->save(); routes/web.php Eloquent artisan
  5. 20 Laravel Eloquent $tsubuyaki = new Tsubuyaki; $tsubuyaki->text = $text;

    $tsubuyaki->save(); routes/web.php $text $tsubuyaki->text text Eloquent artisan
  6. 21 Laravel Eloquent $tsubuyaki = new Tsubuyaki; $tsubuyaki->text = $text;

    $tsubuyaki->save(); routes/web.php $text $tsubuyaki->text text save() Eloquent artisan
  7. 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
  8. 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
  9. 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
  10. 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
  11. 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
  12. 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
  13. 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
  14. 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
  15. 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
  16. 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
  17. 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
  18. 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
  19. 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
  20. 52 3 2 • • Mailgun SendGrid • Interface •

    MailerResolver • • MailerResolver • • 1
  21. 56 • Laravel • Laravel PHP • [ ] •

    Laravel • Facade Eloquent • • • Interface • •