1 | <?php |
||
36 | abstract class AbstractMail implements Mail |
||
37 | { |
||
38 | |||
39 | /** |
||
40 | * Configuration Settings. |
||
41 | * |
||
42 | * @since 1.0.0 |
||
43 | * |
||
44 | * @var ConfigInterface |
||
45 | */ |
||
46 | protected $config; |
||
47 | |||
48 | /** |
||
49 | * Template that is used for the email. |
||
50 | * |
||
51 | * @since 1.0.0 |
||
52 | * |
||
53 | * @var Template |
||
54 | */ |
||
55 | protected $template; |
||
56 | |||
57 | /** |
||
58 | * Content for the different sections. |
||
59 | * |
||
60 | * @since 1.0.0 |
||
61 | * |
||
62 | * @var array |
||
63 | */ |
||
64 | protected $sectionContent = []; |
||
65 | |||
66 | /** |
||
67 | * Format of the mail. |
||
68 | * |
||
69 | * @since 1.0.0 |
||
70 | * |
||
71 | * @var string |
||
72 | */ |
||
73 | protected $format; |
||
74 | |||
75 | /** |
||
76 | * ViewBuilder to create template and section views. |
||
77 | * |
||
78 | * @since 1.0.0 |
||
79 | * |
||
80 | * @var ViewBuilder |
||
81 | */ |
||
82 | protected $viewBuilder; |
||
83 | |||
84 | /** |
||
85 | * Instantiate an AbstractMail object. |
||
86 | * |
||
87 | * @since 1.0.0 |
||
88 | * |
||
89 | * @param ConfigInterface $config The Config to use. |
||
90 | * |
||
91 | * @throws FailedToProcessConfigException If the Config could not be processed. |
||
92 | */ |
||
93 | 16 | public function __construct(ConfigInterface $config) |
|
109 | |||
110 | /** |
||
111 | * Get the template to use for the renderer. |
||
112 | * |
||
113 | * @since 1.0.0 |
||
114 | * |
||
115 | * @return Template Reference to the template that is used. |
||
116 | * @throws RuntimeException |
||
117 | */ |
||
118 | 16 | public function getTemplate() |
|
131 | |||
132 | /** |
||
133 | * Set the template to use for the renderer. |
||
134 | * |
||
135 | * @since 1.0.0 |
||
136 | * |
||
137 | * @param string|Template $template Template to use for the |
||
138 | * renderer. |
||
139 | * |
||
140 | * @return Mail |
||
141 | * @throws InvalidTemplate If the template class could not be instantiated. |
||
142 | * @throws InvalidTemplate If the template type is not recognized. |
||
143 | */ |
||
144 | 16 | public function setTemplate($template) |
|
168 | |||
169 | /** |
||
170 | * Add a section to the Mail. |
||
171 | * |
||
172 | * @since 1.0.0 |
||
173 | * |
||
174 | * @param string $type Type of section to add. |
||
175 | * @param string $content Content of the section. |
||
176 | * |
||
177 | * @throws RuntimeException |
||
178 | */ |
||
179 | 8 | public function addSection($type, $content) |
|
183 | |||
184 | /** |
||
185 | * Render the Mail for a given context. |
||
186 | * |
||
187 | * @since 1.0.0 |
||
188 | * |
||
189 | * @param array $context The context in which to render the email. |
||
190 | * |
||
191 | * @return string Rendered output of the email |
||
192 | */ |
||
193 | 8 | public function render(array $context) |
|
207 | |||
208 | /** |
||
209 | * Send the email to one or more recipients. |
||
210 | * |
||
211 | * @since 1.0.0 |
||
212 | * |
||
213 | * @param Recipients|EmailAddress|array|string $recipients |
||
214 | * |
||
215 | * @return Mail |
||
|
|||
216 | */ |
||
217 | public function sendTo($recipients) |
||
233 | |||
234 | /** |
||
235 | * Execute the sending of one individual email. |
||
236 | * |
||
237 | * @since 1.0.0 |
||
238 | * |
||
239 | * @param EmailAddress $recipient Recipient to send the email to. |
||
240 | * |
||
241 | * @return Mail |
||
242 | */ |
||
243 | protected function executeSend(EmailAddress $recipient) |
||
250 | |||
251 | /** |
||
252 | * Instantiate the requested sections for a template. |
||
253 | * |
||
254 | * @since 1.0.0 |
||
255 | * |
||
256 | * @param array $sections Sections to instantiate. |
||
257 | * @param array $context The context in which to instantiate the sections. |
||
258 | */ |
||
259 | protected function instantiateSections(array $sections, array &$context) |
||
277 | |||
278 | /** |
||
279 | * Set the format of the mail. |
||
280 | * |
||
281 | * @since 1.0.0 |
||
282 | * |
||
283 | * @return string Format of the Mail. |
||
284 | */ |
||
285 | protected function getFormat() |
||
289 | |||
290 | /** |
||
291 | * Set the format of the mail. |
||
292 | * |
||
293 | * @since 1.0.0 |
||
294 | * |
||
295 | * @return void |
||
296 | */ |
||
297 | abstract protected function setFormat(); |
||
298 | |||
299 | /** |
||
300 | * Set the template to the default template defined in the configuration. |
||
301 | * |
||
302 | * @since 1.0.0 |
||
303 | * |
||
304 | * @throws RuntimeException |
||
305 | */ |
||
306 | protected function setDefaultTemplate() |
||
311 | |||
312 | /** |
||
313 | * Create an instance of a template. |
||
314 | * |
||
315 | * @since 1.0.0 |
||
316 | * |
||
317 | * @param string $template Template to instantiate. |
||
318 | * |
||
319 | * @return Template $template Newly created instance. |
||
320 | * @throws RuntimeException |
||
321 | */ |
||
322 | protected function createTemplate($template) |
||
328 | |||
329 | /** |
||
330 | * Set the context of the mail. |
||
331 | * |
||
332 | * @since 1.0.0 |
||
333 | * |
||
334 | * @param array $context Context to set/modify. |
||
335 | * |
||
336 | * @return array Updated context. |
||
337 | */ |
||
338 | abstract protected function setContext(array $context); |
||
339 | } |
||
340 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.