setClient($client); } public function setClient(InstanceMetadataClient $client = null) { $this->customClient = null !== $client; $this->client = $client ?: InstanceMetadataClient::factory(); } public function serialize() { $serializable = array( 'credentials' => parent::serialize(), 'customClient' => $this->customClient, ); if ($this->customClient) { $serializable['client'] = serialize($this->client); } return json_encode($serializable); } public function unserialize($value) { $serialized = json_decode($value, true); parent::unserialize($serialized['credentials']); $this->customClient = $serialized['customClient']; $this->client = $this->customClient ? unserialize($serialized['client']) : InstanceMetadataClient::factory(); } /** * Attempt to get new credentials from the instance profile * * @throws InstanceProfileCredentialsException On error */ protected function refresh() { $credentials = $this->client->getInstanceProfileCredentials(); // Expire the token 5 minutes early to pre-fetch before expiring. $this->credentials->setAccessKeyId($credentials->getAccessKeyId()) ->setSecretKey($credentials->getSecretKey()) ->setSecurityToken($credentials->getSecurityToken()) ->setExpiration($credentials->getExpiration() - 300); } }