1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace T4web\Mail\Listener; |
4
|
|
|
|
5
|
|
|
use Zend\EventManager\EventInterface; |
6
|
|
|
use Zend\Mail\Message; |
7
|
|
|
use T4webDomainInterface\Infrastructure\RepositoryInterface; |
8
|
|
|
use T4web\Mail\Domain\MailLogEntry\MailLogEntry; |
9
|
|
|
use T4web\Mail\Template; |
10
|
|
|
|
11
|
|
|
class LogSending |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var RepositoryInterface |
15
|
|
|
*/ |
16
|
|
|
private $logRepository; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* UserCreate constructor. |
20
|
|
|
* @param RepositoryInterface $logRepository |
21
|
|
|
*/ |
22
|
|
|
public function __construct( |
23
|
|
|
RepositoryInterface $logRepository |
24
|
|
|
) |
25
|
|
|
{ |
26
|
|
|
$this->logRepository = $logRepository; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param EventInterface $event |
31
|
|
|
*/ |
32
|
|
|
public function __invoke(EventInterface $event) |
33
|
|
|
{ |
34
|
|
|
/** @var Message $message */ |
35
|
|
|
$message = $event->getParam('message'); |
36
|
|
|
|
37
|
|
|
/** @var Template $template */ |
38
|
|
|
$template = $event->getParam('template'); |
39
|
|
|
|
40
|
|
|
/** @var \Zend\Mail\AddressList $toAddress */ |
41
|
|
|
$toAddress = $message->getTo(); |
42
|
|
|
$toAddress->rewind(); |
43
|
|
|
|
44
|
|
|
$fromAddress = $message->getFrom(); |
45
|
|
|
$fromAddress->rewind(); |
46
|
|
|
|
47
|
|
|
/** @var \Zend\Mime\Message $body */ |
48
|
|
|
$body = $message->getBody(); |
49
|
|
|
|
50
|
|
|
$entry = new MailLogEntry([ |
51
|
|
|
'mailFrom' => $fromAddress->current()->getEmail(), |
52
|
|
|
'mailTo' => $toAddress->current()->getEmail(), |
53
|
|
|
'subject' => $message->getSubject(), |
54
|
|
|
'layoutId' => $template->getLayoutId(), |
55
|
|
|
'templateId' => $template->getId(), |
56
|
|
|
'body' => $body->getPartContent(0), |
57
|
|
|
'calculatedVars' => json_encode($event->getParam('data')), |
58
|
|
|
]); |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
$this->logRepository->add($entry); |
62
|
|
|
} |
63
|
|
|
} |