cacheJwt = $cacheJwt; } public function add(array $payload): bool { if (!isset($payload['exp'])) { throw new MissingClaimException('exp'); } $expiration = new DateTimeImmutable('@' . $payload['exp'], new DateTimeZone('UTC')); $now = new DateTimeImmutable('now', new DateTimeZone('UTC')); // If the token is already expired, there's no point in adding it to storage if ($expiration <= $now) { return false; } $cacheExpiration = $expiration->add(new DateInterval('PT5M')); if (!isset($payload['jti'])) { throw new MissingClaimException('jti'); } $cacheItem = $this->cacheJwt->getItem($payload['jti']); $cacheItem->set([]); $cacheItem->expiresAt($cacheExpiration); $this->cacheJwt->save($cacheItem); return true; } public function has(array $payload): bool { if (!isset($payload['jti'])) { throw new MissingClaimException('jti'); } return $this->cacheJwt->hasItem($payload['jti']); } public function remove(array $payload): void { if (!isset($payload['jti'])) { throw new MissingClaimException('jti'); } $this->cacheJwt->deleteItem($payload['jti']); } }