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