1 | <?php |
||
10 | class Task |
||
11 | { |
||
12 | /** |
||
13 | * @var string |
||
14 | */ |
||
15 | private $name; |
||
16 | |||
17 | /** |
||
18 | * Task code. |
||
19 | * @var callable |
||
20 | */ |
||
21 | private $callback; |
||
22 | |||
23 | /** |
||
24 | * Task description. |
||
25 | * @var string |
||
26 | */ |
||
27 | private $description; |
||
28 | |||
29 | /** |
||
30 | * Should run this task only once and locally? |
||
31 | * @var bool |
||
32 | */ |
||
33 | private $once = false; |
||
34 | |||
35 | /** |
||
36 | * List of stages in which this task should be executed. |
||
37 | * @var array Key contains stage names. |
||
38 | */ |
||
39 | private $onlyForStage = []; |
||
40 | |||
41 | /** |
||
42 | * List of servers names there this task should be executed. |
||
43 | * @var array Key contains server names. |
||
44 | */ |
||
45 | private $onlyOn = []; |
||
46 | |||
47 | /** |
||
48 | * List of task names to run before. |
||
49 | * @var array |
||
50 | */ |
||
51 | private $before = []; |
||
52 | |||
53 | /** |
||
54 | * List of task names to run after. |
||
55 | * @var array |
||
56 | */ |
||
57 | 20 | private $after = []; |
|
58 | |||
59 | 20 | /** |
|
60 | 20 | * Make task internal and not visible in CLI. |
|
61 | 20 | * @var bool |
|
62 | */ |
||
63 | private $private = false; |
||
64 | |||
65 | /** |
||
66 | * @param string $name Tasks name |
||
67 | * @param callable $callback Task code. |
||
68 | 16 | */ |
|
69 | public function __construct($name, callable $callback = null) |
||
74 | 16 | ||
75 | 15 | /** |
|
76 | 15 | * Run task. |
|
77 | * |
||
78 | * @param Context $context |
||
79 | 16 | */ |
|
80 | public function run(Context $context) |
||
100 | 15 | ||
101 | /** |
||
102 | 15 | * @return string |
|
103 | */ |
||
104 | public function getName() |
||
108 | |||
109 | /** |
||
110 | 15 | * @return string |
|
111 | */ |
||
112 | 15 | public function getDescription() |
|
116 | |||
117 | /** |
||
118 | * Set task description. |
||
119 | * @param string $description |
||
120 | 16 | * @return Task |
|
121 | */ |
||
122 | 16 | public function desc($description) |
|
127 | |||
128 | /** |
||
129 | 16 | * Set this task local and run only once. |
|
130 | * @return Task |
||
131 | 16 | */ |
|
132 | public function once() |
||
137 | |||
138 | 2 | /** |
|
139 | * @return bool |
||
140 | 2 | */ |
|
141 | 2 | public function isOnce() |
|
145 | |||
146 | /** |
||
147 | * @param array|string $servers |
||
148 | * @return Task |
||
149 | */ |
||
150 | 4 | public function onlyOn($servers = []) |
|
155 | |||
156 | /** |
||
157 | * Indicate for which stages this task should be run. |
||
158 | * |
||
159 | 1 | * @param array|string $stages |
|
160 | * @return Task |
||
161 | 1 | */ |
|
162 | public function onlyForStage($stages = []) |
||
167 | 16 | ||
168 | /** |
||
169 | 16 | * @return array |
|
170 | */ |
||
171 | public function getOnlyOn() |
||
175 | |||
176 | /** |
||
177 | 3 | * @return array |
|
178 | */ |
||
179 | 3 | public function getOnlyForStage() |
|
183 | |||
184 | /** |
||
185 | * Decide to run or not to run for these stages. |
||
186 | * @param $stages |
||
187 | * @return bool |
||
188 | */ |
||
189 | public function isForStages($stages) |
||
197 | |||
198 | /** |
||
199 | * Decide to run or not to run on this server. |
||
200 | * @param string $serverName |
||
201 | * @return bool |
||
202 | */ |
||
203 | 15 | public function isOnServer($serverName) |
|
211 | |||
212 | 15 | /** |
|
213 | * @return boolean |
||
214 | 15 | */ |
|
215 | 15 | public function isPrivate() |
|
219 | |||
220 | /** |
||
221 | * Mark task as private. |
||
222 | * @return Task |
||
223 | */ |
||
224 | public function setPrivate() |
||
229 | |||
230 | /** |
||
231 | * @param string $task |
||
232 | */ |
||
233 | public function addBefore($task) |
||
237 | |||
238 | /** |
||
239 | * @param string $task |
||
240 | */ |
||
241 | public function addAfter($task) |
||
245 | |||
246 | /** |
||
247 | * Get before tasks names. |
||
248 | * @return string[] |
||
249 | */ |
||
250 | public function getBefore() |
||
254 | |||
255 | /** |
||
256 | * Get after tasks names. |
||
257 | * @return string[] |
||
258 | */ |
||
259 | public function getAfter() |
||
263 | } |
||
264 |