class CasCommands in CAS 8
Same name and namespace in other branches
- 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'
1 service uses CasCommands
File
- src/
Commands/ CasCommands.php, line 10
Namespace
Drupal\cas\CommandsView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CasCommands:: |
public | function | Sets CAS username for an existing Drupal user. |