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