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 $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 | 24 | public function __construct($name, callable $callback = null) |
|
96 | |||
97 | /** |
||
98 | * @param Context $context |
||
99 | */ |
||
100 | 14 | public function run(Context $context) |
|
118 | |||
119 | public function getName() |
||
123 | |||
124 | 16 | public function __toString() |
|
128 | |||
129 | public function getDescription() |
||
133 | |||
134 | /** |
||
135 | * @param string $description |
||
136 | * @return $this |
||
137 | */ |
||
138 | public function desc($description) |
||
143 | |||
144 | /** |
||
145 | * Mark this task local |
||
146 | * |
||
147 | * @return $this |
||
148 | */ |
||
149 | public function local() |
||
154 | |||
155 | /** |
||
156 | * @return bool |
||
157 | */ |
||
158 | public function isLocal() |
||
162 | |||
163 | public function once() |
||
168 | |||
169 | public function isOnce() |
||
173 | |||
174 | /** |
||
175 | * @param array $hosts |
||
176 | * @return $this |
||
177 | */ |
||
178 | public function onHosts(...$hosts) |
||
183 | |||
184 | /** |
||
185 | * @param array $roles |
||
186 | * @return $this |
||
187 | */ |
||
188 | public function onRoles(...$roles) |
||
193 | |||
194 | /** |
||
195 | * Checks what task should be performed on one of hosts. |
||
196 | * |
||
197 | * @param Host[] $hosts |
||
198 | * @return bool |
||
199 | 2 | */ |
|
200 | public function shouldBePerformed(...$hosts) |
||
224 | 1 | ||
225 | /** |
||
226 | * @return boolean |
||
227 | */ |
||
228 | 13 | public function isPrivate() |
|
232 | |||
233 | /** |
||
234 | * Mark task as private |
||
235 | 13 | * |
|
236 | 13 | * @return $this |
|
237 | */ |
||
238 | public function setPrivate() |
||
243 | |||
244 | /** |
||
245 | * @param string $task |
||
246 | 13 | * |
|
247 | * @return $this |
||
248 | 13 | */ |
|
249 | public function addBefore(string $task) |
||
254 | |||
255 | /** |
||
256 | 9 | * @param string $task |
|
257 | * |
||
258 | 9 | * @return $this |
|
259 | 9 | */ |
|
260 | public function addAfter(string $task) |
||
265 | |||
266 | /** |
||
267 | 1 | * Get before tasks names. |
|
268 | * @return string[] |
||
269 | 1 | */ |
|
270 | 1 | public function getBefore() |
|
274 | |||
275 | /** |
||
276 | * Get after tasks names. |
||
277 | * @return string[] |
||
278 | 1 | */ |
|
279 | public function getAfter() |
||
283 | |||
284 | /** |
||
285 | * Sets task shallow. |
||
286 | * |
||
287 | * Shallow task will not print execution message/finish messages. |
||
288 | 14 | * |
|
289 | * @return $this |
||
290 | 14 | */ |
|
291 | public function shallow() |
||
296 | |||
297 | 14 | /** |
|
298 | * @return bool |
||
299 | 14 | */ |
|
300 | public function isShallow() |
||
304 | |||
305 | /** |
||
306 | * @internal this is used by ParallelExecutor and prevent multiple run |
||
307 | */ |
||
308 | public function setHasRun() |
||
314 | } |
||
315 |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.