public function filterByContext(ContextInterface $context) { return $this->filter(function (TaskInterface $task) use($context) { return $task->canRunInContext($context); }); }
/** * @param ContextInterface $context * * @throws FailureException if any of the tasks fail */ public function run(ContextInterface $context) { $failures = false; $messages = array(); $tasks = $this->tasks->filterByContext($context)->sortByPriority($this->grumPHP); $this->eventDispatcher->dispatch(RunnerEvents::RUNNER_RUN, new RunnerEvent($tasks)); foreach ($tasks as $task) { try { $this->eventDispatcher->dispatch(TaskEvents::TASK_RUN, new TaskEvent($task)); $task->run($context); $this->eventDispatcher->dispatch(TaskEvents::TASK_COMPLETE, new TaskEvent($task)); } catch (RuntimeException $e) { $this->eventDispatcher->dispatch(TaskEvents::TASK_FAILED, new TaskFailedEvent($task, $e)); $messages[] = $e->getMessage(); $failures = true; if ($this->grumPHP->stopOnFailure()) { break; } } } if ($failures) { $this->eventDispatcher->dispatch(RunnerEvents::RUNNER_FAILED, new RunnerFailedEvent($tasks, $messages)); throw new FailureException(implode(PHP_EOL, $messages)); } $this->eventDispatcher->dispatch(RunnerEvents::RUNNER_COMPLETE, new RunnerEvent($tasks)); }