You are here

class UpdateTask in Lightning Core 8.3

Same name and namespace in other branches
  1. 8.5 src/UpdateTask.php \Drupal\lightning_core\UpdateTask
  2. 8 src/UpdateTask.php \Drupal\lightning_core\UpdateTask
  3. 8.2 src/UpdateTask.php \Drupal\lightning_core\UpdateTask
  4. 8.4 src/UpdateTask.php \Drupal\lightning_core\UpdateTask

Hierarchy

Expanded class hierarchy of UpdateTask

File

src/UpdateTask.php, line 8

Namespace

Drupal\lightning_core
View source
class UpdateTask {

  /**
   * The task handler.
   *
   * @var object
   */
  protected $handler;

  /**
   * The reflector for the task method.
   *
   * @var \ReflectionMethod
   */
  protected $reflector;

  /**
   * The doc block for the task method.
   *
   * @var \phpDocumentor\Reflection\DocBlock
   */
  protected $docBlock;

  /**
   * UpdateTask constructor.
   *
   * @param object $handler
   *   The task handler.
   * @param \ReflectionMethod $reflector
   *   The reflector for the task method.
   * @param \phpDocumentor\Reflection\DocBlock $doc_block
   *   The doc block for the task method.
   */
  public function __construct($handler, \ReflectionMethod $reflector, DocBlock $doc_block) {
    $this->handler = $handler;
    $this->reflector = $reflector;
    $this->docBlock = $doc_block;
  }

  /**
   * Asks for confirmation before executing the task.
   *
   * @param \Symfony\Component\Console\Style\StyleInterface $io
   *   The output style.
   *
   * @return bool
   *   TRUE if the task is confirmed, FALSE otherwise.
   */
  protected function confirm(StyleInterface $io) {
    if ($this->docBlock
      ->hasTag('ask')) {
      $tags = $this->docBlock
        ->getTagsByName('ask');
      return $io
        ->confirm(reset($tags)
        ->getDescription());
    }
    return TRUE;
  }

  /**
   * Prompts for confirmation and executes the task.
   *
   * @param \Symfony\Component\Console\Style\StyleInterface $io
   *   The console style handler.
   * @param bool $force
   *   (optional) If TRUE, the task is executed without confirmation.
   */
  public function execute(StyleInterface $io, $force = FALSE) {
    $proceed = $force ? TRUE : $this
      ->confirm($io);
    if ($proceed) {
      $this->reflector
        ->invoke($this->handler, $io);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
UpdateTask::$docBlock protected property The doc block for the task method.
UpdateTask::$handler protected property The task handler.
UpdateTask::$reflector protected property The reflector for the task method.
UpdateTask::confirm protected function Asks for confirmation before executing the task.
UpdateTask::execute public function Prompts for confirmation and executes the task.
UpdateTask::__construct public function UpdateTask constructor.