Platformsh\Cli\Api::getAccount PHP Method

getAccount() public method

Get a user's account info.
public getAccount ( Platformsh\Client\Model\ProjectAccess $user, boolean $reset = false ) : array
$user Platformsh\Client\Model\ProjectAccess
$reset boolean
return array An array containing 'email' and 'display_name'.
    public function getAccount(ProjectAccess $user, $reset = false)
    {
        $cacheKey = 'account:' . $user->id;
        if ($reset || !($details = self::$cache->fetch($cacheKey))) {
            $details = $user->getAccount()->getProperties();
            self::$cache->save($cacheKey, $details, $this->config->get('api.users_ttl'));
        }
        return $details;
    }

Usage Example

 /**
  * Get a list of user email addresses.
  *
  * @return string[]
  */
 public function getUserEmails()
 {
     $project = $this->getProject();
     if (!$project) {
         return [];
     }
     $emails = [];
     foreach ($project->getUsers() as $user) {
         $account = $this->api->getAccount($user);
         $emails[] = $account['email'];
     }
     return $emails;
 }