chengkun
2025-09-05 4822304b63e1bd6327860af7f3db0133cecf167f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
namespace DoubleBreak\Spapi;
use DoubleBreak\Spapi\TokenStorageInterface;
 
class SimpleTokenStorage implements TokenStorageInterface {
 
  private $filePath;
  public function __construct($filePath)
  {
    $this->filePath = $filePath;
  }
 
 
  public function getToken($key): ?array
  {
    $content = file_get_contents($this->filePath);
 
    if ($content != '') {
      $json = json_decode($content, true);
      return $json[$key] ?? null;
    }
    return null;
  }
 
 
  public function storeToken($key, $value)
  {
 
    $json = [];
    $content = file_get_contents($this->filePath);
    if ($content != '') {
      $json = json_decode($content, true);
    }
    $json[$key] = $value;
    file_put_contents($this->filePath, json_encode($json));
 
  }
}