diff options
| author | David T. Sadler <davidtsadler@googlemail.com> | 2026-08-09 20:04:39 +0100 |
|---|---|---|
| committer | David T. Sadler <davidtsadler@googlemail.com> | 2026-08-09 20:04:39 +0100 |
| commit | b9c4f1dcf1333c14e2d1b67561ec7a5f955baa6e (patch) | |
| tree | 610536953be739d0778f19c90c477f080a24718a /src/TokenStorage.php | |
Diffstat (limited to 'src/TokenStorage.php')
| -rw-r--r-- | src/TokenStorage.php | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/TokenStorage.php b/src/TokenStorage.php new file mode 100644 index 0000000..d7b8db8 --- /dev/null +++ b/src/TokenStorage.php @@ -0,0 +1,34 @@ +<?php + +declare(strict_types=1); + +namespace TCB; + +final class TokenStorage +{ + public function __construct( + public string $accessToken, + public string $refreshToken, + public int $expiresOn, + private readonly string $filename, + ) {} + + static public function load(string $filename): self + { + $storage = is_readable($filename) + ? json_decode(file_get_contents($filename), true) + : []; + + return new self( + accessToken: $storage['accessToken'] ?? '', + refreshToken: $storage['refreshToken'] ?? '', + expiresOn: $storage['expiresOn'] ?? 0, + filename: $filename, + ); + } + + public function save(): void + { + file_put_contents($this->filename, json_encode($this, JSON_PRETTY_PRINT)); + } +} |
