@@ -21,11 +21,17 @@ discard block |
||
21 | 21 | |
22 | 22 | } |
23 | 23 | |
24 | + /** |
|
25 | + * @param string $name |
|
26 | + */ |
|
24 | 27 | function setCache($name,$data){ |
25 | 28 | $this->writeFile($name,json_encode($data)); |
26 | 29 | return $data; |
27 | 30 | } |
28 | 31 | |
32 | + /** |
|
33 | + * @param string $name |
|
34 | + */ |
|
29 | 35 | function getCache($name, $expire=null){ |
30 | 36 | if(!is_null($expire)){ |
31 | 37 | $this->expire = $expire; |
@@ -44,6 +50,9 @@ discard block |
||
44 | 50 | return false; |
45 | 51 | } |
46 | 52 | |
53 | + /** |
|
54 | + * @param string $content |
|
55 | + */ |
|
47 | 56 | function writeFile($name, $content){ |
48 | 57 | try { |
49 | 58 | if(!is_dir($this->cache_path)) { |
@@ -13,52 +13,52 @@ |
||
13 | 13 | |
14 | 14 | function __construct() |
15 | 15 | { |
16 | - $this->cache_path = defined('CACHE_DIR')?CACHE_DIR:sys_get_temp_dir(); |
|
17 | - $this->expire = defined('CACHE_EXPIRE')?CACHE_EXPIRE:'3600'; |
|
16 | + $this->cache_path = defined('CACHE_DIR') ?CACHE_DIR:sys_get_temp_dir(); |
|
17 | + $this->expire = defined('CACHE_EXPIRE') ?CACHE_EXPIRE:'3600'; |
|
18 | 18 | } |
19 | 19 | |
20 | - function cache(){ |
|
20 | + function cache() { |
|
21 | 21 | |
22 | 22 | } |
23 | 23 | |
24 | - function setCache($name,$data){ |
|
25 | - $this->writeFile($name,json_encode($data)); |
|
24 | + function setCache($name, $data) { |
|
25 | + $this->writeFile($name, json_encode($data)); |
|
26 | 26 | return $data; |
27 | 27 | } |
28 | 28 | |
29 | - function getCache($name, $expire=null){ |
|
30 | - if(!is_null($expire)){ |
|
29 | + function getCache($name, $expire = null) { |
|
30 | + if (!is_null($expire)) { |
|
31 | 31 | $this->expire = $expire; |
32 | 32 | } |
33 | 33 | |
34 | 34 | $cached = $this->readFile($name); |
35 | 35 | |
36 | - if($cached !== false){ |
|
36 | + if ($cached !== false) { |
|
37 | 37 | $data = json_decode($cached, true); |
38 | 38 | $cache_time = $data['server_time']; |
39 | 39 | $now_time = time(); |
40 | - if($now_time >= $cache_time && $now_time <= ($cache_time + $this->expire)){ |
|
40 | + if ($now_time >= $cache_time && $now_time <= ($cache_time + $this->expire)) { |
|
41 | 41 | return $data; |
42 | 42 | } |
43 | 43 | } |
44 | 44 | return false; |
45 | 45 | } |
46 | 46 | |
47 | - function writeFile($name, $content){ |
|
47 | + function writeFile($name, $content) { |
|
48 | 48 | try { |
49 | - if(!is_dir($this->cache_path)) { |
|
49 | + if (!is_dir($this->cache_path)) { |
|
50 | 50 | mkdir($this->cache_path); |
51 | 51 | } |
52 | - return file_put_contents($this->cache_path."/".$name,$content); |
|
52 | + return file_put_contents($this->cache_path . "/" . $name, $content); |
|
53 | 53 | } catch (Exception $e) { |
54 | 54 | // Handle exception |
55 | 55 | return false; |
56 | 56 | } |
57 | 57 | } |
58 | 58 | |
59 | - function readFile($name){ |
|
59 | + function readFile($name) { |
|
60 | 60 | try { |
61 | - $content = file_get_contents($this->cache_path."/".$name, false); |
|
61 | + $content = file_get_contents($this->cache_path . "/" . $name, false); |
|
62 | 62 | if ($content === false) { |
63 | 63 | // Handle the error |
64 | 64 | } else { |
@@ -35,9 +35,9 @@ |
||
35 | 35 | public function apiCurrent($short = false, $parameters = []) |
36 | 36 | { |
37 | 37 | $result = (new Cache)->getCache('accounts_current'); |
38 | - if(!$result){ |
|
38 | + if (!$result) { |
|
39 | 39 | $result = $this->getRequest('/private/api/v2/json/accounts/current', $parameters); |
40 | - (new Cache)->setCache('accounts_current',$result); |
|
40 | + (new Cache)->setCache('accounts_current', $result); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | return $short ? $this->getShorted($result['account']) : $result['account']; |
@@ -314,12 +314,12 @@ |
||
314 | 314 | return $line; |
315 | 315 | } |
316 | 316 | |
317 | - protected function logRequest($value, $entity=""){ |
|
317 | + protected function logRequest($value, $entity = "") { |
|
318 | 318 | $timestamp = gmdate("Y-m-d H:i:s", time()); |
319 | - $log_dir = defined('LOG_DIR')?LOG_DIR:sys_get_temp_dir(); |
|
320 | - if(!is_dir($log_dir)) { |
|
319 | + $log_dir = defined('LOG_DIR') ?LOG_DIR:sys_get_temp_dir(); |
|
320 | + if (!is_dir($log_dir)) { |
|
321 | 321 | mkdir($log_dir); |
322 | 322 | } |
323 | - file_put_contents($log_dir."/amo_requests.log"," [".$timestamp."] ".microtime(true)." | ".strtoupper($entity)." ".$value. PHP_EOL, FILE_APPEND | LOCK_EX); |
|
323 | + file_put_contents($log_dir . "/amo_requests.log", " [" . $timestamp . "] " . microtime(true) . " | " . strtoupper($entity) . " " . $value . PHP_EOL, FILE_APPEND | LOCK_EX); |
|
324 | 324 | } |
325 | 325 | } |