filterByContext() public méthode

public filterByContext ( GrumPHP\Task\Context\ContextInterface $context ) : TasksCollection
$context GrumPHP\Task\Context\ContextInterface
Résultat TasksCollection
Exemple #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));
 }
Exemple #2
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);
     foreach ($tasks as $task) {
         try {
             $task->run($context);
         } catch (RuntimeException $e) {
             $failures = true;
             $messages[] = $e->getMessage();
         }
     }
     if ($failures) {
         throw new FailureException(implode(PHP_EOL, $messages));
     }
 }
Exemple #3
0
 /**
  * @param ContextInterface $context
  *
  * @return TaskResultCollection
  */
 public function run(ContextInterface $context)
 {
     $tasks = $this->tasks->filterByContext($context)->sortByPriority($this->grumPHP);
     $taskResults = new TaskResultCollection();
     $this->eventDispatcher->dispatch(RunnerEvents::RUNNER_RUN, new RunnerEvent($tasks, $context, $taskResults));
     foreach ($tasks as $task) {
         try {
             $taskResult = $this->runTask($task, $context);
         } catch (RuntimeException $e) {
             $taskResult = TaskResult::createFailed($task, $context, $e->getMessage());
         }
         $taskResults->add($taskResult);
         if (!$taskResult->isPassed() && $taskResult->isBlocking() && $this->grumPHP->stopOnFailure()) {
             break;
         }
     }
     if ($taskResults->isFailed()) {
         $this->eventDispatcher->dispatch(RunnerEvents::RUNNER_FAILED, new RunnerFailedEvent($tasks, $context, $taskResults));
         return $taskResults;
     }
     $this->eventDispatcher->dispatch(RunnerEvents::RUNNER_COMPLETE, new RunnerEvent($tasks, $context, $taskResults));
     return $taskResults;
 }