1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yokai\MessengerBundle\Entity; |
4
|
|
|
|
5
|
|
|
use DateTime; |
6
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
7
|
|
|
use Doctrine\Common\Collections\Collection; |
8
|
|
|
use Doctrine\Common\Util\ClassUtils; |
9
|
|
|
use Yokai\MessengerBundle\Recipient\IdentifierRecipientInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @author Yann Eugoné <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
class Notification |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var int |
18
|
|
|
*/ |
19
|
|
|
private $id; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
private $subject; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
private $body; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var NotificationAttachment|Collection |
33
|
|
|
*/ |
34
|
|
|
private $attachments; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var DateTime |
38
|
|
|
*/ |
39
|
|
|
private $recordedAt; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
private $recipientClass; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var string |
48
|
|
|
*/ |
49
|
|
|
private $recipientId; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var DateTime|null |
53
|
|
|
*/ |
54
|
|
|
private $deliveredAt; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param string $subject |
58
|
|
|
* @param string $body |
59
|
|
|
* @param IdentifierRecipientInterface $recipient |
60
|
|
|
*/ |
61
|
3 |
|
public function __construct($subject, $body, IdentifierRecipientInterface $recipient) |
62
|
|
|
{ |
63
|
3 |
|
$this->subject = $subject; |
64
|
3 |
|
$this->body = $body; |
65
|
3 |
|
$this->recipientClass = ClassUtils::getClass($recipient); |
66
|
3 |
|
$this->recipientId = $recipient->getId(); |
67
|
3 |
|
$this->recordedAt = new DateTime('now'); |
68
|
|
|
|
69
|
3 |
|
$this->attachments = new ArrayCollection(); |
70
|
3 |
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return integer |
74
|
|
|
*/ |
75
|
1 |
|
public function getId() |
76
|
|
|
{ |
77
|
1 |
|
return $this->id; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return string |
82
|
|
|
*/ |
83
|
2 |
|
public function getSubject() |
84
|
|
|
{ |
85
|
2 |
|
return $this->subject; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return string |
90
|
|
|
*/ |
91
|
2 |
|
public function getBody() |
92
|
|
|
{ |
93
|
2 |
|
return $this->body; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return NotificationAttachment[] |
98
|
|
|
*/ |
99
|
|
|
public function getAttachments() |
100
|
|
|
{ |
101
|
|
|
return $this->attachments->toArray(); |
|
|
|
|
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return string |
106
|
|
|
*/ |
107
|
2 |
|
public function getRecipientClass() |
108
|
|
|
{ |
109
|
2 |
|
return $this->recipientClass; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @return string |
114
|
|
|
*/ |
115
|
2 |
|
public function getRecipientId() |
116
|
|
|
{ |
117
|
2 |
|
return $this->recipientId; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @return DateTime |
122
|
|
|
*/ |
123
|
1 |
|
public function getRecordedAt() |
124
|
|
|
{ |
125
|
1 |
|
return $this->recordedAt; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @return bool |
130
|
|
|
*/ |
131
|
1 |
|
public function isDelivered() |
132
|
|
|
{ |
133
|
1 |
|
return null !== $this->deliveredAt; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @return DateTime|null |
138
|
|
|
*/ |
139
|
2 |
|
public function getDeliveredAt() |
140
|
|
|
{ |
141
|
2 |
|
return $this->deliveredAt; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
*/ |
146
|
2 |
|
public function setDelivered() |
147
|
|
|
{ |
148
|
2 |
|
if (null !== $this->deliveredAt) { |
149
|
1 |
|
return; //immutable |
150
|
|
|
} |
151
|
|
|
|
152
|
2 |
|
$this->deliveredAt = new DateTime('now'); |
153
|
2 |
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @param NotificationAttachment $attachment |
157
|
|
|
*/ |
158
|
|
|
public function addNotificationAttachment(NotificationAttachment $attachment) |
159
|
|
|
{ |
160
|
|
|
$this->attachments->add($attachment); |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: