13
Laravel
class Register
{
public function __construct(
private readonly Mailer $mailer,
) {}
public function create(string $name): void
{
// 何らか登録などする処理
// メールの送信
$this->mailer->send(new SayHello($name));
}
}
app/Services/Register.php
Slide 14
Slide 14 text
14
Laravel
class Register
{
public function __construct(
private readonly Mailer $mailer,
) {}
public function create(string $name): void
{
// 何らか登録などする処理
// メールの送信
$this->mailer->send(new SayHello($name));
}
}
Mailer
app/Services/Register.php
Slide 15
Slide 15 text
15
Laravel
class Register
{
public function __construct(
private readonly Mailer $mailer,
) {}
public function create(string $name): void
{
// 何らか登録などする処理
// メールの送信
$this->mailer->send(new SayHello($name));
}
}
Mailer
Laravel
app/Services/Register.php
Slide 16
Slide 16 text
16
class Register
{
public function __construct(
private readonly SayHelloSenderInterface $sender,
) {}
public function create(string $name): void
{
// 何らか登録などする処理
// メールの送信
$this->sender>send($name);
}
}
lib/User/Register.php
Laravel
class SayHelloSenderInterface
{
public function send(string $name): void
}
lib/Mail/SayHelloSenderInterface.php
Slide 17
Slide 17 text
17
class Register
{
public function __construct(
private readonly SayHelloSenderInterface $sender,
) {}
public function create(string $name): void
{
// 何らか登録などする処理
// メールの送信
$this->sender>send($name);
}
}
Laravel
class SayHelloSenderInterface
{
public function send(string $name): void
}
Interface
Mailer
lib/User/Register.php lib/Mail/SayHelloSenderInterface.php
Slide 18
Slide 18 text
18
Laravel
class SayHelloConcrete implements SayHelloSenderInterface
{
public function __construct(
private readonly Mailer $mailer,
) {}
public function send(string $name): void
{
// メールの送信
$this->mailer->send(new SayHello($name));
}
}
app/Mail/SayHelloConcrete.php
class SayHelloSenderInterface
{
public array $bindings = [
¥Package¥Mail¥SayHelloInterface::class =>
¥App¥Services¥SayHelloConclete::class,
];
}
app/Providers/AppServiceProvider.php
Slide 19
Slide 19 text
19
Laravel
class SayHelloConcrete implements SayHelloSenderInterface
{
public function __construct(
private readonly Mailer $mailer,
) {}
public function send(string $name): void
{
// メールの送信
$this->mailer->send(new SayHello($name));
}
}
class SayHelloSenderInterface
{
public array $bindings = [
¥Package¥Mail¥SayHelloInterface::class =>
¥App¥Services¥SayHelloConclete::class,
];
}
Laravel app
ServiceProvider Interface
app/Mail/SayHelloConcrete.php app/Providers/AppServiceProvider.php