Final Class Yiisoft\Mailer\View\MessageBodyRenderer
| Inheritance | Yiisoft\ |
|---|
View renderer used to compose message body.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\ |
|
| addBodyToMessage() | Adds the rendered body to the message and returns it. | Yiisoft\ |
| renderHtml() | Renders the HTML view specified with optional parameters and layout. | Yiisoft\ |
| renderText() | Renders the text view specified with optional parameters and layout. | Yiisoft\ |
| withLocale() | Returns a new instance with specified locale code. | Yiisoft\ |
| withTemplate() | Returns a new instance with the specified message body template. | Yiisoft\ |
| withView() | Returns a new instance with the specified view. | Yiisoft\ |
Method Details
| public mixed __construct ( \ | ||
| $view | \ |
The view instance. |
| $template | Yiisoft\ |
The message body template instance. |
public function __construct(
private View $view,
private MessageBodyTemplate $template,
) {
}
Adds the rendered body to the message and returns it.
| public \ | ||
| $message | \ |
The message to which the body will be added. |
| $htmlView | string |
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. |
| return | \ |
The message with the added body. |
|---|---|---|
| throws | \ |
If the view file does not exist. |
public function addBodyToMessage(
MessageInterface $message,
string $htmlView,
array $viewParameters = [],
array $layoutParameters = [],
?string $textView = null,
): MessageInterface {
$message = $message->withHtmlBody(
$this->renderHtml($htmlView, $viewParameters, $layoutParameters)
);
if ($textView !== null) {
$message = $message->withTextBody(
$this->renderText($textView, $viewParameters, $layoutParameters)
);
}
return $message;
}
Renders the HTML view specified with optional parameters and layout.
See also \
| public string renderHtml ( string $view, array $viewParameters = [], array $layoutParameters = [] ) | ||
| $view | string |
The view name of the view file. |
| $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. |
| return | string |
The rendering HTML result. |
|---|---|---|
| throws | \ |
If the view file does not exist. |
public function renderHtml(string $view, array $viewParameters = [], array $layoutParameters = []): string
{
$content = $this->view
->withContextPath($this->template->viewPath)
->render($view, $viewParameters);
if ($this->template->htmlLayout === null) {
return $content;
}
$layoutParameters['content'] = $content;
return $this->view
->withContextPath($this->template->viewPath)
->render($this->template->htmlLayout, $layoutParameters);
}
Renders the text view specified with optional parameters and layout.
See also \
| public string renderText ( string $view, array $viewParameters = [], array $layoutParameters = [] ) | ||
| $view | string |
The view name of the view file. |
| $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. |
| return | string |
The rendering text result. |
|---|---|---|
| throws | \ |
If the view file does not exist. |
public function renderText(string $view, array $viewParameters = [], array $layoutParameters = []): string
{
$content = $this->view
->withContextPath($this->template->viewPath)
->render($view, $viewParameters);
if ($this->template->textLayout === null) {
return $content;
}
$layoutParameters['content'] = $content;
return $this->view
->withContextPath($this->template->viewPath)
->render($this->template->textLayout, $layoutParameters);
}
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->view = $this->view->withLocale($locale);
return $new;
}
Returns a new instance with the specified message body template.
| public self withTemplate ( Yiisoft\ | ||
| $template | Yiisoft\ |
The message body template. |
| return | self |
The new instance. |
|---|---|---|
public function withTemplate(MessageBodyTemplate $template): self
{
$new = clone $this;
$new->template = $template;
return $new;
}
Returns a new instance with the specified view.
| public self withView ( \ | ||
| $view | \ |
The view instance. |
| return | self |
The new instance. |
|---|---|---|
public function withView(View $view): self
{
$new = clone $this;
$new->view = $view;
return $new;
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.