You are here

class CasCommands in CAS 8

Same name and namespace in other branches
  1. 2.x src/Commands/CasCommands.php \Drupal\cas\Commands\CasCommands

Drush command file for CAS commands.

Hierarchy

  • class \Drupal\cas\Commands\CasCommands extends \Drush\Commands\DrushCommands

Expanded class hierarchy of CasCommands

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

File

src/Commands/CasCommands.php, line 10

Namespace

Drupal\cas\Commands
View source
class CasCommands extends DrushCommands {

  /**
   * Sets CAS username for an existing Drupal user.
   *
   * @param string $drupalUsername
   *   The drupal user name of the user to modify.
   * @param string $casUsername
   *   The CAS username to assign to the user.
   *
   * @usage cas:set-cas-username foo bar
   *   Assigns the CAS username of "bar" to the Drupal user with name "foo"
   *
   * @command cas:set-cas-username
   */
  public function setCasUsername($drupalUsername, $casUsername) {
    $account = user_load_by_name($drupalUsername);
    if ($account) {
      $casUserManager = \Drupal::service('cas.user_manager');
      $casUserManager
        ->setCasUsernameForAccount($account, $casUsername);
      $this->logger
        ->success(dt('Assigned CAS username "!casUsername" to user "!drupalUsername"', [
        '!casUsername' => $casUsername,
        '!drupalUsername' => $drupalUsername,
      ]));
    }
    else {
      $this->logger
        ->error(dt('Unable to load user: !user', [
        '!user' => $drupalUsername,
      ]));
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CasCommands::setCasUsername public function Sets CAS username for an existing Drupal user.