← Каталог
Laravel - MVC-фреймворк и паттерны проектирования — Внедрение через конструктор
Фрагмент из «Laravel - MVC-фреймворк и паттерны проектирования»: Внедрение через конструктор.
class NotificationService
{
protected $mailer;
public function __construct(Mailer $mailer)
{
$this->mailer = $mailer;
}
public function send($user, $message)
{
$this->mailer->send($user->email, $message);
}
} class NotificationService
{
protected $mailer;
public function __construct(Mailer $mailer)
{
$this->mailer = $mailer;
}
public function send($user, $message)
{
$this->mailer->send($user->email, $message);
}
}