Cache
5 days ago
CredentialSource
5 days ago
Credentials
5 days ago
HttpHandler
5 days ago
Middleware
5 days ago
AccessToken.php
5 days ago
ApplicationDefaultCredentials.php
5 days ago
CacheTrait.php
5 days ago
CredentialsLoader.php
5 days ago
ExternalAccountCredentialSourceInterface.php
5 days ago
FetchAuthTokenCache.php
5 days ago
FetchAuthTokenInterface.php
5 days ago
GCECache.php
5 days ago
GetQuotaProjectInterface.php
5 days ago
GetUniverseDomainInterface.php
5 days ago
Iam.php
5 days ago
IamSignerTrait.php
5 days ago
OAuth2.php
5 days ago
ProjectIdProviderInterface.php
5 days ago
ServiceAccountSignerTrait.php
5 days ago
SignBlobInterface.php
5 days ago
UpdateMetadataInterface.php
5 days ago
UpdateMetadataTrait.php
5 days ago
CacheTrait.php
97 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * Copyright 2015 Google Inc. |
| 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | */ |
| 18 | namespace WPMailSMTP\Vendor\Google\Auth; |
| 19 | |
| 20 | use WPMailSMTP\Vendor\Psr\Cache\CacheItemPoolInterface; |
| 21 | trait CacheTrait |
| 22 | { |
| 23 | /** |
| 24 | * @var int |
| 25 | */ |
| 26 | private $maxKeyLength = 64; |
| 27 | /** |
| 28 | * @var array<mixed> |
| 29 | */ |
| 30 | private $cacheConfig; |
| 31 | /** |
| 32 | * @var ?CacheItemPoolInterface |
| 33 | */ |
| 34 | private $cache; |
| 35 | /** |
| 36 | * Gets the cached value if it is present in the cache when that is |
| 37 | * available. |
| 38 | * |
| 39 | * @param mixed $k |
| 40 | * |
| 41 | * @return mixed |
| 42 | */ |
| 43 | private function getCachedValue($k) |
| 44 | { |
| 45 | if (\is_null($this->cache)) { |
| 46 | return null; |
| 47 | } |
| 48 | $key = $this->getFullCacheKey($k); |
| 49 | if (\is_null($key)) { |
| 50 | return null; |
| 51 | } |
| 52 | $cacheItem = $this->cache->getItem($key); |
| 53 | if ($cacheItem->isHit()) { |
| 54 | return $cacheItem->get(); |
| 55 | } |
| 56 | } |
| 57 | /** |
| 58 | * Saves the value in the cache when that is available. |
| 59 | * |
| 60 | * @param mixed $k |
| 61 | * @param mixed $v |
| 62 | * @return mixed |
| 63 | */ |
| 64 | private function setCachedValue($k, $v) |
| 65 | { |
| 66 | if (\is_null($this->cache)) { |
| 67 | return null; |
| 68 | } |
| 69 | $key = $this->getFullCacheKey($k); |
| 70 | if (\is_null($key)) { |
| 71 | return null; |
| 72 | } |
| 73 | $cacheItem = $this->cache->getItem($key); |
| 74 | $cacheItem->set($v); |
| 75 | $cacheItem->expiresAfter($this->cacheConfig['lifetime']); |
| 76 | return $this->cache->save($cacheItem); |
| 77 | } |
| 78 | /** |
| 79 | * @param null|string $key |
| 80 | * @return null|string |
| 81 | */ |
| 82 | private function getFullCacheKey($key) |
| 83 | { |
| 84 | if (\is_null($key)) { |
| 85 | return null; |
| 86 | } |
| 87 | $key = $this->cacheConfig['prefix'] . $key; |
| 88 | // ensure we do not have illegal characters |
| 89 | $key = \preg_replace('|[^a-zA-Z0-9_\\.!]|', '', $key); |
| 90 | // Hash keys if they exceed $maxKeyLength (defaults to 64) |
| 91 | if ($this->maxKeyLength && \strlen($key) > $this->maxKeyLength) { |
| 92 | $key = \substr(\hash('sha256', $key), 0, $this->maxKeyLength); |
| 93 | } |
| 94 | return $key; |
| 95 | } |
| 96 | } |
| 97 |