1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* This file is part of Aura for PHP. |
5
|
|
|
* |
6
|
|
|
* @license http://opensource.org/licenses/MIT MIT |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Aura\Payload; |
11
|
|
|
|
12
|
|
|
use Aura\Payload_Interface\PayloadInterface; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* |
16
|
|
|
* A domain payload object. |
17
|
|
|
* |
18
|
|
|
* @package Aura.Payload |
19
|
|
|
* |
20
|
|
|
*/ |
21
|
|
|
class PayloadImmutable implements PayloadInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* |
25
|
|
|
* The payload status. |
26
|
|
|
* |
27
|
|
|
* @var mixed |
28
|
|
|
* |
29
|
|
|
*/ |
30
|
|
|
private $status; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* |
34
|
|
|
* The domain input. |
35
|
|
|
* |
36
|
|
|
* @var mixed |
37
|
|
|
* |
38
|
|
|
*/ |
39
|
|
|
private $input; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* |
43
|
|
|
* The domain output. |
44
|
|
|
* |
45
|
|
|
* @var mixed |
46
|
|
|
* |
47
|
|
|
*/ |
48
|
|
|
private $output; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* |
52
|
|
|
* Messages reported by the domain. |
53
|
|
|
* |
54
|
|
|
* @var mixed |
55
|
|
|
* |
56
|
|
|
*/ |
57
|
|
|
private $messages; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* |
61
|
|
|
* Arbitrary extra information from the domain. |
62
|
|
|
* |
63
|
|
|
* @var mixed |
64
|
|
|
* |
65
|
|
|
*/ |
66
|
|
|
private $extras; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* |
70
|
|
|
* Sets the payload status. |
71
|
|
|
* |
72
|
|
|
* @param mixed $status The payload status. |
73
|
|
|
* |
74
|
|
|
* @return self |
75
|
|
|
* |
76
|
|
|
*/ |
77
|
|
|
public function setStatus($status) |
78
|
|
|
{ |
79
|
|
|
$cloned = clone $this; |
80
|
|
|
$cloned->status = $status; |
81
|
|
|
|
82
|
|
|
return $cloned; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* |
87
|
|
|
* Gets the payload status. |
88
|
|
|
* |
89
|
|
|
* @return mixed |
90
|
|
|
* |
91
|
|
|
*/ |
92
|
|
|
public function getStatus() |
93
|
|
|
{ |
94
|
|
|
return $this->status; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* |
99
|
|
|
* Sets the domain input. |
100
|
|
|
* |
101
|
|
|
* @param mixed $input The domain input. |
102
|
|
|
* |
103
|
|
|
* @return self |
104
|
|
|
* |
105
|
|
|
*/ |
106
|
|
|
public function setInput($input) |
107
|
|
|
{ |
108
|
|
|
$cloned = clone $this; |
109
|
|
|
$cloned->input = $input; |
110
|
|
|
|
111
|
|
|
return $cloned; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* |
116
|
|
|
* Gets the domain input. |
117
|
|
|
* |
118
|
|
|
* @return mixed |
119
|
|
|
* |
120
|
|
|
*/ |
121
|
|
|
public function getInput() |
122
|
|
|
{ |
123
|
|
|
return $this->input; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* |
128
|
|
|
* Sets the domain output. |
129
|
|
|
* |
130
|
|
|
* @param mixed $output The domain output. |
131
|
|
|
* |
132
|
|
|
* @return self |
133
|
|
|
* |
134
|
|
|
*/ |
135
|
|
|
public function setOutput($output) |
136
|
|
|
{ |
137
|
|
|
$cloned = clone $this; |
138
|
|
|
$cloned->output = $output; |
139
|
|
|
|
140
|
|
|
return $cloned; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* |
145
|
|
|
* Gets the domain output. |
146
|
|
|
* |
147
|
|
|
* @return mixed |
148
|
|
|
* |
149
|
|
|
*/ |
150
|
|
|
public function getOutput() |
151
|
|
|
{ |
152
|
|
|
return $this->output; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* |
157
|
|
|
* Sets the domain messages. |
158
|
|
|
* |
159
|
|
|
* @param mixed $messages The domain messages. |
160
|
|
|
* |
161
|
|
|
* @return self |
162
|
|
|
* |
163
|
|
|
*/ |
164
|
|
|
public function setMessages($messages) |
165
|
|
|
{ |
166
|
|
|
$cloned = clone $this; |
167
|
|
|
$cloned->messages = $messages; |
168
|
|
|
|
169
|
|
|
return $cloned; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* |
174
|
|
|
* Gets the domain messages. |
175
|
|
|
* |
176
|
|
|
* @return mixed |
177
|
|
|
* |
178
|
|
|
*/ |
179
|
|
|
public function getMessages() |
180
|
|
|
{ |
181
|
|
|
return $this->messages; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* |
186
|
|
|
* Sets arbitrary extra domain information. |
187
|
|
|
* |
188
|
|
|
* @param mixed $extras The domain extras. |
189
|
|
|
* |
190
|
|
|
* @return self |
191
|
|
|
* |
192
|
|
|
*/ |
193
|
|
|
public function setExtras($extras) |
194
|
|
|
{ |
195
|
|
|
$cloned = clone $this; |
196
|
|
|
$cloned->extras = $extras; |
197
|
|
|
|
198
|
|
|
return $cloned; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* |
203
|
|
|
* Gets the arbitrary extra domain information. |
204
|
|
|
* |
205
|
|
|
* @return mixed |
206
|
|
|
* |
207
|
|
|
*/ |
208
|
|
|
public function getExtras() |
209
|
|
|
{ |
210
|
|
|
return $this->extras; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* Deep clone all properties |
215
|
|
|
*/ |
216
|
|
|
protected function __clone() |
217
|
|
|
{ |
218
|
|
|
$this->status = $this->deepClone($this->status); |
219
|
|
|
$this->input = $this->deepClone($this->input); |
220
|
|
|
$this->output = $this->deepClone($this->output); |
221
|
|
|
$this->messages = $this->deepClone($this->messages); |
222
|
|
|
$this->extras = $this->deepClone($this->extras); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* Return a cloned property |
227
|
|
|
* |
228
|
|
|
* @param $property |
229
|
|
|
* |
230
|
|
|
* @return mixed |
231
|
|
|
*/ |
232
|
|
|
protected function deepClone($property) |
233
|
|
|
{ |
234
|
|
|
if (is_array($property)) { |
235
|
|
|
$cloned = []; |
236
|
|
|
foreach ($property as $key => $value) { |
237
|
|
|
$cloned[$key] = $this->deepClone($value); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
return $cloned; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
if (is_object($property)) { |
244
|
|
|
return clone $property; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
return $property; |
248
|
|
|
} |
249
|
|
|
} |
250
|
|
|
|