1 | <?php |
||
14 | class Message implements MessageInterface |
||
15 | { |
||
16 | /** |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $type; |
||
20 | |||
21 | /** |
||
22 | * @var array |
||
23 | */ |
||
24 | protected $body; |
||
25 | |||
26 | /** |
||
27 | * @var int |
||
28 | */ |
||
29 | protected $state; |
||
30 | |||
31 | /** |
||
32 | * @var int |
||
33 | */ |
||
34 | protected $restartCount = 0; |
||
35 | |||
36 | /** |
||
37 | * @var string |
||
38 | */ |
||
39 | protected $group; |
||
40 | |||
41 | /** |
||
42 | * @var \DateTime |
||
43 | */ |
||
44 | protected $createdAt; |
||
45 | |||
46 | /** |
||
47 | * @var \DateTime |
||
48 | */ |
||
49 | protected $updatedAt; |
||
50 | |||
51 | /** |
||
52 | * @var \DateTime |
||
53 | */ |
||
54 | protected $startedAt; |
||
55 | |||
56 | /** |
||
57 | * @var \DateTime |
||
58 | */ |
||
59 | protected $completedAt; |
||
60 | |||
61 | /** |
||
62 | * Constructor. |
||
63 | */ |
||
64 | public function __construct() |
||
65 | { |
||
66 | $this->createdAt = new \DateTime(); |
||
67 | $this->updatedAt = new \DateTime(); |
||
68 | $this->state = self::STATE_OPEN; |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * {@inheritdoc} |
||
73 | */ |
||
74 | public function __clone() |
||
75 | { |
||
76 | $this->state = self::STATE_OPEN; |
||
77 | $this->startedAt = null; |
||
78 | $this->completedAt = null; |
||
79 | |||
80 | $this->createdAt = new \DateTime(); |
||
81 | $this->updatedAt = new \DateTime(); |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * {@inheritdoc} |
||
86 | */ |
||
87 | public function setBody(array $body) |
||
91 | |||
92 | /** |
||
93 | * {@inheritdoc} |
||
94 | */ |
||
95 | public function getBody() |
||
99 | |||
100 | /** |
||
101 | * {@inheritdoc} |
||
102 | */ |
||
103 | public function getValue($names, $default = null) |
||
120 | |||
121 | /** |
||
122 | * {@inheritdoc} |
||
123 | */ |
||
124 | public function setCompletedAt(\DateTime $completedAt = null) |
||
128 | |||
129 | /** |
||
130 | * {@inheritdoc} |
||
131 | */ |
||
132 | public function getCompletedAt() |
||
136 | |||
137 | /** |
||
138 | * {@inheritdoc} |
||
139 | */ |
||
140 | public function setCreatedAt(\DateTime $createdAt = null) |
||
144 | |||
145 | /** |
||
146 | * {@inheritdoc} |
||
147 | */ |
||
148 | public function getCreatedAt() |
||
152 | |||
153 | /** |
||
154 | * {@inheritdoc} |
||
155 | */ |
||
156 | public function setGroup($group) |
||
160 | |||
161 | /** |
||
162 | * {@inheritdoc} |
||
163 | */ |
||
164 | public function getGroup() |
||
168 | |||
169 | /** |
||
170 | * {@inheritdoc} |
||
171 | */ |
||
172 | public function setType($type) |
||
176 | |||
177 | /** |
||
178 | * {@inheritdoc} |
||
179 | */ |
||
180 | public function getType() |
||
184 | |||
185 | /** |
||
186 | * {@inheritdoc} |
||
187 | */ |
||
188 | public function setState($state) |
||
192 | |||
193 | /** |
||
194 | * {@inheritdoc} |
||
195 | */ |
||
196 | public function getState() |
||
200 | |||
201 | /** |
||
202 | * {@inheritdoc} |
||
203 | */ |
||
204 | public function setRestartCount($restartCount) |
||
208 | |||
209 | /** |
||
210 | * {@inheritdoc} |
||
211 | */ |
||
212 | public function getRestartCount() |
||
216 | |||
217 | /** |
||
218 | * {@inheritdoc} |
||
219 | */ |
||
220 | public function setUpdatedAt(\DateTime $updatedAt = null) |
||
224 | |||
225 | /** |
||
226 | * {@inheritdoc} |
||
227 | */ |
||
228 | public function getUpdatedAt() |
||
232 | |||
233 | /** |
||
234 | * @return string[] |
||
235 | */ |
||
236 | public static function getStateList() |
||
237 | { |
||
238 | return array( |
||
239 | self::STATE_OPEN => 'open', |
||
240 | self::STATE_IN_PROGRESS => 'in_progress', |
||
241 | self::STATE_DONE => 'done', |
||
242 | self::STATE_ERROR => 'error', |
||
243 | self::STATE_CANCELLED => 'cancelled', |
||
244 | ); |
||
245 | } |
||
246 | |||
247 | /** |
||
248 | * {@inheritdoc} |
||
249 | */ |
||
250 | public function setStartedAt(\DateTime $startedAt = null) |
||
254 | |||
255 | /** |
||
256 | * {@inheritdoc} |
||
257 | */ |
||
258 | public function getStartedAt() |
||
262 | |||
263 | /** |
||
264 | * {@inheritdoc} |
||
265 | */ |
||
266 | public function getStateName() |
||
267 | { |
||
268 | $list = self::getStateList(); |
||
269 | |||
270 | return isset($list[$this->getState()]) ? $list[$this->getState()] : ''; |
||
271 | } |
||
272 | |||
273 | /** |
||
274 | * {@inheritdoc} |
||
275 | */ |
||
276 | public function isRunning() |
||
280 | |||
281 | /** |
||
282 | * {@inheritdoc} |
||
283 | */ |
||
284 | public function isCancelled() |
||
288 | |||
289 | /** |
||
290 | * {@inheritdoc} |
||
291 | */ |
||
292 | public function isError() |
||
296 | |||
297 | /** |
||
298 | * {@inheritdoc} |
||
299 | */ |
||
300 | public function isOpen() |
||
304 | } |
||
305 |