52 lines
1.5 KiB
PHP
52 lines
1.5 KiB
PHP
<?php
|
|
namespace Misuzu\OAuth2;
|
|
|
|
use Carbon\CarbonImmutable;
|
|
use Index\Db\DbResult;
|
|
|
|
class OAuth2RefreshInfo {
|
|
public function __construct(
|
|
public private(set) string $id,
|
|
public private(set) string $appId,
|
|
public private(set) ?string $userId,
|
|
public private(set) ?string $accessId,
|
|
public private(set) string $token,
|
|
public private(set) string $scope,
|
|
public private(set) int $createdTime,
|
|
public private(set) int $expiresTime
|
|
) {}
|
|
|
|
public static function fromResult(DbResult $result): OAuth2RefreshInfo {
|
|
return new OAuth2RefreshInfo(
|
|
id: $result->getString(0),
|
|
appId: $result->getString(1),
|
|
userId: $result->getStringOrNull(2),
|
|
accessId: $result->getStringOrNull(3),
|
|
token: $result->getString(4),
|
|
scope: $result->getString(5),
|
|
createdTime: $result->getInteger(6),
|
|
expiresTime: $result->getInteger(7),
|
|
);
|
|
}
|
|
|
|
/** @var string[] */
|
|
public array $scopes {
|
|
get => explode(' ', $this->scope);
|
|
}
|
|
|
|
public CarbonImmutable $createdAt {
|
|
get => CarbonImmutable::createFromTimestampUTC($this->createdTime);
|
|
}
|
|
|
|
public bool $expired {
|
|
get => time() > $this->expiresTime;
|
|
}
|
|
|
|
public CarbonImmutable $expiresAt {
|
|
get => CarbonImmutable::createFromTimestampUTC($this->expiresTime);
|
|
}
|
|
|
|
public int $remainingLifetime {
|
|
get => max(0, $this->expiresTime - time());
|
|
}
|
|
}
|