1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace AbterPhp\Contact\Domain\Entities; |
6
|
|
|
|
7
|
|
|
use AbterPhp\Framework\Domain\Entities\IStringerEntity; |
8
|
|
|
|
9
|
|
|
class Message implements IStringerEntity |
10
|
|
|
{ |
11
|
|
|
/** @var string */ |
12
|
|
|
protected $id; |
13
|
|
|
|
14
|
|
|
/** @var Form */ |
15
|
|
|
protected $form; |
16
|
|
|
|
17
|
|
|
/** @var string */ |
18
|
|
|
protected $subject; |
19
|
|
|
|
20
|
|
|
/** @var string */ |
21
|
|
|
protected $body; |
22
|
|
|
|
23
|
|
|
/** @var string */ |
24
|
|
|
protected $fromName; |
25
|
|
|
|
26
|
|
|
/** @var string */ |
27
|
|
|
protected $fromEmail; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param string $id |
31
|
|
|
* @param Form $form |
32
|
|
|
* @param string $subject |
33
|
|
|
* @param string $body |
34
|
|
|
* @param string $fromName |
35
|
|
|
* @param string $fromEmail |
36
|
|
|
*/ |
37
|
|
|
public function __construct( |
38
|
|
|
string $id, |
39
|
|
|
Form $form, |
40
|
|
|
string $subject, |
41
|
|
|
string $body, |
42
|
|
|
string $fromName, |
43
|
|
|
string $fromEmail |
44
|
|
|
) { |
45
|
|
|
$this->id = $id; |
46
|
|
|
$this->form = $form; |
47
|
|
|
$this->subject = $subject; |
48
|
|
|
$this->body = $body; |
49
|
|
|
$this->fromName = $fromName; |
50
|
|
|
$this->fromEmail = $fromEmail; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return string |
55
|
|
|
*/ |
56
|
|
|
public function getId() |
57
|
|
|
{ |
58
|
|
|
return $this->id; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param string $id |
63
|
|
|
*/ |
64
|
|
|
public function setId($id) |
65
|
|
|
{ |
66
|
|
|
$this->id = $id; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return Form |
71
|
|
|
*/ |
72
|
|
|
public function getForm(): Form |
73
|
|
|
{ |
74
|
|
|
return $this->form; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param Form $form |
79
|
|
|
* |
80
|
|
|
* @return $this |
81
|
|
|
*/ |
82
|
|
|
public function setForm(Form $form): Message |
83
|
|
|
{ |
84
|
|
|
$this->form = $form; |
85
|
|
|
|
86
|
|
|
return $this; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return string |
91
|
|
|
*/ |
92
|
|
|
public function getSubject(): string |
93
|
|
|
{ |
94
|
|
|
return $this->subject; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param string $subject |
99
|
|
|
* |
100
|
|
|
* @return $this |
101
|
|
|
*/ |
102
|
|
|
public function setSubject(string $subject): Message |
103
|
|
|
{ |
104
|
|
|
$this->subject = $subject; |
105
|
|
|
|
106
|
|
|
return $this; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return string |
111
|
|
|
*/ |
112
|
|
|
public function getBody(): string |
113
|
|
|
{ |
114
|
|
|
return $this->body; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @param string $body |
119
|
|
|
* |
120
|
|
|
* @return $this |
121
|
|
|
*/ |
122
|
|
|
public function setBody(string $body): Message |
123
|
|
|
{ |
124
|
|
|
$this->body = $body; |
125
|
|
|
|
126
|
|
|
return $this; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @return string |
131
|
|
|
*/ |
132
|
|
|
public function getFromName(): string |
133
|
|
|
{ |
134
|
|
|
return $this->fromName; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @param string $fromName |
139
|
|
|
* |
140
|
|
|
* @return $this |
141
|
|
|
*/ |
142
|
|
|
public function setFromName(string $fromName): Message |
143
|
|
|
{ |
144
|
|
|
$this->fromName = $fromName; |
145
|
|
|
|
146
|
|
|
return $this; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @return string |
151
|
|
|
*/ |
152
|
|
|
public function getFromEmail(): string |
153
|
|
|
{ |
154
|
|
|
return $this->fromEmail; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @param string $fromEmail |
159
|
|
|
* |
160
|
|
|
* @return $this |
161
|
|
|
*/ |
162
|
|
|
public function setFromEmail(string $fromEmail): Message |
163
|
|
|
{ |
164
|
|
|
$this->fromEmail = $fromEmail; |
165
|
|
|
|
166
|
|
|
return $this; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @return string |
171
|
|
|
*/ |
172
|
|
|
public function __toString(): string |
173
|
|
|
{ |
174
|
|
|
return sprintf('%s - %s', $this->getFromName(), $this->getSubject()); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @return array|null |
179
|
|
|
*/ |
180
|
|
|
public function toData(): ?array |
181
|
|
|
{ |
182
|
|
|
return [ |
183
|
|
|
'id' => $this->getId(), |
184
|
|
|
'form' => $this->getForm(), |
185
|
|
|
'subject' => $this->getSubject(), |
186
|
|
|
'body' => $this->getBody(), |
187
|
|
|
'from_name' => $this->getFromName(), |
188
|
|
|
'from_email' => $this->getFromEmail(), |
189
|
|
|
]; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @return string |
194
|
|
|
*/ |
195
|
|
|
public function toJSON(): string |
196
|
|
|
{ |
197
|
|
|
return json_encode($this->toData()); |
198
|
|
|
} |
199
|
|
|
} |
200
|
|
|
|