-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathBaseEmailAction.php
More file actions
48 lines (38 loc) · 1.3 KB
/
BaseEmailAction.php
File metadata and controls
48 lines (38 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
declare(strict_types=1);
namespace Netgen\InformationCollection\Core\Action;
use Netgen\InformationCollection\API\Action\ActionInterface;
use Netgen\InformationCollection\API\Exception\EmailNotSentException;
use Netgen\InformationCollection\API\MailerInterface;
use Netgen\InformationCollection\API\Value\Event\InformationCollected;
use Netgen\InformationCollection\Core\EmailDataProvider\DefaultProvider;
use Netgen\InformationCollection\Core\Factory\BaseEmailDataFactory;
abstract class BaseEmailAction implements ActionInterface
{
/**
* @var \Netgen\InformationCollection\API\MailerInterface
*/
protected $mailer;
/**
* @var DefaultProvider
*/
protected $emailDataProvider;
public function __construct(MailerInterface $mailer, DefaultProvider $emailDataProvider)
{
$this->mailer = $mailer;
$this->emailDataProvider = $emailDataProvider;
}
/**
* {@inheritdoc}
*/
public function act(InformationCollected $event): void
{
$emailData = $this->emailDataProvider->provide($event);
try {
$this->mailer->sendEmail($emailData);
} catch (EmailNotSentException $e) {
$this->throwException($e);
}
}
abstract protected function throwException(EmailNotSentException $exception);
}