You are here

class WardenCommands in Warden 8

Same name and namespace in other branches
  1. 8.2 src/Commands/WardenCommands.php \Drupal\warden\Commands\WardenCommands
  2. 3.x src/Commands/WardenCommands.php \Drupal\warden\Commands\WardenCommands

A Drush commandfile.

In addition to this file, you need a drush.services.yml in root of your module, and a composer.json file that provides the name of the services file to use.

See these files for an example of injecting Drupal services:

Hierarchy

  • class \Drupal\warden\Commands\WardenCommands extends \Drush\Commands\DrushCommands

Expanded class hierarchy of WardenCommands

1 string reference to 'WardenCommands'
drush.services.yml in ./drush.services.yml
drush.services.yml
1 service uses WardenCommands
warden.commands in ./drush.services.yml
\Drupal\warden\Commands\WardenCommands

File

src/Commands/WardenCommands.php, line 18

Namespace

Drupal\warden\Commands
View source
class WardenCommands extends DrushCommands {

  /**
   * Test the connection to Warden by getting its public key
   *
   *
   * @command warden:check
   * @aliases warden-check
   */
  public function check() {
    try {
      $warden = \Drupal::service('warden.manager');
      drush_print(dt('URL: :url', [
        ':url' => $warden
          ->getWardenUrl(),
      ]));
      if ($warden
        ->hasBasicAuthentication()) {
        drush_print(dt('HTTP Username: :username', [
          ':username' => $warden
            ->getUsername(),
        ]));
        drush_print(dt('HTTP Password: :password', [
          ':password' => $warden
            ->getPassword(),
        ]));
      }
      if ($warden
        ->hasCertificatePath()) {
        drush_print(dt('Certificate file: :path', [
          ':path' => $warden
            ->getCertificatePath(),
        ]));
      }
      $key = $warden
        ->getPublicKey();
      drush_print(dt('Going to check connection to Warden server by retrieving the public key ...'));
      drush_print($key);
    } catch (Exception $e) {
      drush_set_error($e
        ->getMessage());
    }
  }

  /**
   * Update Warden with the lastest site data
   *
   *
   * @command warden:update
   * @aliases warden-update
   */
  public function update() {
    drush_print(dt('Going to update Warden ...'));
    try {
      $warden_manager = \Drupal::service('warden.manager');
      $warden_manager
        ->updateWarden();
      drush_print(dt('... success'));
    } catch (Exception $e) {
      return drush_set_error($e
        ->getMessage());
    }
  }

  /**
   * Displays the module data that will be sent to Warden
   *
   *
   * @command warden:show-module-data
   * @aliases warden-show-module-data
   */
  public function showModuleData() {
    module_load_include('inc', 'warden', 'warden.page');
    $warden_manager = \Drupal::service('warden.manager');
    $data = $warden_manager
      ->generateSiteData();
    $this
      ->output()
      ->writeln($data);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
WardenCommands::check public function Test the connection to Warden by getting its public key
WardenCommands::showModuleData public function Displays the module data that will be sent to Warden
WardenCommands::update public function Update Warden with the lastest site data