123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?php
- namespace Aws\Token;
- use Aws\Identity\BearerTokenIdentity;
- use Aws\Token\TokenInterface;
- class Token extends BearerTokenIdentity implements TokenInterface, \Serializable
- {
- protected $token;
- protected $expires;
-
- public function __construct($token, $expires = null)
- {
- $this->token = $token;
- $this->expires = $expires;
- }
-
- public static function __set_state(array $state)
- {
- return new self(
- $state['token'],
- $state['expires']
- );
- }
-
- public function getToken()
- {
- return $this->token;
- }
-
- public function getExpiration()
- {
- return $this->expires;
- }
-
- public function isExpired()
- {
- return $this->expires !== null && time() >= $this->expires;
- }
-
- public function toArray()
- {
- return [
- '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->token = $data['token'];
- $this->expires = $data['expires'];
- }
- }
|