Total Complexity | 7 |
Total Lines | 50 |
Duplicated Lines | 0 % |
Coverage | 0% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
13 | class DirectoryResponse { |
||
14 | |||
15 | use SingletonTrait; |
||
16 | |||
17 | private const _FILE = 'DirectoryResponse'; |
||
18 | |||
19 | private function __construct() {} |
||
20 | |||
21 | private $_responses = []; |
||
22 | private $_index = 0; |
||
23 | |||
24 | /** |
||
25 | * @throws Exception\InvalidResponse |
||
26 | * @throws Exception\RateLimitReached |
||
27 | * @throws Exception\ServiceUnavailable |
||
28 | */ |
||
29 | public function get() : Response\GetDirectory { |
||
30 | |||
31 | if(array_key_exists($this->_index, $this->_responses)) { |
||
32 | return $this->_responses[$this->_index]; |
||
33 | } |
||
34 | $this->_responses[$this->_index] = null; |
||
35 | |||
36 | $cacheFile = Account::getCommonKeyDirectoryPath() . self::_FILE; |
||
37 | |||
38 | if(file_exists($cacheFile) && filemtime($cacheFile) > strtotime('-2 days')) { |
||
39 | |||
40 | $rawResponse = Connector\RawResponse::getFromString(file_get_contents($cacheFile)); |
||
41 | |||
42 | try { |
||
43 | return $this->_responses[$this->_index] = new Response\GetDirectory($rawResponse); |
||
44 | |||
45 | } catch(Exception\AbstractException $e) { |
||
46 | unlink($cacheFile); |
||
47 | } |
||
48 | } |
||
49 | |||
50 | $request = new Request\GetDirectory(); |
||
51 | $response = $request->getResponse(); |
||
52 | $this->set($response); |
||
53 | |||
54 | return $response; |
||
55 | } |
||
56 | |||
57 | public function set(Response\GetDirectory $response) : void { |
||
63 | } |
||
64 | } |