1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Mailer; |
6
|
|
|
|
7
|
|
|
use Yiisoft\View\ViewContextInterface; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Stores the path to the view file directory and the layout view names. |
11
|
|
|
*/ |
12
|
|
|
final class MessageBodyTemplate implements ViewContextInterface |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var string The directory containing view files for composing mail messages. |
16
|
|
|
*/ |
17
|
|
|
private string $viewPath; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var string The HTML layout view name. |
21
|
|
|
* |
22
|
|
|
* It is the layout used to render HTML mail body. If the value is empty string, no layout will be applied. |
23
|
|
|
* |
24
|
|
|
* The property can take the following values: |
25
|
|
|
* |
26
|
|
|
* - a relative view name: a view file relative to {@see MessageBodyRenderer::$viewPath}, e.g., 'layouts/html'. |
27
|
|
|
* - an empty string: the layout is disabled. |
28
|
|
|
*/ |
29
|
|
|
private string $htmlLayout; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string The TEXT layout view name. |
33
|
|
|
* |
34
|
|
|
* This is the layout used to render TEXT mail body. If the value is empty string, no layout will be applied. |
35
|
|
|
* |
36
|
|
|
* The property can take the following values: |
37
|
|
|
* |
38
|
|
|
* - a relative view name: a view file relative to {@see MessageBodyRenderer::$viewPath}, e.g., 'layouts/text'. |
39
|
|
|
* - an empty string: the layout is disabled. |
40
|
|
|
*/ |
41
|
|
|
private string $textLayout; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param string $viewPath The directory containing view files for composing mail messages. |
45
|
|
|
* @param string $htmlLayout The HTML layout view name. It is the layout used to render HTML mail body. |
46
|
|
|
* @param string $textLayout The TEXT layout view name. This is the layout used to render TEXT mail body. |
47
|
|
|
*/ |
48
|
35 |
|
public function __construct( |
49
|
|
|
string $viewPath, |
50
|
|
|
string $htmlLayout = 'layouts/html', |
51
|
|
|
string $textLayout = 'layouts/text' |
52
|
|
|
) { |
53
|
35 |
|
$this->viewPath = $viewPath; |
54
|
35 |
|
$this->htmlLayout = $htmlLayout; |
55
|
35 |
|
$this->textLayout = $textLayout; |
56
|
35 |
|
} |
57
|
|
|
|
58
|
|
|
/** Returns the directory containing view files for composing mail messages. |
59
|
|
|
* |
60
|
|
|
* @return string The directory containing view files for composing mail messages. |
61
|
|
|
*/ |
62
|
10 |
|
public function getViewPath(): string |
63
|
|
|
{ |
64
|
10 |
|
return $this->viewPath; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Returns the HTML layout view name. |
69
|
|
|
* |
70
|
|
|
* @return string The HTML layout view name. |
71
|
|
|
*/ |
72
|
9 |
|
public function getHtmlLayout(): string |
73
|
|
|
{ |
74
|
9 |
|
return $this->htmlLayout; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Returns the TEXT layout view name. |
79
|
|
|
* |
80
|
|
|
* @return string The TEXT layout view name. |
81
|
|
|
*/ |
82
|
8 |
|
public function getTextLayout(): string |
83
|
|
|
{ |
84
|
8 |
|
return $this->textLayout; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|