Example #1
0
 public function __construct(TaskInterface $task, $constructorParameters)
 {
     // TODO: If we ever want to convert the simulated task back into
     // an executable task, then we should save the wrapped task.
     $this->task = $task instanceof WrappedTaskInterface ? $task->original() : $task;
     $this->constructorParameters = $constructorParameters;
 }
Example #2
0
 /**
  * @param \Robo\Result|\Robo\Contract\TaskInterface $result
  * @param \Consolidation\AnnotatedCommand\CommandData $commandData
  *
  * @return null|\Robo\Result
  */
 public function process($result, CommandData $commandData)
 {
     if ($result instanceof TaskInterface) {
         try {
             return $result->run();
         } catch (\Exception $e) {
             return Result::fromException($result, $e);
         }
     }
 }
Example #3
0
 /**
  * Before running this task, register its rollback and completion
  * handlers on its collection. The reason this class exists is to
  * defer registration of rollback and completion tasks until 'run()' time.
  *
  * @return \Robo\Result
  */
 public function run()
 {
     if ($this->rollbackTask) {
         $this->collection->registerRollback($this->rollbackTask);
     }
     if ($this->task instanceof RollbackInterface) {
         $this->collection->registerRollback(new CallableTask([$this->task, 'rollback'], $this->task));
     }
     if ($this->task instanceof CompletionInterface) {
         $this->collection->registerCompletion(new CallableTask([$this->task, 'complete'], $this->task));
     }
     return $this->task->run();
 }
Example #4
0
 /**
  * Danger: reach through the simulated wrapper and pull out the command
  * to be executed.  This is used when using a simulated task with another
  * simulated task that runs commands, e.g. the Remote\Ssh task.  Using
  * a simulated CommandInterface task with a non-simulated task may produce
  * unexpected results (e.g. execution!).
  *
  * @return string
  *
  * @throws \Robo\Exception\TaskException
  */
 public function getCommand()
 {
     if (!$this->task instanceof CommandInterface) {
         throw new TaskException($this->task, 'Simulated task that is not a CommandInterface used as a CommandInterface.');
     }
     return $this->task->getCommand();
 }
Example #5
0
 /**
  * If there is a single task, run it; if there is a collection, run
  * all of its tasks.
  *
  * @return \Robo\Result
  */
 protected function runTasks()
 {
     if (!$this->collection && $this->currentTask) {
         return $this->currentTask->run();
     }
     return $this->getCollection()->run();
 }
Example #6
0
 /**
  * @param TaskInterface|NestedCollectionInterface|WrappedTaskInterface $task
  * @param $parentCollection
  */
 protected function setParentCollectionForTask($task, $parentCollection)
 {
     if ($task instanceof NestedCollectionInterface) {
         $task->setParentCollection($parentCollection);
     }
 }
Example #7
0
 /**
  * @param TaskInterface $task
  *
  * @return Result
  */
 private function runSilently(TaskInterface $task)
 {
     $this->suppressOutput();
     $result = $task->run();
     $this->restoreOutput();
     return $result;
 }
Example #8
0
 /**
  * Create a TaskWrapper.
  *
  * Temporary tasks are always wrapped in a TaskWrapper, as are
  * any tasks that are added to a collection.  If a temporary task
  * is added to a collection, then it is first unwrapped from its
  * TaskWrapper (via its getTask method), and then added to a
  * new TaskWrapper for the collection it is added to.
  *
  * In this way, when the TaskWrapper is finally executed, the
  * task's rollback and completion handlers will be registered on
  * whichever collection it was registered on.
  */
 public function __construct(Collection $collection, TaskInterface $task, TaskInterface $rollbackTask = null)
 {
     $this->collection = $collection;
     $this->task = $task instanceof self ? $task->getTask() : $task;
     $this->rollbackTask = $rollbackTask;
 }
Example #9
0
 /**
  * Wrap the provided task in a wrapper that will ignore
  * any errors or exceptions that may be produced.  This
  * is useful, for example, in adding optional cleanup tasks
  * at the beginning of a task collection, to remove previous
  * results which may or may not exist.
  *
  * TODO: Provide some way to specify which sort of errors
  * are ignored, so that 'file not found' may be ignored,
  * but 'permission denied' reported?
  */
 public function ignoreErrorsTaskWrapper(TaskInterface $task)
 {
     // If the task is a stack-based task, then tell it
     // to try to run all of its operations, even if some
     // of them fail.
     if ($task instanceof StackBasedTask) {
         $task->stopOnFail(false);
     }
     $ignoreErrorsInTask = function () use($task) {
         $data = [];
         try {
             $result = $this->runSubtask($task);
             $message = $result->getMessage();
             $data = $result->getData();
             $data['exitcode'] = $result->getExitCode();
         } catch (\Exception $e) {
             $message = $e->getMessage();
         }
         return Result::success($task, $message, $data);
     };
     // Wrap our ignore errors callable in a task.
     return new CallableTask($ignoreErrorsInTask, $this);
 }
 /**
  * Create a CompletionWrapper.
  *
  * Temporary tasks are always wrapped in a CompletionWrapper, as are
  * any tasks that are added to a collection.  If a temporary task
  * is added to a collection, then it is first unwrapped from its
  * CompletionWrapper (via its original() method), and then added to a
  * new CompletionWrapper for the collection it is added to.
  *
  * In this way, when the CompletionWrapper is finally executed, the
  * task's rollback and completion handlers will be registered on
  * whichever collection it was registered on.
  */
 public function __construct(Collection $collection, TaskInterface $task, TaskInterface $rollbackTask = null)
 {
     $this->collection = $collection;
     $this->task = $task instanceof WrappedTaskInterface ? $task->original() : $task;
     $this->rollbackTask = $rollbackTask;
 }