2 namespace Robo\Collection;
5 use Robo\Contract\TaskInterface;
6 use Robo\State\StateAwareInterface;
10 * Creates a task wrapper that converts any Callable into an
11 * object that can be used directly with a task collection.
13 * It is not necessary to use this class directly; Collection will
14 * automatically wrap Callables when they are added.
16 class CallableTask implements TaskInterface
24 * @var \Robo\Contract\TaskInterface
28 public function __construct(callable $fn, TaskInterface $reference)
31 $this->reference = $reference;
35 * @return \Robo\Result
39 $result = call_user_func($this->fn, $this->getState());
40 // If the function returns no result, then count it
42 if (!isset($result)) {
43 $result = Result::success($this->reference);
45 // If the function returns a result, it must either return
46 // a \Robo\Result or an exit code. In the later case, we
47 // convert it to a \Robo\Result.
48 if (!$result instanceof Result) {
49 $result = new Result($this->reference, $result);
55 public function getState()
57 if ($this->reference instanceof StateAwareInterface) {
58 return $this->reference->getState();