1 | <?php |
||
13 | class Task |
||
14 | { |
||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | private $name; |
||
19 | |||
20 | /** |
||
21 | * @var callable |
||
22 | */ |
||
23 | private $callback; |
||
24 | |||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | private $description; |
||
29 | |||
30 | /** |
||
31 | * Should we run this task locally? |
||
32 | * |
||
33 | * @var bool |
||
34 | */ |
||
35 | private $local = false; |
||
36 | |||
37 | /** |
||
38 | * Lists of hosts, roles, stages there task should be executed. |
||
39 | * |
||
40 | * @var array |
||
41 | */ |
||
42 | private $on = ['hosts' => [], 'roles' => [], 'stages' => []]; |
||
43 | |||
44 | /** |
||
45 | * List of task names to run before. |
||
46 | * |
||
47 | * @var array |
||
48 | */ |
||
49 | private $before = []; |
||
50 | |||
51 | /** |
||
52 | * List of task names to run after. |
||
53 | * |
||
54 | * @var array |
||
55 | */ |
||
56 | private $after = []; |
||
57 | |||
58 | /** |
||
59 | * Make task internal and not visible in CLI. |
||
60 | * |
||
61 | * @var bool |
||
62 | */ |
||
63 | private $private = false; |
||
64 | |||
65 | /** |
||
66 | * Mark task to run only once, of the first node from the pool |
||
67 | * |
||
68 | * @var bool |
||
69 | */ |
||
70 | private $once = false; |
||
71 | |||
72 | /** |
||
73 | * Mark if the task has run at least once |
||
74 | * |
||
75 | * @var bool |
||
76 | */ |
||
77 | private $hasRun = false; |
||
78 | |||
79 | /** |
||
80 | * Shallow task will not print execution message/finish messages. |
||
81 | * Useful for success messages and info printing. |
||
82 | * |
||
83 | * @var bool |
||
84 | */ |
||
85 | private $shallow = false; |
||
86 | |||
87 | /** |
||
88 | * @param string $name Tasks name |
||
89 | * @param callable $callback Task code |
||
90 | */ |
||
91 | 28 | public function __construct($name, callable $callback = null) |
|
96 | |||
97 | /** |
||
98 | * @param Context $context |
||
99 | */ |
||
100 | 16 | public function run(Context $context) |
|
118 | |||
119 | /** |
||
120 | * @return string |
||
121 | */ |
||
122 | 21 | public function getName() |
|
126 | |||
127 | /** |
||
128 | * @return string |
||
129 | */ |
||
130 | 17 | public function getDescription() |
|
134 | |||
135 | /** |
||
136 | * @param string $description |
||
137 | * @return $this |
||
138 | */ |
||
139 | 12 | public function desc($description) |
|
144 | |||
145 | /** |
||
146 | * Mark this task local |
||
147 | * |
||
148 | * @return $this |
||
149 | */ |
||
150 | 17 | public function local() |
|
155 | |||
156 | /** |
||
157 | * @return bool |
||
158 | */ |
||
159 | 17 | public function isLocal() |
|
163 | |||
164 | 13 | public function once() |
|
169 | |||
170 | 6 | public function isOnce() |
|
174 | |||
175 | /** |
||
176 | * @param array $hosts |
||
177 | * @return $this |
||
178 | */ |
||
179 | 2 | public function onHosts(...$hosts) |
|
184 | |||
185 | /** |
||
186 | * @param array $roles |
||
187 | * @return $this |
||
188 | */ |
||
189 | 2 | public function onRoles(...$roles) |
|
194 | |||
195 | /** |
||
196 | * @param array $stages |
||
197 | * @return $this |
||
198 | */ |
||
199 | 2 | public function onStage(...$stages) |
|
204 | |||
205 | /** |
||
206 | * Checks what task should be performed on one of hosts. |
||
207 | * |
||
208 | * @param Host[] $hosts |
||
209 | * @return bool |
||
210 | */ |
||
211 | 21 | public function shouldBePerformed(...$hosts) |
|
242 | |||
243 | /** |
||
244 | * @return boolean |
||
245 | */ |
||
246 | 17 | public function isPrivate() |
|
250 | |||
251 | /** |
||
252 | * Mark task as private |
||
253 | * |
||
254 | * @return $this |
||
255 | */ |
||
256 | 12 | public function setPrivate() |
|
261 | |||
262 | /** |
||
263 | * @param string $task |
||
264 | * |
||
265 | * @return $this |
||
266 | */ |
||
267 | 1 | public function addBefore(string $task) |
|
272 | |||
273 | /** |
||
274 | * @param string $task |
||
275 | * |
||
276 | * @return $this |
||
277 | */ |
||
278 | 1 | public function addAfter(string $task) |
|
283 | |||
284 | /** |
||
285 | * Get before tasks names. |
||
286 | * @return string[] |
||
287 | */ |
||
288 | 19 | public function getBefore() |
|
292 | |||
293 | /** |
||
294 | * Get after tasks names. |
||
295 | * @return string[] |
||
296 | */ |
||
297 | 19 | public function getAfter() |
|
301 | |||
302 | /** |
||
303 | * Sets task shallow. |
||
304 | * |
||
305 | * Shallow task will not print execution message/finish messages. |
||
306 | * |
||
307 | * @return $this |
||
308 | */ |
||
309 | 11 | public function shallow() |
|
314 | |||
315 | /** |
||
316 | * @return bool |
||
317 | */ |
||
318 | 18 | public function isShallow() |
|
322 | |||
323 | /** |
||
324 | * @internal this is used by ParallelExecutor and prevent multiple run |
||
325 | */ |
||
326 | 2 | public function setHasRun() |
|
332 | } |
||
333 |