1
|
|
|
<?php |
2
|
|
|
namespace PSB\Core\Transport; |
3
|
|
|
|
4
|
|
|
|
5
|
|
|
use PSB\Core\HeaderTypeEnum; |
6
|
|
|
use PSB\Core\Util\Guard; |
7
|
|
|
|
8
|
|
|
class IncomingPhysicalMessage |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var string |
12
|
|
|
*/ |
13
|
|
|
private $messageId; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var array |
17
|
|
|
*/ |
18
|
|
|
private $headers; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
private $originalBody; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
private $body; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param string $messageId |
32
|
|
|
* @param array $headers |
33
|
|
|
* @param string $body |
34
|
|
|
*/ |
35
|
14 |
View Code Duplication |
public function __construct($messageId, array $headers, $body) |
36
|
|
|
{ |
37
|
14 |
|
Guard::againstNullAndEmpty('messageId', $messageId); |
38
|
13 |
|
Guard::againstNull('body', $body); |
39
|
|
|
|
40
|
12 |
|
$this->messageId = $messageId; |
41
|
12 |
|
$this->headers = $headers; |
42
|
12 |
|
$this->body = $body; |
43
|
12 |
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return string |
47
|
|
|
*/ |
48
|
1 |
|
public function getMessageId() |
49
|
|
|
{ |
50
|
1 |
|
return $this->messageId; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return array |
55
|
|
|
*/ |
56
|
3 |
|
public function getHeaders() |
57
|
|
|
{ |
58
|
3 |
|
return $this->headers; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return string |
63
|
|
|
*/ |
64
|
4 |
|
public function getBody() |
65
|
|
|
{ |
66
|
4 |
|
return $this->body; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return string|null |
71
|
|
|
*/ |
72
|
1 |
|
public function getReplyToAddress() |
73
|
|
|
{ |
74
|
1 |
|
return isset($this->headers[HeaderTypeEnum::REPLY_TO_ADDRESS]) ? $this->headers[HeaderTypeEnum::REPLY_TO_ADDRESS] : null; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param string $name |
79
|
|
|
* @param string $value |
80
|
|
|
*/ |
81
|
1 |
|
public function setHeader($name, $value) |
82
|
|
|
{ |
83
|
1 |
|
$this->headers[$name] = $value; |
84
|
1 |
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param array $headers |
88
|
|
|
*/ |
89
|
1 |
|
public function replaceHeaders(array $headers) |
90
|
|
|
{ |
91
|
1 |
|
$this->headers = $headers; |
92
|
1 |
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param string $newBody |
96
|
|
|
*/ |
97
|
3 |
|
public function replaceBody($newBody) |
98
|
|
|
{ |
99
|
3 |
|
Guard::againstNull('body', $newBody); |
100
|
|
|
|
101
|
2 |
|
if ($this->originalBody === null) { |
102
|
2 |
|
$this->originalBody = $this->body; |
103
|
|
|
} |
104
|
|
|
|
105
|
2 |
|
$this->body = $newBody; |
106
|
2 |
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Makes sure that the body is reset to the original state as it was when the message was created. |
110
|
|
|
*/ |
111
|
2 |
|
public function revertToOriginalBodyIfNeeded() |
112
|
|
|
{ |
113
|
2 |
|
if ($this->originalBody !== null) { |
114
|
1 |
|
$this->body = $this->originalBody; |
115
|
|
|
} |
116
|
2 |
|
} |
117
|
|
|
} |
118
|
|
|
|