1 | <?php |
||
11 | class ClientWithCache |
||
12 | { |
||
13 | private const CACHE_DIR = '/tmp/battlerite'; |
||
14 | |||
15 | private const CACHE_PREFIX = 'battlerite-'; |
||
16 | |||
17 | private const CACHE_LIFETIME = 300; |
||
18 | |||
19 | /** |
||
20 | * @var Client |
||
21 | */ |
||
22 | private $client; |
||
23 | /** |
||
24 | * @var Cache |
||
25 | */ |
||
26 | private $cache; |
||
27 | |||
28 | 4 | public function __construct(Client $client, Cache $cache) |
|
33 | |||
34 | /** |
||
35 | * Create default API client setup with a filesystem caching layer |
||
36 | */ |
||
37 | 1 | public static function create(string $apiKey): self |
|
38 | { |
||
39 | 1 | return new self( |
|
40 | 1 | new Client( |
|
41 | 1 | new ApiClient( |
|
42 | 1 | $apiKey, |
|
43 | 1 | new GuzzleClient() |
|
44 | ) |
||
45 | ), |
||
46 | 1 | new FilesystemCache(self::CACHE_DIR, '.cache') |
|
47 | ); |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * Create default API client setup with a custom caching layer |
||
52 | */ |
||
53 | 1 | public static function createWithCache(string $apiKey, Cache $cache): self |
|
54 | { |
||
55 | 1 | return new self( |
|
56 | 1 | new Client( |
|
57 | 1 | new ApiClient( |
|
58 | 1 | $apiKey, |
|
59 | 1 | new GuzzleClient() |
|
60 | ) |
||
61 | ), |
||
62 | 1 | $cache |
|
63 | ); |
||
64 | } |
||
65 | |||
66 | 1 | public function getPlayer(string $playerId): DetailedPlayer |
|
76 | |||
77 | 1 | public function getMatch(string $matchId): DetailedMatch |
|
87 | } |
||
88 |