|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BFW; |
|
4
|
|
|
|
|
5
|
|
|
class RunTasks extends Subjects |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* @var array[] $runSteps All steps used for run the application |
|
9
|
|
|
*/ |
|
10
|
|
|
protected $runSteps; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @var string $notifyPrefix A prefix to use for task name |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $notifyPrefix; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Constructor |
|
19
|
|
|
* |
|
20
|
|
|
* @param \stdClass[] $runSteps All step to call |
|
21
|
|
|
* @param string $notifyPrefix The prefix to use for task name |
|
22
|
|
|
*/ |
|
23
|
|
|
public function __construct($runSteps, $notifyPrefix) |
|
24
|
|
|
{ |
|
25
|
|
|
$this->runSteps = $runSteps; |
|
|
|
|
|
|
26
|
|
|
$this->notifyPrefix = $notifyPrefix; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Getter to access to the run step array |
|
31
|
|
|
* |
|
32
|
|
|
* @return array |
|
33
|
|
|
*/ |
|
34
|
|
|
public function getRunSteps() |
|
35
|
|
|
{ |
|
36
|
|
|
return $this->runSteps; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Setter to re-define the run step array |
|
41
|
|
|
* |
|
42
|
|
|
* @param \stdObject[] $runSteps The new list of run steps |
|
43
|
|
|
* |
|
44
|
|
|
* @return $this |
|
45
|
|
|
*/ |
|
46
|
|
|
public function setRunSteps($runSteps) |
|
47
|
|
|
{ |
|
48
|
|
|
$this->runSteps = $runSteps; |
|
|
|
|
|
|
49
|
|
|
return $this; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Add a new run step to the list |
|
54
|
|
|
* |
|
55
|
|
|
* @param string $name The name of the new run step |
|
56
|
|
|
* @param \stdClass $runStepsToAdd The run step to add |
|
57
|
|
|
* |
|
58
|
|
|
* @return $this |
|
59
|
|
|
*/ |
|
60
|
|
|
public function addToRunSteps($name, \stdClass $runStepsToAdd) |
|
61
|
|
|
{ |
|
62
|
|
|
$this->runSteps[(string) $name] = $runStepsToAdd; |
|
63
|
|
|
return $this; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Getter to property notifyPrefix |
|
68
|
|
|
* |
|
69
|
|
|
* @return string |
|
70
|
|
|
*/ |
|
71
|
|
|
public function getNotifyPrefix() |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->notifyPrefix; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Setter to re-define the notifyPrefix |
|
78
|
|
|
* |
|
79
|
|
|
* @param string $notifyPrefix |
|
80
|
|
|
* |
|
81
|
|
|
* @return $this |
|
82
|
|
|
*/ |
|
83
|
|
|
public function setNotifyPrefix($notifyPrefix) |
|
84
|
|
|
{ |
|
85
|
|
|
$this->notifyPrefix = (string) $notifyPrefix; |
|
86
|
|
|
return $this; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Run all steps declared and notify for each step |
|
91
|
|
|
* Call the callback if declared for each step |
|
92
|
|
|
* |
|
93
|
|
|
* @return void |
|
94
|
|
|
*/ |
|
95
|
|
|
public function run() |
|
96
|
|
|
{ |
|
97
|
|
|
$prefix = $this->notifyPrefix; |
|
98
|
|
|
|
|
99
|
|
|
$this->addNotification($prefix.'_start_run_tasks'); |
|
100
|
|
|
|
|
101
|
|
|
foreach ($this->runSteps as $actionName => $stepInfos) { |
|
102
|
|
|
$context = null; |
|
103
|
|
|
if (property_exists($stepInfos, 'context')) { |
|
104
|
|
|
$context = $stepInfos->context; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
if (!property_exists($stepInfos, 'callback')) { |
|
108
|
|
|
$this->addNotification($prefix.'_exec_'.$actionName, $context); |
|
109
|
|
|
continue; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
$this->addNotification($prefix.'_run_'.$actionName, $context); |
|
113
|
|
|
|
|
114
|
|
|
if (is_callable($stepInfos->callback)) { |
|
115
|
|
|
$callback = $stepInfos->callback; |
|
116
|
|
|
$callback(); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
$this->addNotification($prefix.'_finish_'.$actionName, $context); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
$this->addNotification($prefix.'_end_run_tasks'); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Send a notification to all observers connected to the subject |
|
127
|
|
|
* |
|
128
|
|
|
* @param string $action The action name |
|
129
|
|
|
* @param mixed $context (default null) The context to pass to the subject |
|
130
|
|
|
* |
|
131
|
|
|
* @return void |
|
132
|
|
|
*/ |
|
133
|
|
|
public function sendNotify($action, $context = null) |
|
134
|
|
|
{ |
|
135
|
|
|
$this->addNotification($action, $context); |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..