|
1
|
|
|
<?php |
|
2
|
|
|
namespace Da\Mailer\Queue\Backend\Sqs; |
|
3
|
|
|
|
|
4
|
|
|
use BadMethodCallException; |
|
5
|
|
|
use Da\Mailer\Event\EventHandlerTrait; |
|
6
|
|
|
use Da\Mailer\Model\AbstractMailObject; |
|
7
|
|
|
use Da\Mailer\Queue\Backend\MailJobInterface; |
|
8
|
|
|
use Da\Mailer\Model\MailMessage; |
|
9
|
|
|
|
|
10
|
|
|
class SqsMailJob extends AbstractMailObject implements MailJobInterface |
|
11
|
|
|
{ |
|
12
|
|
|
use EventHandlerTrait; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @var string |
|
16
|
|
|
*/ |
|
17
|
|
|
private $id; |
|
18
|
|
|
/** |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
private $receiptHandle; |
|
22
|
|
|
/** |
|
23
|
|
|
* @var MailMessage|string the message to store |
|
24
|
|
|
*/ |
|
25
|
|
|
private $message; |
|
26
|
|
|
/** |
|
27
|
|
|
* @var int |
|
28
|
|
|
*/ |
|
29
|
|
|
private $delaySeconds; |
|
30
|
|
|
/** |
|
31
|
|
|
* @var int between 0 and 900 seconds |
|
32
|
|
|
*/ |
|
33
|
|
|
private $visibilityTimeout; |
|
34
|
|
|
/** |
|
35
|
|
|
* @var bool |
|
36
|
|
|
*/ |
|
37
|
|
|
private $deleted = false; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @inheritdoc |
|
41
|
|
|
*/ |
|
42
|
|
|
public function __construct(array $config = []) |
|
43
|
|
|
{ |
|
44
|
|
|
parent::__construct($config); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @return string |
|
49
|
|
|
*/ |
|
50
|
|
|
public function getId() |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->id; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param string $anId |
|
57
|
|
|
*/ |
|
58
|
|
|
public function setId($anId) |
|
59
|
|
|
{ |
|
60
|
|
|
$this->id = $anId; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @return bool |
|
65
|
|
|
*/ |
|
66
|
|
|
public function isNewRecord() |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->id === null || $this->receiptHandle === null; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @return string |
|
73
|
|
|
*/ |
|
74
|
|
|
public function getReceiptHandle() |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->receiptHandle; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param string $receiptHandle |
|
81
|
|
|
*/ |
|
82
|
|
|
public function setReceiptHandle($receiptHandle) |
|
83
|
|
|
{ |
|
84
|
|
|
$this->receiptHandle = $receiptHandle; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @inheritdoc |
|
89
|
|
|
*/ |
|
90
|
|
|
public function getMessage() |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->message; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @inheritdoc |
|
97
|
|
|
*/ |
|
98
|
|
|
public function setMessage($message) |
|
99
|
|
|
{ |
|
100
|
|
|
$this->message = $message; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @return int |
|
105
|
|
|
*/ |
|
106
|
|
|
public function getDelaySeconds() |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->delaySeconds; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @param int $delaySeconds |
|
113
|
|
|
*/ |
|
114
|
|
|
public function setDelaySeconds($delaySeconds) |
|
115
|
|
|
{ |
|
116
|
|
|
if ($delaySeconds < 0 || $delaySeconds > 900) { |
|
117
|
|
|
throw new BadMethodCallException('Delay seconds must be between 0 and 900 seconds interval'); |
|
118
|
|
|
} |
|
119
|
|
|
$this->delaySeconds = $delaySeconds; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @return int |
|
124
|
|
|
*/ |
|
125
|
|
|
public function getVisibilityTimeout() |
|
126
|
|
|
{ |
|
127
|
|
|
return $this->message; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @param int $visibilityTimeout |
|
132
|
|
|
*/ |
|
133
|
|
|
public function setVisibilityTimeout($visibilityTimeout) |
|
134
|
|
|
{ |
|
135
|
|
|
$this->visibilityTimeout = $visibilityTimeout; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* @return bool |
|
140
|
|
|
*/ |
|
141
|
|
|
public function getDeleted() |
|
142
|
|
|
{ |
|
143
|
|
|
return $this->deleted; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* @param bool $deleted |
|
148
|
|
|
*/ |
|
149
|
|
|
public function setDeleted($deleted) |
|
150
|
|
|
{ |
|
151
|
|
|
$this->deleted = $deleted; |
|
152
|
|
|
} |
|
153
|
|
|
} |
|
154
|
|
|
|