/** * Add the results from the most recent task to the accumulated * results from all tasks that have run so far, merging data * as necessary. */ public function accumulateResults($key, Result $result, Result $taskResult) { // If the result is not set or is not a Result, then ignore it if (isset($result) && $result instanceof Result) { // If the task is unnamed, then all of its data elements // just get merged in at the top-level of the final Result object. if (static::isUnnamedTask($key)) { $result->merge($taskResult); } elseif (isset($result[$key])) { // There can only be one task with a given name; however, if // there are tasks added 'before' or 'after' the named task, // then the results from these will be stored under the same // name unless they are given a name of their own when added. $current = $result[$key]; $result[$key] = $taskResult->merge($current); } else { $result[$key] = $taskResult; } } return $result; }
/** * {@inheritdoc} */ public function run() { $finalResult = Result::success($this); $this->startProgressIndicator(); foreach ($this->iterable as $key => $value) { $this->showIterationMessage($key, $value); try { foreach ($this->functionStack as $fn) { $result = call_user_func($fn, $key, $value); $this->advanceProgressIndicator(); if (!isset($result)) { $result = Result::success($this); } // If the function returns a result, it must either return // a \Robo\Result or an exit code. In the later case, we // convert it to a \Robo\Result. if (!$result instanceof Result) { $result = new Result($this, $result); } if (!$result->wasSuccessful()) { return $result; } $finalResult = $result->merge($finalResult); } } catch (\Exception $e) { return Result::fromException($result, $e); } } $this->stopProgressIndicator(); return $finalResult; }