@@ -95,23 +95,23 @@ |
||
95 | 95 | */ |
96 | 96 | public function has($key){ |
97 | 97 | |
98 | - $cacheFile = implode('.',[$key,$this->ext]); |
|
99 | - $cacheLocation = $this->fs . DIRECTORY_SEPARATOR . $cacheFile; |
|
98 | + $cacheFile = implode('.',[$key,$this->ext]); |
|
99 | + $cacheLocation = $this->fs . DIRECTORY_SEPARATOR . $cacheFile; |
|
100 | 100 | |
101 | - if (!file_exists($cacheLocation)){ |
|
102 | - return false; |
|
103 | - } |
|
101 | + if (!file_exists($cacheLocation)){ |
|
102 | + return false; |
|
103 | + } |
|
104 | 104 | |
105 | - $data = \file_get_contents($cacheLocation); |
|
106 | - $cacheData = json_decode($data, TRUE); |
|
105 | + $data = \file_get_contents($cacheLocation); |
|
106 | + $cacheData = json_decode($data, TRUE); |
|
107 | 107 | |
108 | - //cache has expired |
|
109 | - if ($cacheData[0] < time() ){ |
|
110 | - \unlink($cacheLocation); |
|
111 | - return false; |
|
112 | - } |
|
108 | + //cache has expired |
|
109 | + if ($cacheData[0] < time() ){ |
|
110 | + \unlink($cacheLocation); |
|
111 | + return false; |
|
112 | + } |
|
113 | 113 | |
114 | - return true; |
|
114 | + return true; |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | $this->fs = $file; |
39 | 39 | $this->ext = 'cache'; |
40 | 40 | |
41 | - if(!@mkdir($this->fs, 0755) && !is_dir($this->fs)){ |
|
41 | + if (!@mkdir($this->fs, 0755) && !is_dir($this->fs)) { |
|
42 | 42 | throw new \Exception('unable to create directory'); |
43 | 43 | } |
44 | 44 | |
@@ -62,21 +62,21 @@ discard block |
||
62 | 62 | |
63 | 63 | $cacheItem = $this->_createCacheItem($key, $value, $ttl); |
64 | 64 | |
65 | - \file_put_contents($cacheItem['file'],$cacheItem['data']); |
|
65 | + \file_put_contents($cacheItem['file'], $cacheItem['data']); |
|
66 | 66 | |
67 | - if (!file_exists($cacheItem['file'])){ |
|
67 | + if (!file_exists($cacheItem['file'])) { |
|
68 | 68 | return false; |
69 | 69 | } |
70 | 70 | |
71 | 71 | return true; |
72 | 72 | } |
73 | 73 | |
74 | - private function _createCacheItem(string $key, $value, int $ttl){ |
|
74 | + private function _createCacheItem(string $key, $value, int $ttl) { |
|
75 | 75 | |
76 | - $filename = implode('.',[$key,$this->ext]); |
|
76 | + $filename = implode('.', [$key, $this->ext]); |
|
77 | 77 | |
78 | 78 | return [ |
79 | - 'file' => $this->fs . DIRECTORY_SEPARATOR . $filename, |
|
79 | + 'file' => $this->fs.DIRECTORY_SEPARATOR.$filename, |
|
80 | 80 | 'data' => json_encode([$ttl, $value]) |
81 | 81 | ]; |
82 | 82 | } |
@@ -93,12 +93,12 @@ discard block |
||
93 | 93 | * |
94 | 94 | * @return bool |
95 | 95 | */ |
96 | - public function has($key){ |
|
96 | + public function has($key) { |
|
97 | 97 | |
98 | - $cacheFile = implode('.',[$key,$this->ext]); |
|
99 | - $cacheLocation = $this->fs . DIRECTORY_SEPARATOR . $cacheFile; |
|
98 | + $cacheFile = implode('.', [$key, $this->ext]); |
|
99 | + $cacheLocation = $this->fs.DIRECTORY_SEPARATOR.$cacheFile; |
|
100 | 100 | |
101 | - if (!file_exists($cacheLocation)){ |
|
101 | + if (!file_exists($cacheLocation)) { |
|
102 | 102 | return false; |
103 | 103 | } |
104 | 104 | |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | $cacheData = json_decode($data, TRUE); |
107 | 107 | |
108 | 108 | //cache has expired |
109 | - if ($cacheData[0] < time() ){ |
|
109 | + if ($cacheData[0] < time()) { |
|
110 | 110 | \unlink($cacheLocation); |
111 | 111 | return false; |
112 | 112 | } |
@@ -122,12 +122,12 @@ discard block |
||
122 | 122 | * @return mixed The value of the item from the cache, or $default in case of cache miss. |
123 | 123 | * |
124 | 124 | */ |
125 | - public function get($key){ |
|
125 | + public function get($key) { |
|
126 | 126 | |
127 | - $cacheFile = implode('.',[$key,$this->ext]); |
|
128 | - $cacheLocation = $this->fs . DIRECTORY_SEPARATOR . $cacheFile; |
|
127 | + $cacheFile = implode('.', [$key, $this->ext]); |
|
128 | + $cacheLocation = $this->fs.DIRECTORY_SEPARATOR.$cacheFile; |
|
129 | 129 | |
130 | - if ($this->has($key)){ |
|
130 | + if ($this->has($key)) { |
|
131 | 131 | $data = \file_get_contents($cacheLocation); |
132 | 132 | $cacheData = json_decode($data, TRUE); |
133 | 133 | return $cacheData[1]; |
@@ -155,14 +155,14 @@ discard block |
||
155 | 155 | * |
156 | 156 | * @return bool True on success and false on failure. |
157 | 157 | */ |
158 | - public function clear(){ |
|
159 | - if (is_dir( $this->fs )){ |
|
158 | + public function clear() { |
|
159 | + if (is_dir($this->fs)) { |
|
160 | 160 | array_map('unlink', glob("$this->fs/*.*")); |
161 | 161 | } |
162 | 162 | |
163 | 163 | $data = glob("$this->fs/*.*"); |
164 | 164 | |
165 | - if (!empty($data)){ |
|
165 | + if (!empty($data)) { |
|
166 | 166 | return false; |
167 | 167 | } |
168 | 168 |
@@ -28,16 +28,16 @@ |
||
28 | 28 | * @param DateInterval $ttl |
29 | 29 | * @throws CacheException |
30 | 30 | */ |
31 | - public function __construct(DateInterval $ttl) |
|
32 | - { |
|
33 | - $foundApc = \extension_loaded('apc'); |
|
31 | + public function __construct(DateInterval $ttl) |
|
32 | + { |
|
33 | + $foundApc = \extension_loaded('apc'); |
|
34 | 34 | |
35 | - if (!$foundApc){ |
|
36 | - throw new CacheException('APC Extension not found.'); |
|
37 | - } |
|
35 | + if (!$foundApc){ |
|
36 | + throw new CacheException('APC Extension not found.'); |
|
37 | + } |
|
38 | 38 | |
39 | - parent::__construct($ttl); |
|
40 | - } |
|
39 | + parent::__construct($ttl); |
|
40 | + } |
|
41 | 41 | |
42 | 42 | /** |
43 | 43 | * Determines whether an item is present in the cache. |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | { |
33 | 33 | $foundApc = \extension_loaded('apc'); |
34 | 34 | |
35 | - if (!$foundApc){ |
|
35 | + if (!$foundApc) { |
|
36 | 36 | throw new CacheException('APC Extension not found.'); |
37 | 37 | } |
38 | 38 | |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | * |
52 | 52 | * @return bool |
53 | 53 | */ |
54 | - public function has($key){ |
|
54 | + public function has($key) { |
|
55 | 55 | return \apc_exists($key); |
56 | 56 | } |
57 | 57 | |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | */ |
95 | 95 | public function delete($key) |
96 | 96 | { |
97 | - if (\apc_exists($key)){ |
|
97 | + if (\apc_exists($key)) { |
|
98 | 98 | \apc_delete($key); |
99 | 99 | } |
100 | 100 | } |
@@ -104,12 +104,12 @@ discard block |
||
104 | 104 | * |
105 | 105 | * @return bool True on success and false on failure. |
106 | 106 | */ |
107 | - public function clear(){ |
|
107 | + public function clear() { |
|
108 | 108 | |
109 | 109 | \apc_clear_cache(); |
110 | 110 | $apcResult = $this->getInfo(); |
111 | 111 | |
112 | - if (!empty($apcResult['cache_list'])){ |
|
112 | + if (!empty($apcResult['cache_list'])) { |
|
113 | 113 | return false; |
114 | 114 | } |
115 | 115 | |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | * |
123 | 123 | * @return array |
124 | 124 | */ |
125 | - public function getInfo(){ |
|
125 | + public function getInfo() { |
|
126 | 126 | return apc_cache_info(); |
127 | 127 | } |
128 | 128 |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * @param DateInterval $ttl |
42 | 42 | * @return CacheStorageInterface |
43 | 43 | */ |
44 | - public function withTtl(DateInterval $ttl){ |
|
44 | + public function withTtl(DateInterval $ttl) { |
|
45 | 45 | $new = clone $this; |
46 | 46 | $new->ttl = $ttl; |
47 | 47 | return $new; |
@@ -53,11 +53,11 @@ discard block |
||
53 | 53 | * @param null|int $ttl |
54 | 54 | * @return int |
55 | 55 | */ |
56 | - public function getTtlTimestamp($ttl = null){ |
|
56 | + public function getTtlTimestamp($ttl = null) { |
|
57 | 57 | |
58 | - if (null === $ttl){ |
|
58 | + if (null === $ttl) { |
|
59 | 59 | $dateTime = new DateTime(); |
60 | - $dateTime->add( $this->ttl ); |
|
60 | + $dateTime->add($this->ttl); |
|
61 | 61 | $ttl = $dateTime->getTimestamp(); |
62 | 62 | } |
63 | 63 | |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @return DateInterval |
71 | 71 | */ |
72 | - public function getTtl(){ |
|
72 | + public function getTtl() { |
|
73 | 73 | return $this->ttl; |
74 | 74 | } |
75 | 75 |