← All changes
|
includes/sdk/google/google/auth/src/Middleware/ScopedAccessTokenMiddleware.php
+15
-15
1.2.8
→
1.4.2
View file →
| @@ -14,13 +14,13 @@ | ||
| 14 | 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | 15 | * See the License for the specific language governing permissions and |
| 16 | 16 | * limitations under the License. |
| 17 | 17 | */ |
| 18 | -namespace Dudlewebs\WPMCS\Google\Auth\Middleware; | |
| 18 | +namespace Dudlewebs\WPMCS\GCP\Google\Auth\Middleware; | |
| 19 | 19 | |
| 20 | -use Dudlewebs\WPMCS\Google\Auth\CacheTrait; | |
| 21 | -use Dudlewebs\WPMCS\Psr\Cache\CacheItemPoolInterface; | |
| 22 | -use Dudlewebs\WPMCS\Psr\Http\Message\RequestInterface; | |
| 20 | +use Dudlewebs\WPMCS\GCP\Google\Auth\CacheTrait; | |
| 21 | +use Dudlewebs\WPMCS\GCP\Psr\Cache\CacheItemPoolInterface; | |
| 22 | +use Dudlewebs\WPMCS\GCP\Psr\Http\Message\RequestInterface; | |
| 23 | 23 | /** |
| 24 | 24 | * ScopedAccessTokenMiddleware is a Guzzle Middleware that adds an Authorization |
| 25 | 25 | * header provided by a closure. |
| 26 | 26 | * |
| @@ -48,21 +48,21 @@ | ||
| 48 | 48 | * Creates a new ScopedAccessTokenMiddleware. |
| 49 | 49 | * |
| 50 | 50 | * @param callable $tokenFunc a token generator function |
| 51 | 51 | * @param array<string>|string $scopes the token authentication scopes |
| 52 | - * @param array<mixed> $cacheConfig configuration for the cache when it's present | |
| 53 | - * @param CacheItemPoolInterface $cache an implementation of CacheItemPoolInterface | |
| 52 | + * @param array<mixed>|null $cacheConfig configuration for the cache when it's present | |
| 53 | + * @param CacheItemPoolInterface|null $cache an implementation of CacheItemPoolInterface | |
| 54 | 54 | */ |
| 55 | - public function __construct(callable $tokenFunc, $scopes, array $cacheConfig = null, CacheItemPoolInterface $cache = null) | |
| 55 | + public function __construct(callable $tokenFunc, $scopes, ?array $cacheConfig = null, ?CacheItemPoolInterface $cache = null) | |
| 56 | 56 | { |
| 57 | 57 | $this->tokenFunc = $tokenFunc; |
| 58 | - if (!(is_string($scopes) || is_array($scopes))) { | |
| 58 | + if (!(\is_string($scopes) || \is_array($scopes))) { | |
| 59 | 59 | throw new \InvalidArgumentException('wants scope should be string or array'); |
| 60 | 60 | } |
| 61 | 61 | $this->scopes = $scopes; |
| 62 | - if (!is_null($cache)) { | |
| 62 | + if (!\is_null($cache)) { | |
| 63 | 63 | $this->cache = $cache; |
| 64 | - $this->cacheConfig = array_merge(['lifetime' => self::DEFAULT_CACHE_LIFETIME, 'prefix' => ''], $cacheConfig); | |
| 64 | + $this->cacheConfig = \array_merge(['lifetime' => self::DEFAULT_CACHE_LIFETIME, 'prefix' => ''], $cacheConfig); | |
| 65 | 65 | } |
| 66 | 66 | } |
| 67 | 67 | /** |
| 68 | 68 | * Updates the request with an Authorization header when auth is 'scoped'. |
| @@ -97,9 +97,9 @@ | ||
| 97 | 97 | * @return \Closure |
| 98 | 98 | */ |
| 99 | 99 | public function __invoke(callable $handler) |
| 100 | 100 | { |
| 101 | - return function (RequestInterface $request, array $options) use ($handler) { | |
| 101 | + return function (RequestInterface $request, array $options) use($handler) { | |
| 102 | 102 | // Requests using "auth"="scoped" will be authorized. |
| 103 | 103 | if (!isset($options['auth']) || $options['auth'] !== 'scoped') { |
| 104 | 104 | return $handler($request, $options); |
| 105 | 105 | } |
| @@ -112,12 +112,12 @@ | ||
| 112 | 112 | */ |
| 113 | 113 | private function getCacheKey() |
| 114 | 114 | { |
| 115 | 115 | $key = null; |
| 116 | - if (is_string($this->scopes)) { | |
| 116 | + if (\is_string($this->scopes)) { | |
| 117 | 117 | $key .= $this->scopes; |
| 118 | - } elseif (is_array($this->scopes)) { | |
| 119 | - $key .= implode(':', $this->scopes); | |
| 118 | + } elseif (\is_array($this->scopes)) { | |
| 119 | + $key .= \implode(':', $this->scopes); | |
| 120 | 120 | } |
| 121 | 121 | return $key; |
| 122 | 122 | } |
| 123 | 123 | /** |
| @@ -132,9 +132,9 @@ | ||
| 132 | 132 | $cached = $this->getCachedValue($cacheKey); |
| 133 | 133 | if (!empty($cached)) { |
| 134 | 134 | return $cached; |
| 135 | 135 | } |
| 136 | - $token = call_user_func($this->tokenFunc, $this->scopes); | |
| 136 | + $token = \call_user_func($this->tokenFunc, $this->scopes); | |
| 137 | 137 | $this->setCachedValue($cacheKey, $token); |
| 138 | 138 | return $token; |
| 139 | 139 | } |
| 140 | 140 | } |