1 | <?php |
||
17 | class CallableTask implements TaskInterface |
||
18 | { |
||
19 | /** |
||
20 | * @var callable |
||
21 | */ |
||
22 | protected $fn; |
||
23 | |||
24 | /** |
||
25 | * @var \Robo\Contract\TaskInterface |
||
26 | */ |
||
27 | protected $reference; |
||
28 | |||
29 | public function __construct(callable $fn, TaskInterface $reference) |
||
30 | { |
||
31 | $this->fn = $fn; |
||
32 | $this->reference = $reference; |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * {@inheritdoc} |
||
37 | */ |
||
38 | public function run() |
||
39 | { |
||
40 | $result = call_user_func($this->fn, $this->getState()); |
||
41 | // If the function returns no result, then count it |
||
42 | // as a success. |
||
43 | if (!isset($result)) { |
||
44 | $result = Result::success($this->reference); |
||
45 | } |
||
46 | // If the function returns a result, it must either return |
||
47 | // a \Robo\Result or an exit code. In the later case, we |
||
48 | // convert it to a \Robo\Result. |
||
49 | if (!$result instanceof Result) { |
||
50 | $result = new Result($this->reference, $result); |
||
51 | } |
||
52 | |||
53 | return $result; |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * @return \Robo\State\Data |
||
58 | */ |
||
59 | public function getState() |
||
66 | } |
||
67 |