PluginProbe
Media Cloud Sync / 1.2.13
Media Cloud Sync v1.2.13
1.4.2 1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 All 36 releases
media-cloud-sync / includes / sdk / s3 / Aws / Token / Token.php

Token.php in Media Cloud Sync 1.2.13, at includes/sdk/s3/Aws/Token/Token.php

95 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Dudlewebs\WPMCS\s3\Aws\Token;
4
5 use Dudlewebs\WPMCS\s3\Aws\Identity\BearerTokenIdentity;
6 use Dudlewebs\WPMCS\s3\Aws\Token\TokenInterface;
7 /**
8 * Basic implementation of the AWS Token interface that allows callers to
9 * pass in an AWS token in the constructor.
10 */
11 class Token extends BearerTokenIdentity implements TokenInterface, \Serializable
12 {
13 protected $token;
14 protected $expires;
15 /**
16 * Constructs a new basic token object, with the specified AWS
17 * token
18 *
19 * @param string $token Security token to use
20 * @param int $expires UNIX timestamp for when the token expires
21 */
22 public function __construct($token, $expires = null)
23 {
24 $this->token = $token;
25 $this->expires = $expires;
26 }
27 /**
28 * Sets the state of a token object
29 *
30 * @param array $state array containing 'token' and 'expires'
31 */
32 public static function __set_state(array $state)
33 {
34 return new self($state['token'], $state['expires']);
35 }
36 /**
37 * @return string
38 */
39 public function getToken()
40 {
41 return $this->token;
42 }
43 /**
44 * @return int
45 */
46 public function getExpiration()
47 {
48 return $this->expires;
49 }
50 /**
51 * @return bool
52 */
53 public function isExpired()
54 {
55 return $this->expires !== null && \time() >= $this->expires;
56 }
57 /**
58 * @return array
59 */
60 public function toArray()
61 {
62 return ['token' => $this->token, 'expires' => $this->expires];
63 }
64 /**
65 * @return string
66 */
67 public function serialize()
68 {
69 return \json_encode($this->__serialize());
70 }
71 /**
72 * Sets the state of the object from serialized json data
73 */
74 public function unserialize($serialized)
75 {
76 $data = \json_decode($serialized, \true);
77 $this->__unserialize($data);
78 }
79 /**
80 * @return array
81 */
82 public function __serialize()
83 {
84 return $this->toArray();
85 }
86 /**
87 * Sets the state of this object from an array
88 */
89 public function __unserialize($data)
90 {
91 $this->token = $data['token'];
92 $this->expires = $data['expires'];
93 }
94 }
95