| 1: | <?php declare(strict_types=1); |
| 2: | |
| 3: | namespace Salient\Http; |
| 4: | |
| 5: | use Salient\Utility\Date; |
| 6: | use DateTimeImmutable; |
| 7: | use DateTimeInterface; |
| 8: | use InvalidArgumentException; |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | class GenericToken extends GenericCredential |
| 14: | { |
| 15: | private ?DateTimeImmutable $Expires; |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | public function __construct( |
| 25: | string $token, |
| 26: | string $authenticationScheme, |
| 27: | $expires = null |
| 28: | ) { |
| 29: | if (is_int($expires) && $expires < 0) { |
| 30: | throw new InvalidArgumentException( |
| 31: | sprintf('Invalid timestamp: %d', $expires), |
| 32: | ); |
| 33: | } |
| 34: | |
| 35: | $this->Expires = $expires instanceof DateTimeInterface |
| 36: | ? Date::immutable($expires) |
| 37: | : ($expires !== null |
| 38: | ? new DateTimeImmutable('@' . $expires) |
| 39: | : null); |
| 40: | |
| 41: | parent::__construct($token, $authenticationScheme); |
| 42: | } |
| 43: | |
| 44: | |
| 45: | |
| 46: | |
| 47: | |
| 48: | public function getExpires(): ?DateTimeImmutable |
| 49: | { |
| 50: | return $this->Expires; |
| 51: | } |
| 52: | } |
| 53: | |