PluginProbe
Media Cloud Sync / 1.4.2
Media Cloud Sync v1.4.2
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
← All changes | includes/sdk/s3/Aws/Token/TokenProvider.php +9 -10 1.2.13 → 1.4.2 View file →
@@ -2,9 +2,8 @@
2 2
3 3 namespace Dudlewebs\WPMCS\s3\Aws\Token;
4 4
5 5 use Dudlewebs\WPMCS\s3\Aws;
6 -use Dudlewebs\WPMCS\s3\Aws\Api\DateTimeResult;
7 6 use Dudlewebs\WPMCS\s3\Aws\CacheInterface;
8 7 use Dudlewebs\WPMCS\s3\Aws\Exception\TokenException;
9 8 use Dudlewebs\WPMCS\s3\GuzzleHttp\Promise;
10 9 /**
@@ -27,10 +26,10 @@
27 26 * each provider until a token is successfully returned.
28 27 */
29 28 class TokenProvider
30 29 {
30 + const ENV_PROFILE = 'AWS_PROFILE';
31 31 use ParsesIniTrait;
32 - const ENV_PROFILE = 'AWS_PROFILE';
33 32 /**
34 33 * Create a default token provider tha checks for cached a SSO token from
35 34 * the CLI
36 35 *
@@ -55,9 +54,9 @@
55 54 $defaultChain[$provider] = self::cache($defaultChain[$provider], $config['token'], 'aws_cached_' . $provider . '_token');
56 55 }
57 56 }
58 57 }
59 - return self::memoize(\call_user_func_array([TokenProvider::class, 'chain'], \array_values($defaultChain)));
58 + return self::memoize(\call_user_func_array([__CLASS__, 'chain'], \array_values($defaultChain)));
60 59 }
61 60 /**
62 61 * Create a token provider function from a static token.
63 62 *
@@ -67,9 +66,9 @@
67 66 */
68 67 public static function fromToken(TokenInterface $token)
69 68 {
70 69 $promise = Promise\Create::promiseFor($token);
71 - return function () use($promise) {
70 + return static function () use($promise) {
72 71 return $promise;
73 72 };
74 73 }
75 74 /**
@@ -83,13 +82,13 @@
83 82 {
84 83 $links = \func_get_args();
85 84 //Common use case for when aws_shared_config_files is false
86 85 if (empty($links)) {
87 - return function () {
86 + return static function () {
88 87 return Promise\Create::promiseFor(\false);
89 88 };
90 89 }
91 - return function () use($links) {
90 + return static function () use($links) {
92 91 /** @var callable $parent */
93 92 $parent = \array_shift($links);
94 93 $promise = $parent();
95 94 while ($next = \array_shift($links)) {
@@ -106,9 +105,9 @@
106 105 * @return callable
107 106 */
108 107 public static function memoize(callable $provider)
109 108 {
110 - return function () use($provider) {
109 + return static function () use($provider) {
111 110 static $result;
112 111 static $isConstant;
113 112 // Constant tokens will be returned constantly.
114 113 if ($isConstant) {
@@ -150,9 +149,9 @@
150 149 */
151 150 public static function cache(callable $provider, CacheInterface $cache, $cacheKey = null)
152 151 {
153 152 $cacheKey = $cacheKey ?: 'aws_cached_token';
154 - return function () use($provider, $cache, $cacheKey) {
153 + return static function () use($provider, $cache, $cacheKey) {
155 154 $found = $cache->get($cacheKey);
156 155 if (\is_array($found) && isset($found['token'])) {
157 156 $foundToken = $found['token'];
158 157 if ($foundToken instanceof TokenInterface) {
@@ -164,9 +163,9 @@
164 163 }
165 164 }
166 165 }
167 166 return $provider()->then(function (TokenInterface $token) use($cache, $cacheKey) {
168 - $cache->set($cacheKey, $token, null === $token->getExpiration() ? 0 : $token->getExpiration() - \time());
167 + $cache->set($cacheKey, ['token' => $token], null === $token->getExpiration() ? 0 : $token->getExpiration() - \time());
169 168 return $token;
170 169 });
171 170 };
172 171 }
@@ -204,8 +203,8 @@
204 203 * @see Aws\Token\SsoTokenProvider for $config details.
205 204 */
206 205 public static function sso($profileName, $filename, $config = [])
207 206 {
208 - $ssoClient = isset($config['ssoClient']) ? $config['ssoClient'] : null;
207 + $ssoClient = $config['ssoClient'] ?? null;
209 208 return new SsoTokenProvider($profileName, $filename, $ssoClient);
210 209 }
211 210 }