38
app/Http/Controllers/TsubuyakiController.php
lib TsubuyakiCreatedSenderInterface
namespace Lib¥Mail;
interface TsubuyakiCreatedSenderInterface {
public function send(): void;
}
lib/Mail/TsubuyakiCreatedSenderInterface.php
Slide 39
Slide 39 text
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
Slide 40
Slide 40 text
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
Slide 41
Slide 41 text
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
Slide 42
Slide 42 text
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
Slide 43
Slide 43 text
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
45
app/Http/Controllers/TsubuyakiController.php
namespace Lib¥Tsubuyaki;
interface TsubuyakiUseCaseInterface {
public function save(string $text): void;
}
lib/Tsubuyaki/TsubuyakiUseCaseInterface.php
lib TsubuyakiUseCaseInterface
Slide 46
Slide 46 text
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
Slide 47
Slide 47 text
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
Slide 48
Slide 48 text
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