1 | <?php |
||
34 | abstract class AbstractMail implements MailInterface |
||
35 | { |
||
36 | |||
37 | /** |
||
38 | * Configuration Settings. |
||
39 | * |
||
40 | * @since 1.0.0 |
||
41 | * |
||
42 | * @var ConfigInterface |
||
43 | */ |
||
44 | protected $config; |
||
45 | |||
46 | /** |
||
47 | * Template that is used for the email. |
||
48 | * |
||
49 | * @since 1.0.0 |
||
50 | * |
||
51 | * @var TemplateInterface |
||
52 | */ |
||
53 | protected $template; |
||
54 | |||
55 | /** |
||
56 | * Content for the different sections. |
||
57 | * |
||
58 | * @since 1.0.0 |
||
59 | * |
||
60 | * @var array |
||
61 | */ |
||
62 | protected $sectionContent = []; |
||
63 | |||
64 | /** |
||
65 | * Format of the mail. |
||
66 | * |
||
67 | * @since 1.0.0 |
||
68 | * |
||
69 | * @var string |
||
70 | */ |
||
71 | protected $format; |
||
72 | |||
73 | /** |
||
74 | * ViewBuilder to create template and section views. |
||
75 | * |
||
76 | * @since 1.0.0 |
||
77 | * |
||
78 | * @var ViewBuilder |
||
79 | */ |
||
80 | protected $viewBuilder; |
||
81 | |||
82 | /** |
||
83 | * Instantiate an AbstractMail object. |
||
84 | * |
||
85 | * @since 1.0.0 |
||
86 | * |
||
87 | * @param ConfigInterface $config The Config to use. |
||
88 | * |
||
89 | * @throws FailedToProcessConfigException If the Config could not be processed. |
||
90 | */ |
||
91 | 16 | public function __construct(ConfigInterface $config) |
|
107 | |||
108 | /** |
||
109 | * Get the template to use for the renderer. |
||
110 | * |
||
111 | * @since 1.0.0 |
||
112 | * |
||
113 | * @return TemplateInterface Reference to the template that is used. |
||
114 | * @throws RuntimeException |
||
115 | */ |
||
116 | 16 | public function getTemplate() |
|
129 | |||
130 | /** |
||
131 | * Set the template to use for the renderer. |
||
132 | * |
||
133 | * @since 1.0.0 |
||
134 | * |
||
135 | * @param string|TemplateInterface $template Template to use for the |
||
136 | * renderer. |
||
137 | * |
||
138 | * @throws InvalidTemplateException If the template class could not be instantiated. |
||
139 | * @throws InvalidTemplateException If the template type is not recognized. |
||
140 | */ |
||
141 | 16 | public function setTemplate($template) |
|
163 | |||
164 | /** |
||
165 | * Add a section to the Mail. |
||
166 | * |
||
167 | * @since 1.0.0 |
||
168 | * |
||
169 | * @param string $type Type of section to add. |
||
170 | * @param string $content Content of the section. |
||
171 | * |
||
172 | * @throws RuntimeException |
||
173 | */ |
||
174 | 8 | public function addSection($type, $content) |
|
178 | |||
179 | /** |
||
180 | * Render the Mail for a given context. |
||
181 | * |
||
182 | * @since 1.0.0 |
||
183 | * |
||
184 | * @param array $context The context in which to render the email. |
||
185 | * |
||
186 | * @return string Rendered output of the email |
||
187 | */ |
||
188 | 8 | public function render(array $context) |
|
202 | |||
203 | /** |
||
204 | * Instantiate the requested sections for a template. |
||
205 | * |
||
206 | * @since 1.0.0 |
||
207 | * |
||
208 | * @param array $sections Sections to instantiate. |
||
209 | * @param array $context The context in which to instantiate the sections. |
||
210 | */ |
||
211 | 8 | protected function instantiateSections(array $sections, array &$context) |
|
229 | |||
230 | /** |
||
231 | * Set the format of the mail. |
||
232 | * |
||
233 | * @since 1.0.0 |
||
234 | * |
||
235 | * @return string Format of the Mail. |
||
236 | */ |
||
237 | 8 | protected function getFormat() |
|
241 | |||
242 | /** |
||
243 | * Set the format of the mail. |
||
244 | * |
||
245 | * @since 1.0.0 |
||
246 | * |
||
247 | * @return void |
||
248 | */ |
||
249 | abstract protected function setFormat(); |
||
250 | |||
251 | /** |
||
252 | * Set the template to the default template defined in the configuration. |
||
253 | * |
||
254 | * @since 1.0.0 |
||
255 | * |
||
256 | * @throws RuntimeException |
||
257 | */ |
||
258 | protected function setDefaultTemplate() |
||
263 | |||
264 | /** |
||
265 | * Create an instance of a template. |
||
266 | * |
||
267 | * @since 1.0.0 |
||
268 | * |
||
269 | * @param string $template Template to instantiate. |
||
270 | * |
||
271 | * @return TemplateInterface $template Newly created instance. |
||
272 | * @throws RuntimeException |
||
273 | */ |
||
274 | 16 | protected function createTemplate($template) |
|
280 | |||
281 | /** |
||
282 | * Set the context of the mail. |
||
283 | * |
||
284 | * @since 1.0.0 |
||
285 | * |
||
286 | * @param array $context Context to set/modify. |
||
287 | * |
||
288 | * @return array Updated context. |
||
289 | */ |
||
290 | abstract protected function setContext(array $context); |
||
291 | } |
||
292 |