You are here

class InstallCommand in CKEditor Media Embed Plugin 8

Same name in this branch
  1. 8 src/Command/InstallCommand.php \Drupal\ckeditor_media_embed\Command\InstallCommand
  2. 8 src/Command/Drush/InstallCommand.php \Drupal\ckeditor_media_embed\Command\Drush\InstallCommand

Class InstallCommand.

Hierarchy

Expanded class hierarchy of InstallCommand

1 string reference to 'InstallCommand'
drush.services.yml in ./drush.services.yml
drush.services.yml
1 service uses InstallCommand
ckeditor_media_embed_install in ./drush.services.yml
Drupal\ckeditor_media_embed\Command\Drush\InstallCommand

File

src/Command/Drush/InstallCommand.php, line 15

Namespace

Drupal\ckeditor_media_embed\Command\Drush
View source
class InstallCommand implements CKEditorCliCommandInterface {

  /**
   * The CKEditor Media Embed CLI Commands service.
   *
   * @var \Drupal\ckeditor_media_embed\CLICommands
   */
  protected $cliCommands;

  /**
   * The messages displayed to the user at various steps of the installation.
   *
   * @var string[]
   */
  protected $messages;

  /**
   * Constructs command object.
   *
   * @param \Drupal\ckeditor_media_embed\Command\CliCommandWrapper $cli_commands
   *   The CKEditor Media Embed CLI Commands service.
   */
  public function __construct(CliCommandWrapper $cli_commands) {
    $this->cliCommands = $cli_commands;
    $this
      ->setMessages();
  }

  /**
   * Executes the command.
   *
   * @param \Symfony\Component\Console\Input\InputInterface $input
   *   An InputInterface instance.
   * @param \Symfony\Component\Console\Output\OutputInterface $output
   *   An OutputInterface instance.
   * @param \Drush\Style\DrushStyle $io
   *   The Drush i/o object.
   */
  public function execute(InputInterface $input, OutputInterface $output, DrushStyle $io) {
    $this->input = $input;
    $this->output = $output;
    $this->io = $io;
    $overwrite = $this->cliCommands
      ->askToOverwritePluginFiles($this);
    if ($overwrite) {
      $this->cliCommands
        ->overwritePluginFiles($this, $overwrite);
    }
  }

  /**
   * Set messages to display to the user at various steps of the installation.
   *
   * @return $this
   */
  protected function setMessages() {
    $messages_file = \Drupal::service('module_handler')
      ->getModule('ckeditor_media_embed')
      ->getPath() . '/console/translations/en/ckeditor_media_embed.install.yml';
    $messages = Yaml::decode(file_get_contents($messages_file))['messages'];
    $this->messages = array_map(function ($message) {
      return dt($message);
    }, $messages);
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getInput() {
    return $this->input;
  }

  /**
   * {@inheritdoc}
   */
  public function getIo() {
    return $this->io;
  }

  /**
   * {@inheritdoc}
   */
  public function getMessage($message_key) {
    return $this->messages[$message_key];
  }

  /**
   * {@inheritdoc}
   */
  public function confirmation($question, $default = FALSE) {
    return $this->io
      ->confirm($question, $default);
  }

  /**
   * {@inheritdoc}
   */
  public function comment($text) {
    $this->io
      ->text(sprintf('<comment>%s</comment>', $text));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
InstallCommand::$cliCommands protected property The CKEditor Media Embed CLI Commands service.
InstallCommand::$messages protected property The messages displayed to the user at various steps of the installation.
InstallCommand::comment public function Output message in comment style. Overrides CKEditorCliCommandInterface::comment
InstallCommand::confirmation public function Present confirmation question to user. Overrides CKEditorCliCommandInterface::confirmation
InstallCommand::execute public function Executes the command.
InstallCommand::getInput public function Retrieve the command input service. Overrides CKEditorCliCommandInterface::getInput
InstallCommand::getIo public function Retrieve the i/o style. Overrides CKEditorCliCommandInterface::getIo
InstallCommand::getMessage public function Retrieve message text. Overrides CKEditorCliCommandInterface::getMessage
InstallCommand::setMessages protected function Set messages to display to the user at various steps of the installation.
InstallCommand::__construct public function Constructs command object.