GrumPHP\Collection\TasksCollection::filterByContext PHP Method

filterByContext() public method

public filterByContext ( GrumPHP\Task\Context\ContextInterface $context ) : TasksCollection
$context GrumPHP\Task\Context\ContextInterface
return TasksCollection
    public function filterByContext(ContextInterface $context)
    {
        return $this->filter(function (TaskInterface $task) use($context) {
            return $task->canRunInContext($context);
        });
    }

Usage Example

Exemplo n.º 1
0
 /**
  * @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));
 }
All Usage Examples Of GrumPHP\Collection\TasksCollection::filterByContext