Final Class Yiisoft\Mailer\View\ViewMailer
| Inheritance | Yiisoft\Mailer\View\ViewMailer |
|---|---|
| Implements | Yiisoft\Mailer\MailerInterface |
Mailer decorator with extra method compose() for composing message body via view rendering.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Mailer\View\ViewMailer | |
| compose() | Creates a new message instance and optionally composes its body content via view rendering. | Yiisoft\Mailer\View\ViewMailer |
| send() | Yiisoft\Mailer\View\ViewMailer | |
| sendMultiple() | Yiisoft\Mailer\View\ViewMailer | |
| withLocale() | Returns a new instance with specified locale code. | Yiisoft\Mailer\View\ViewMailer |
| withTemplate() | Returns a new instance with the specified message body template. | Yiisoft\Mailer\View\ViewMailer |
Method Details
| public mixed __construct ( \Yiisoft\Mailer\MailerInterface $mailer, Yiisoft\Mailer\View\MessageBodyRenderer $messageBodyRenderer ) | ||
| $mailer | \Yiisoft\Mailer\MailerInterface |
The mailer. |
| $messageBodyRenderer | Yiisoft\Mailer\View\MessageBodyRenderer |
View renderer for compose message body. |
public function __construct(
private readonly MailerInterface $mailer,
private MessageBodyRenderer $messageBodyRenderer,
) {
}
Creates a new message instance and optionally composes its body content via view rendering.
| public \Yiisoft\Mailer\MessageInterface compose ( string|null $htmlView = null, array $viewParameters = [], array $layoutParameters = [], string|null $textView = null ) | ||
| $htmlView | string|null |
The view name to be used for rendering the message HTML body. |
| $viewParameters | array |
The parameters (name-value pairs) that will be extracted and available in the view file. |
| $layoutParameters | array |
The parameters (name-value pairs) that will be extracted and available in the layout file. |
| $textView | string|null |
The view name to be used for rendering the message text body. If |
| return | \Yiisoft\Mailer\MessageInterface |
The message instance. |
|---|---|---|
| throws | \Yiisoft\View\Exception\ViewNotFoundException |
If the view file does not exist. |
public function compose(
?string $htmlView = null,
array $viewParameters = [],
array $layoutParameters = [],
?string $textView = null,
): MessageInterface {
$message = new Message();
if ($htmlView === null) {
return $message;
}
return $this->messageBodyRenderer->addBodyToMessage(
$message,
$htmlView,
$viewParameters,
$layoutParameters,
$textView,
);
}
| public void send ( \Yiisoft\Mailer\MessageInterface $message ) | ||
| $message | \Yiisoft\Mailer\MessageInterface | |
public function send(MessageInterface $message): void
{
$this->mailer->send($message);
}
| public \Yiisoft\Mailer\SendResults sendMultiple ( array $messages ) | ||
| $messages | array | |
public function sendMultiple(array $messages): SendResults
{
return $this->mailer->sendMultiple($messages);
}
Returns a new instance with specified locale code.
| public self withLocale ( string $locale ) | ||
| $locale | string |
The locale code. |
public function withLocale(string $locale): self
{
$new = clone $this;
$new->messageBodyRenderer = $new->messageBodyRenderer->withLocale($locale);
return $new;
}
Returns a new instance with the specified message body template.
| public self withTemplate ( Yiisoft\Mailer\View\MessageBodyTemplate $template ) | ||
| $template | Yiisoft\Mailer\View\MessageBodyTemplate |
The message body template instance. |
| return | self |
The new instance. |
|---|---|---|
public function withTemplate(MessageBodyTemplate $template): self
{
$new = clone $this;
$new->messageBodyRenderer = $new->messageBodyRenderer->withTemplate($template);
return $new;
}
Signup or Login in order to comment.