function UserList::getFromOptions

8.0.x UserList.php UserList::getFromOptions()
7.x UserList.php UserList::getFromOptions()
master UserList.php UserList::getFromOptions()
1 call to UserList::getFromOptions()
UserList::__construct in lib/Drush/User/UserList.php
Finds a list of user objects based on Drush arguments, or options.

File

lib/Drush/User/UserList.php, line 45

Namespace

Drush\User

Class

UserList

Code

function getFromOptions() {
  $accounts = array();
  $userversion = drush_user_get_class();
  if ($mails = _convert_csv_to_array(drush_get_option('mail'))) {
    foreach ($mails as $mail) {
      if ($account = $userversion->load_by_mail($mail)) {
        $single = drush_usersingle_get_class($account);
        $accounts[$single->id()] = $single;
      }
      else {
        throw new UserListException('Unable to find a matching user for ' . $mail . '.');
      }
    }
  }
  if ($names = _convert_csv_to_array(drush_get_option('name'))) {
    foreach ($names as $name) {
      if ($account = $userversion->load_by_name($name)) {
        $single = drush_usersingle_get_class($account);
        $accounts[$single->id()] = $single;
      }
      else {
        throw new UserListException('Unable to find a matching user for ' . $name . '.');
      }
    }
  }
  if ($userids = _convert_csv_to_array(drush_get_option('uid'))) {
    foreach ($userids as $userid) {
      if (is_numeric($userid) && $account = $userversion->load_by_uid($userid)) {
        $single = drush_usersingle_get_class($account);
        $accounts[$single->id()] = $single;
      }
      else {
        throw new UserListException('Unable to find a matching user for ' . $userid . '.');
      }
    }
  }
  return $accounts;
}