1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Shippinno\Notification\Domain\Model; |
5
|
|
|
|
6
|
|
|
use Shippinno\Template\LoadFailedException; |
7
|
|
|
use Shippinno\Template\RenderFailedException; |
8
|
|
|
use Shippinno\Template\Template; |
9
|
|
|
use Shippinno\Template\TemplateNotFoundException; |
10
|
|
|
|
11
|
|
|
class TemplateNotificationFactory |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var Template |
15
|
|
|
*/ |
16
|
|
|
private $template; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
private $subjectTemplateNameFormat = '%s.subject'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
private $bodyTemplateNameFormat = '%s.body'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param Template $template |
30
|
|
|
*/ |
31
|
1 |
|
public function __construct(Template $template) |
32
|
|
|
{ |
33
|
1 |
|
$this->template = $template; |
34
|
1 |
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param string $templateName |
38
|
|
|
* @param array $templateVariables |
39
|
|
|
* @param Destination $destination |
40
|
|
|
* @param DeduplicationKey|null $deduplicationKey |
41
|
|
|
* @return Notification |
42
|
|
|
* @throws LoadFailedException |
43
|
|
|
* @throws RenderFailedException |
44
|
|
|
* @throws TemplateNotFoundException |
45
|
|
|
*/ |
46
|
1 |
|
public function create( |
47
|
|
|
string $templateName, |
48
|
|
|
array $templateVariables, |
49
|
|
|
Destination $destination, |
50
|
|
|
DeduplicationKey $deduplicationKey = null |
51
|
|
|
) { |
52
|
1 |
|
$subject = $this->template->render( |
53
|
1 |
|
sprintf($this->subjectTemplateNameFormat, $templateName), |
54
|
1 |
|
$templateVariables |
55
|
|
|
); |
56
|
1 |
|
$body = $this->template->render( |
57
|
1 |
|
sprintf($this->bodyTemplateNameFormat, $templateName), |
58
|
1 |
|
$templateVariables |
59
|
|
|
); |
60
|
|
|
|
61
|
1 |
|
return new Notification( |
62
|
1 |
|
$destination, |
63
|
1 |
|
new Subject($subject), |
64
|
1 |
|
new Body($body), |
65
|
1 |
|
$deduplicationKey, |
66
|
1 |
|
$templateName, |
67
|
1 |
|
$templateVariables |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|