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 there task should be executed. |
||
39 | * |
||
40 | * @var array |
||
41 | */ |
||
42 | private $on = ['hosts' => [], 'roles' => []]; |
||
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 $hidden = 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 | * Task filepath location. |
||
89 | * |
||
90 | * @var string |
||
91 | */ |
||
92 | private $filepath = ''; |
||
93 | |||
94 | /** |
||
95 | * @param string $name Tasks name |
||
96 | * @param callable $callback Task code |
||
97 | */ |
||
98 | 17 | public function __construct($name, callable $callback = null) |
|
103 | |||
104 | /** |
||
105 | * @param Context $context |
||
106 | */ |
||
107 | 3 | public function run(Context $context) |
|
125 | |||
126 | 4 | public function getName() |
|
130 | |||
131 | public function __toString() |
||
135 | |||
136 | 1 | public function getDescription() |
|
140 | |||
141 | /** |
||
142 | * @param string $description |
||
143 | * @return $this |
||
144 | */ |
||
145 | 11 | public function desc($description) |
|
150 | |||
151 | /** |
||
152 | * Mark this task local |
||
153 | * |
||
154 | * @return $this |
||
155 | */ |
||
156 | 1 | public function local() |
|
161 | |||
162 | /** |
||
163 | * @return bool |
||
164 | */ |
||
165 | 1 | public function isLocal() |
|
169 | |||
170 | 2 | public function once() |
|
175 | |||
176 | 1 | public function isOnce() |
|
180 | |||
181 | /** |
||
182 | * @param array $hosts |
||
183 | * @return $this |
||
184 | */ |
||
185 | 2 | public function onHosts(...$hosts) |
|
190 | |||
191 | /** |
||
192 | * @param array $roles |
||
193 | * @return $this |
||
194 | */ |
||
195 | 2 | public function onRoles(...$roles) |
|
200 | |||
201 | /** |
||
202 | * Checks what task should be performed on one of hosts. |
||
203 | * |
||
204 | * @param Host[] $hosts |
||
205 | * @return bool |
||
206 | */ |
||
207 | 5 | public function shouldBePerformed(...$hosts) |
|
231 | |||
232 | /** |
||
233 | * @return boolean |
||
234 | */ |
||
235 | 1 | public function isHidden() |
|
239 | |||
240 | /** |
||
241 | * Mark task as hidden |
||
242 | * |
||
243 | * @return $this |
||
244 | */ |
||
245 | 1 | public function hidden() |
|
250 | |||
251 | /** |
||
252 | * @param string $task |
||
253 | * |
||
254 | * @return $this |
||
255 | */ |
||
256 | 1 | public function addBefore(string $task) |
|
261 | |||
262 | /** |
||
263 | * @param string $task |
||
264 | * |
||
265 | * @return $this |
||
266 | */ |
||
267 | 1 | public function addAfter(string $task) |
|
272 | |||
273 | /** |
||
274 | * Get before tasks names. |
||
275 | * @return string[] |
||
276 | */ |
||
277 | 3 | public function getBefore() |
|
281 | |||
282 | /** |
||
283 | * Get after tasks names. |
||
284 | * @return string[] |
||
285 | */ |
||
286 | 3 | public function getAfter() |
|
290 | |||
291 | /** |
||
292 | * Sets task shallow. |
||
293 | * |
||
294 | * Shallow task will not print execution message/finish messages. |
||
295 | * |
||
296 | * @return $this |
||
297 | */ |
||
298 | public function shallow() |
||
303 | |||
304 | /** |
||
305 | * @return bool |
||
306 | */ |
||
307 | public function isShallow() |
||
311 | |||
312 | /** |
||
313 | * @internal this is used by ParallelExecutor and prevent multiple run |
||
314 | */ |
||
315 | public function setHasRun() |
||
321 | |||
322 | /** |
||
323 | * @return string |
||
324 | */ |
||
325 | public function getFilepath(): string |
||
329 | |||
330 | /** |
||
331 | * @param string $filepath |
||
332 | */ |
||
333 | 10 | public function setFilepath(string $filepath): void |
|
337 | } |
||
338 |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.