key = trim($key); $this->secret = trim($secret); $this->token = $token; $this->expires = $expires; } public static function __set_state(array $state) { return new self( $state['key'], $state['secret'], $state['token'], $state['expires'] ); } public function getAccessKeyId() { return $this->key; } public function getSecretKey() { return $this->secret; } public function getSecurityToken() { return $this->token; } public function getExpiration() { return $this->expires; } public function isExpired() { return $this->expires !== null && time() >= $this->expires; } public function toArray() { return [ 'key' => $this->key, 'secret' => $this->secret, 'token' => $this->token, 'expires' => $this->expires ]; } public function serialize() { return json_encode($this->__serialize()); } public function unserialize($serialized) { $data = json_decode($serialized, true); $this->__unserialize($data); } public function __serialize() { return $this->toArray(); } public function __unserialize($data) { $this->key = $data['key']; $this->secret = $data['secret']; $this->token = $data['token']; $this->expires = $data['expires']; } /** * Internal-only. Used when IMDS is unreachable * or returns expires credentials. * * @internal */ public function extendExpiration() { $extension = mt_rand(5, 10); $this->expires = time() + $extension * 60; $message = <<