/** * Creates authentication instance from data, previously exported using * \ForumHouse\SelectelStorageApi\Authentication\CredentialsAuthentication::exportAuthenticationData * * @param array $data Previously exported data * * @return static * @throws \Exception */ public static function createFromExported(array $data) { $absentKeys = Arr::findAbsent($data, array('authToken', 'storageUrl', 'expireAuthToken')); if (!empty($absentKeys)) { throw new \Exception("The following keys are absent in exported data: " . implode(', ', $absentKeys)); } return new static($data['authToken'], $data['storageUrl'], $data['expireAuthToken']); }
/** * Imports Selectel response headers into instance variables * * @param array $headers * * @throws UnsupportedResponseFormatException */ protected function importHeaders(array $headers) { $absentKeys = Arr::findAbsent($headers, array('X-Expire-Auth-Token', 'X-Storage-Url', 'X-Auth-Token')); if (!empty($absentKeys)) { throw new UnsupportedResponseFormatException("Authentication response has the following data absent: " . implode(', ', $absentKeys)); } $this->expireAuthToken = $headers['X-Expire-Auth-Token'][0]; $this->storageUrl = trim($headers['X-Storage-Url'][0], '/'); $this->authToken = $headers['X-Auth-Token'][0]; }