1 | <?php |
||
12 | class Task |
||
13 | { |
||
14 | private $name; |
||
15 | private $callback; |
||
16 | private $description; |
||
17 | |||
18 | /** |
||
19 | * Task source file location. |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | private $sourceLocation = ''; |
||
24 | |||
25 | /** |
||
26 | * Should we run this task locally? |
||
27 | * |
||
28 | * @var bool |
||
29 | */ |
||
30 | private $local = false; |
||
31 | |||
32 | /** |
||
33 | * List of task names to run before. |
||
34 | * |
||
35 | * @var string[] |
||
36 | */ |
||
37 | private $before = []; |
||
38 | |||
39 | /** |
||
40 | * List of task names to run after. |
||
41 | * |
||
42 | * @var string[] |
||
43 | */ |
||
44 | private $after = []; |
||
45 | |||
46 | /** |
||
47 | * Make task internal and not visible in CLI. |
||
48 | * |
||
49 | * @var bool |
||
50 | */ |
||
51 | private $hidden = false; |
||
52 | |||
53 | /** |
||
54 | * Run task only once on one of hosts. |
||
55 | * |
||
56 | * @var bool |
||
57 | */ |
||
58 | private $once = false; |
||
59 | |||
60 | /** |
||
61 | * Shallow task will not print execution message/finish messages. |
||
62 | * Useful for success messages and info printing. |
||
63 | * |
||
64 | * @var bool |
||
65 | */ |
||
66 | private $shallow = false; |
||
67 | |||
68 | /** |
||
69 | * Limit parallel execution of the task. |
||
70 | * |
||
71 | * @var int|null |
||
72 | */ |
||
73 | private $limit = null; |
||
74 | |||
75 | /** |
||
76 | * @var array |
||
77 | */ |
||
78 | private $selector; |
||
79 | |||
80 | 23 | public function __construct($name, callable $callback = null) |
|
86 | |||
87 | 10 | public function run(Context $context) |
|
101 | |||
102 | 12 | public function getName() |
|
106 | |||
107 | 2 | public function __toString() |
|
111 | |||
112 | 10 | public function getDescription() |
|
116 | |||
117 | 20 | public function desc(string $description) |
|
122 | |||
123 | 8 | public function getSourceLocation(): string |
|
127 | |||
128 | 19 | public function saveSourceLocation() |
|
135 | |||
136 | /** |
||
137 | * Mark this task local. |
||
138 | */ |
||
139 | 1 | public function local() |
|
144 | |||
145 | 1 | public function isLocal() |
|
149 | |||
150 | /** |
||
151 | * Mark this task to run only once on one of hosts. |
||
152 | */ |
||
153 | 1 | public function once() |
|
158 | |||
159 | 9 | public function isOnce() |
|
163 | |||
164 | /** |
||
165 | * Mark task as hidden and not accessible from CLI. |
||
166 | * |
||
167 | * @return $this |
||
168 | */ |
||
169 | 10 | public function hidden() |
|
174 | |||
175 | 10 | public function isHidden() |
|
179 | |||
180 | 2 | public function addBefore(string $task) |
|
185 | |||
186 | 1 | public function addAfter(string $task) |
|
191 | |||
192 | 11 | public function getBefore() |
|
196 | |||
197 | 11 | public function getAfter() |
|
201 | |||
202 | /** |
||
203 | * Sets task as shallow. Shallow task will not print execution message/finish messages. |
||
204 | */ |
||
205 | 9 | public function shallow() |
|
210 | |||
211 | 8 | public function isShallow() |
|
215 | |||
216 | /** |
||
217 | * @return int|null |
||
218 | */ |
||
219 | 8 | public function getLimit(): ?int |
|
223 | |||
224 | /** |
||
225 | * @param int|null $limit |
||
226 | * @return Task |
||
227 | */ |
||
228 | public function limit(?int $limit) |
||
233 | |||
234 | public function select(string $selector) |
||
238 | |||
239 | /** |
||
240 | * @return array |
||
241 | */ |
||
242 | 9 | public function getSelector(): ?array |
|
246 | |||
247 | 6 | public function addSelector(?array $newSelector) |
|
257 | } |
||
258 |