|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright (c) 2011-present Mediasift Ltd |
|
5
|
|
|
* All rights reserved. |
|
6
|
|
|
* |
|
7
|
|
|
* Redistribution and use in source and binary forms, with or without |
|
8
|
|
|
* modification, are permitted provided that the following conditions |
|
9
|
|
|
* are met: |
|
10
|
|
|
* |
|
11
|
|
|
* * Redistributions of source code must retain the above copyright |
|
12
|
|
|
* notice, this list of conditions and the following disclaimer. |
|
13
|
|
|
* |
|
14
|
|
|
* * Redistributions in binary form must reproduce the above copyright |
|
15
|
|
|
* notice, this list of conditions and the following disclaimer in |
|
16
|
|
|
* the documentation and/or other materials provided with the |
|
17
|
|
|
* distribution. |
|
18
|
|
|
* |
|
19
|
|
|
* * Neither the names of the copyright holders nor the names of his |
|
20
|
|
|
* contributors may be used to endorse or promote products derived |
|
21
|
|
|
* from this software without specific prior written permission. |
|
22
|
|
|
* |
|
23
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
24
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
25
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|
26
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
27
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
|
28
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
29
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
30
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
31
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
32
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
33
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
34
|
|
|
* POSSIBILITY OF SUCH DAMAGE. |
|
35
|
|
|
* |
|
36
|
|
|
* @category Libraries |
|
37
|
|
|
* @package Storyplayer/PlayerLib |
|
38
|
|
|
* @author Stuart Herbert <[email protected]> |
|
39
|
|
|
* @copyright 2011-present Mediasift Ltd www.datasift.com |
|
40
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
41
|
|
|
* @link http://datasift.github.io/storyplayer |
|
42
|
|
|
*/ |
|
43
|
|
|
|
|
44
|
|
|
namespace DataSift\Storyplayer\PlayerLib; |
|
45
|
|
|
|
|
46
|
|
|
use Exception; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* tracks the result from a single phase |
|
50
|
|
|
* |
|
51
|
|
|
* a result is a little more than just a PASS/FAIL: |
|
52
|
|
|
* |
|
53
|
|
|
* 1. we need to know what happened during this phase |
|
54
|
|
|
* 2. we need to know how this affects the playing of the story |
|
55
|
|
|
* 3. we need to know if there are any other phases we need to execute |
|
56
|
|
|
* *because* we have executed this phase |
|
57
|
|
|
* 4. we need to know if there's a message to pass on to the end-user |
|
58
|
|
|
* |
|
59
|
|
|
* perhaps it was much easier when we just hard-coded all of this? |
|
60
|
|
|
* |
|
61
|
|
|
* @category Libraries |
|
62
|
|
|
* @package Storyplayer/PlayerLib |
|
63
|
|
|
* @author Stuart Herbert <[email protected]> |
|
64
|
|
|
* @copyright 2011-present Mediasift Ltd www.datasift.com |
|
65
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
66
|
|
|
* @link http://datasift.github.io/storyplayer |
|
67
|
|
|
*/ |
|
68
|
|
|
|
|
69
|
|
|
class Phase_Result |
|
70
|
|
|
{ |
|
71
|
|
|
protected $phaseName; |
|
72
|
|
|
protected $message; |
|
73
|
|
|
protected $nextAction; |
|
74
|
|
|
protected $result; |
|
75
|
|
|
protected $exception; |
|
76
|
|
|
|
|
77
|
|
|
public $activityLog = []; |
|
78
|
|
|
|
|
79
|
|
|
const MIN_RESULT = 1; |
|
80
|
|
|
const MAX_RESULT = 8; |
|
81
|
|
|
|
|
82
|
|
|
const COMPLETED = 1; |
|
83
|
|
|
// success is an alias for completed! |
|
84
|
|
|
const SUCCEEDED = 1; |
|
85
|
|
|
const FAILED = 2; |
|
86
|
|
|
const INCOMPLETE = 3; |
|
87
|
|
|
const ERROR = 4; |
|
88
|
|
|
const HASNOACTIONS = 5; |
|
89
|
|
|
const SKIPPED = 6; |
|
90
|
|
|
const BLACKLISTED = 7; |
|
91
|
|
|
const CANNOTRUN = 8; |
|
92
|
|
|
|
|
93
|
|
|
protected $resultTextMap = [ |
|
94
|
|
|
1 => "SUCCEEDED", |
|
95
|
|
|
2 => "FAILED", |
|
96
|
|
|
3 => "INCOMPLETE", |
|
97
|
|
|
4 => "ERROR", |
|
98
|
|
|
5 => "HASNOACTIONS", |
|
99
|
|
|
6 => "SKIPPED", |
|
100
|
|
|
7 => "BLACKLISTED", |
|
101
|
|
|
8 => "CANNOTRUN", |
|
102
|
|
|
]; |
|
103
|
|
|
|
|
104
|
|
|
public function __construct($phaseName) |
|
105
|
|
|
{ |
|
106
|
|
|
$this->phaseName = $phaseName; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @return string |
|
111
|
|
|
*/ |
|
112
|
|
|
public function getPhaseName() |
|
113
|
|
|
{ |
|
114
|
|
|
return $this->phaseName; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @return boolean |
|
119
|
|
|
*/ |
|
120
|
|
|
public function hasMessage() |
|
121
|
|
|
{ |
|
122
|
|
|
if (isset($this->message)) { |
|
123
|
|
|
return true; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
return false; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* @return string|null |
|
131
|
|
|
*/ |
|
132
|
|
|
public function getMessage() |
|
133
|
|
|
{ |
|
134
|
|
|
if (!isset($this->exception)) { |
|
135
|
|
|
return $this->message; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
// we only want stack traces if an error has occurred |
|
139
|
|
|
if ($this->result !== self::ERROR) { |
|
140
|
|
|
return $this->message; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
// if we get here, then we want the stack trace too |
|
144
|
|
|
return $this->message . PHP_EOL . $this->exception->getTraceAsString(); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* @return \Exception|null |
|
149
|
|
|
*/ |
|
150
|
|
|
public function getException() |
|
151
|
|
|
{ |
|
152
|
|
|
return $this->exception; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* @return int |
|
157
|
|
|
*/ |
|
158
|
|
|
public function getPhaseResult() |
|
159
|
|
|
{ |
|
160
|
|
|
return $this->result; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* @return string |
|
165
|
|
|
*/ |
|
166
|
|
|
public function getPhaseResultString() |
|
167
|
|
|
{ |
|
168
|
|
|
if (isset($this->resultTextMap[$this->result])) { |
|
169
|
|
|
return $this->resultTextMap[$this->result]; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
return "UNKNOWN"; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
/** |
|
176
|
|
|
* @return bool |
|
177
|
|
|
*/ |
|
178
|
|
|
public function getPhaseCompleted() |
|
179
|
|
|
{ |
|
180
|
|
|
if ($this->result == self::COMPLETED) { |
|
181
|
|
|
return true; |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
return false; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* @return bool |
|
189
|
|
|
*/ |
|
190
|
|
|
public function getPhaseSucceeded() |
|
191
|
|
|
{ |
|
192
|
|
|
if ($this->result == self::COMPLETED) { |
|
193
|
|
|
return true; |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
return false; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* @return bool |
|
201
|
|
|
*/ |
|
202
|
|
|
public function getPhaseFailed() |
|
203
|
|
|
{ |
|
204
|
|
|
if ($this->result == self::FAILED) { |
|
205
|
|
|
return true; |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
return false; |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
public function getPhaseHasErrored() |
|
212
|
|
|
{ |
|
213
|
|
|
if ($this->result == self::ERROR) { |
|
214
|
|
|
return true; |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
return false; |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
/** |
|
221
|
|
|
* @return bool |
|
222
|
|
|
*/ |
|
223
|
|
|
public function getPhaseIsIncomplete() |
|
224
|
|
|
{ |
|
225
|
|
|
if ($this->result == self::INCOMPLETE) { |
|
226
|
|
|
return true; |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
return false; |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
/** |
|
233
|
|
|
* @return bool |
|
234
|
|
|
*/ |
|
235
|
|
|
public function getPhaseHasNoActions() |
|
236
|
|
|
{ |
|
237
|
|
|
if ($this->result == self::HASNOACTIONS) { |
|
238
|
|
|
return true; |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
return false; |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* @return bool |
|
246
|
|
|
*/ |
|
247
|
|
|
public function getPhaseIsBlacklisted() |
|
248
|
|
|
{ |
|
249
|
|
|
if ($this->result == self::BLACKLISTED) { |
|
250
|
|
|
return true; |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
return false; |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
/** |
|
257
|
|
|
* @return bool |
|
258
|
|
|
*/ |
|
259
|
|
|
public function getPhaseHasBeenSkipped() |
|
260
|
|
|
{ |
|
261
|
|
|
if ($this->result == self::SKIPPED) { |
|
262
|
|
|
return true; |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
return false; |
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
|
|
/** |
|
269
|
|
|
* @return bool |
|
270
|
|
|
*/ |
|
271
|
|
|
public function getPhaseCannotRun() |
|
272
|
|
|
{ |
|
273
|
|
|
if ($this->result == self::CANNOTRUN) { |
|
274
|
|
|
return true; |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
|
|
return false; |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
/** |
|
281
|
|
|
* @return int |
|
282
|
|
|
*/ |
|
283
|
|
|
public function getNextAction() |
|
284
|
|
|
{ |
|
285
|
|
|
return $this->nextAction; |
|
286
|
|
|
} |
|
287
|
|
|
|
|
288
|
|
|
/** |
|
289
|
|
|
* @param integer $result |
|
290
|
|
|
* @param string|null $msg |
|
291
|
|
|
* @param Exception|null $e |
|
292
|
|
|
* @return void |
|
293
|
|
|
*/ |
|
294
|
|
View Code Duplication |
public function setContinuePlaying($result = 1, $msg = null, $e = null) |
|
295
|
|
|
{ |
|
296
|
|
|
$this->nextAction = PhaseGroup_Player::NEXT_CONTINUE; |
|
297
|
|
|
$this->result = $result; |
|
298
|
|
|
$this->message = $msg; |
|
299
|
|
|
$this->exception = $e; |
|
300
|
|
|
} |
|
301
|
|
|
|
|
302
|
|
|
/** |
|
303
|
|
|
* @param integer $result |
|
304
|
|
|
* @param string $msg |
|
305
|
|
|
* @param Exception|null $e |
|
306
|
|
|
* @return void |
|
307
|
|
|
*/ |
|
308
|
|
View Code Duplication |
public function setPlayingFailed($result, $msg, $e = null) |
|
309
|
|
|
{ |
|
310
|
|
|
$this->nextAction = PhaseGroup_Player::NEXT_FAIL; |
|
311
|
|
|
$this->result = $result; |
|
312
|
|
|
$this->message = $msg; |
|
313
|
|
|
$this->exception = $e; |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
|
|
/** |
|
317
|
|
|
* @param integer $result |
|
318
|
|
|
* @param string $msg |
|
319
|
|
|
* @return void |
|
320
|
|
|
*/ |
|
321
|
|
View Code Duplication |
public function setSkipPlaying($result, $msg, $e = null) |
|
322
|
|
|
{ |
|
323
|
|
|
$this->nextAction = PhaseGroup_Player::NEXT_SKIP; |
|
324
|
|
|
$this->result = $result; |
|
325
|
|
|
$this->message = $msg; |
|
326
|
|
|
$this->exception = $e; |
|
327
|
|
|
} |
|
328
|
|
|
} |
|
329
|
|
|
|