1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of NodalFlow. |
5
|
|
|
* (c) Fabrice de Stefanis / https://github.com/fab2s/NodalFlow |
6
|
|
|
* This source file is licensed under the MIT license which you will |
7
|
|
|
* find in the LICENSE file or at https://opensource.org/licenses/MIT |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace fab2s\NodalFlow\Events; |
11
|
|
|
|
12
|
|
|
use fab2s\NodalFlow\Callbacks\CallbackInterface; |
13
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class CallbackWrapper |
17
|
|
|
*/ |
18
|
|
|
class CallbackWrapper implements EventSubscriberInterface |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* The registered Callback class |
22
|
|
|
* |
23
|
|
|
* @var CallbackInterface |
24
|
|
|
*/ |
25
|
|
|
protected $callBack; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* CallbackWrapper constructor. |
29
|
|
|
* |
30
|
|
|
* @param CallbackInterface $callBack |
31
|
|
|
*/ |
32
|
|
|
public function __construct(CallbackInterface $callBack) |
33
|
|
|
{ |
34
|
|
|
$this->callBack = $callBack; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return array |
39
|
|
|
*/ |
40
|
|
|
public static function getSubscribedEvents() |
41
|
|
|
{ |
42
|
|
|
return [ |
43
|
|
|
FlowEventInterface::FLOW_START => ['start', 0], |
44
|
|
|
FlowEventInterface::FLOW_PROGRESS => ['progress', 0], |
45
|
|
|
FlowEventInterface::FLOW_SUCCESS => ['success', 0], |
46
|
|
|
FlowEventInterface::FLOW_FAIL => ['fail', 0], |
47
|
|
|
]; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Triggered when a Flow starts |
52
|
|
|
* |
53
|
|
|
* @param FlowEventInterface $event |
54
|
|
|
*/ |
55
|
|
|
public function start(FlowEventInterface $event) |
56
|
|
|
{ |
57
|
|
|
$this->callBack->start($event->getFlow()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Triggered when a Flow progresses, |
62
|
|
|
* eg exec once or generates once |
63
|
|
|
* |
64
|
|
|
* @param FlowEventInterface $event |
65
|
|
|
*/ |
66
|
|
|
public function progress(FlowEventInterface $event) |
67
|
|
|
{ |
68
|
|
|
$this->callBack->progress($event->getFlow(), /* @scrutinizer ignore-type */ $event->getNode()); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Triggered when a Flow completes without exceptions |
73
|
|
|
* |
74
|
|
|
* @param FlowEventInterface $event |
75
|
|
|
*/ |
76
|
|
|
public function success(FlowEventInterface $event) |
77
|
|
|
{ |
78
|
|
|
$this->callBack->success($event->getFlow()); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Triggered when a Flow fails |
83
|
|
|
* |
84
|
|
|
* @param FlowEventInterface $event |
85
|
|
|
*/ |
86
|
|
|
public function fail(FlowEventInterface $event) |
87
|
|
|
{ |
88
|
|
|
$this->callBack->fail($event->getFlow()); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|