1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Shippinno\Notification\Infrastructure\Domain\Model; |
5
|
|
|
|
6
|
|
|
use Shippinno\Email\EmailNotSentException; |
7
|
|
|
use Shippinno\Email\SendEmail; |
8
|
|
|
use Shippinno\Notification\Domain\Model\Destination; |
9
|
|
|
use Shippinno\Notification\Domain\Model\EmailDestination; |
10
|
|
|
use Shippinno\Notification\Domain\Model\Gateway; |
11
|
|
|
use Shippinno\Notification\Domain\Model\Notification; |
12
|
|
|
use Shippinno\Notification\Domain\Model\NotificationNotSentException; |
13
|
|
|
use Tanigami\ValueObjects\Web\Email; |
14
|
|
|
use Tanigami\ValueObjects\Web\EmailAddress; |
15
|
|
|
use Verraes\ClassFunctions\ClassFunctions; |
16
|
|
|
|
17
|
|
|
class EmailGateway extends Gateway |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var SendEmail |
21
|
|
|
*/ |
22
|
|
|
private $sendEmail; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var EmailAddress |
26
|
|
|
*/ |
27
|
|
|
private $from; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param SendEmail $sendEmail |
31
|
|
|
* @param EmailAddress $from |
32
|
|
|
*/ |
33
|
3 |
|
public function __construct(SendEmail $sendEmail, EmailAddress $from) |
34
|
|
|
{ |
35
|
3 |
|
$this->sendEmail = $sendEmail; |
36
|
3 |
|
$this->from = $from; |
37
|
3 |
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* {@inheritdoc} |
41
|
|
|
*/ |
42
|
2 |
|
protected function doSend(Notification $notification): void |
43
|
|
|
{ |
44
|
|
|
/** @var EmailDestination $destination */ |
45
|
2 |
|
$destination = $notification->destination(); |
46
|
2 |
|
$email = new Email( |
47
|
2 |
|
$notification->subject()->subject(), |
48
|
2 |
|
$notification->body()->body(), |
49
|
2 |
|
$this->from, |
50
|
2 |
|
$destination->to(), |
51
|
2 |
|
$destination->cc(), |
52
|
2 |
|
$destination->bcc() |
53
|
|
|
); |
54
|
|
|
try { |
55
|
2 |
|
$this->sendEmail->execute($email); |
56
|
1 |
|
} catch (EmailNotSentException $e) { |
57
|
1 |
|
throw new NotificationNotSentException($notification, $e); |
|
|
|
|
58
|
|
|
} |
59
|
1 |
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritdoc} |
63
|
|
|
*/ |
64
|
3 |
|
public function sendsToDestination(Destination $destination): bool |
65
|
|
|
{ |
66
|
3 |
|
return $destination instanceof EmailDestination; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: