@@ -38,13 +38,13 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | public function __construct($file, DateInterval $ttl) |
| 40 | 40 | { |
| 41 | - if (!is_string($file)){ |
|
| 41 | + if (!is_string($file)) { |
|
| 42 | 42 | throw new \Exception('Directory must be a valid string'); |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | $this->fs = $file; |
| 46 | 46 | |
| 47 | - if(!@mkdir($this->fs, 0755) && !is_dir($this->fs)){ |
|
| 47 | + if (!@mkdir($this->fs, 0755) && !is_dir($this->fs)) { |
|
| 48 | 48 | throw new \Exception('unable to create directory'); |
| 49 | 49 | } |
| 50 | 50 | |
@@ -68,9 +68,9 @@ discard block |
||
| 68 | 68 | |
| 69 | 69 | $cacheItem = $this->_createCacheItem($key, $value, $ttl); |
| 70 | 70 | |
| 71 | - \file_put_contents($cacheItem['file'],$cacheItem['data']); |
|
| 71 | + \file_put_contents($cacheItem['file'], $cacheItem['data']); |
|
| 72 | 72 | |
| 73 | - if (!file_exists($cacheItem['file'])){ |
|
| 73 | + if (!file_exists($cacheItem['file'])) { |
|
| 74 | 74 | return false; |
| 75 | 75 | } |
| 76 | 76 | |
@@ -86,16 +86,16 @@ discard block |
||
| 86 | 86 | * @return array |
| 87 | 87 | * @throws \Exception |
| 88 | 88 | */ |
| 89 | - private function _createCacheItem($key, $value, $ttl){ |
|
| 89 | + private function _createCacheItem($key, $value, $ttl) { |
|
| 90 | 90 | |
| 91 | - if (!is_string($key)){ |
|
| 91 | + if (!is_string($key)) { |
|
| 92 | 92 | throw new \Exception('$key must be a valid string'); |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - $filename = implode('.',[$key,$this->ext]); |
|
| 95 | + $filename = implode('.', [$key, $this->ext]); |
|
| 96 | 96 | |
| 97 | 97 | return [ |
| 98 | - 'file' => $this->fs . DIRECTORY_SEPARATOR . $filename, |
|
| 98 | + 'file' => $this->fs.DIRECTORY_SEPARATOR.$filename, |
|
| 99 | 99 | 'data' => json_encode([$ttl, $value]) |
| 100 | 100 | ]; |
| 101 | 101 | } |
@@ -112,12 +112,12 @@ discard block |
||
| 112 | 112 | * |
| 113 | 113 | * @return bool |
| 114 | 114 | */ |
| 115 | - public function has($key){ |
|
| 115 | + public function has($key) { |
|
| 116 | 116 | |
| 117 | - $cacheFile = implode('.',[$key,$this->ext]); |
|
| 118 | - $cacheLocation = $this->fs . DIRECTORY_SEPARATOR . $cacheFile; |
|
| 117 | + $cacheFile = implode('.', [$key, $this->ext]); |
|
| 118 | + $cacheLocation = $this->fs.DIRECTORY_SEPARATOR.$cacheFile; |
|
| 119 | 119 | |
| 120 | - if (!file_exists($cacheLocation)){ |
|
| 120 | + if (!file_exists($cacheLocation)) { |
|
| 121 | 121 | return false; |
| 122 | 122 | } |
| 123 | 123 | |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | $cacheData = json_decode($data, TRUE); |
| 126 | 126 | |
| 127 | 127 | //cache has expired |
| 128 | - if ($cacheData[0] < time() ){ |
|
| 128 | + if ($cacheData[0] < time()) { |
|
| 129 | 129 | \unlink($cacheLocation); |
| 130 | 130 | return false; |
| 131 | 131 | } |
@@ -141,12 +141,12 @@ discard block |
||
| 141 | 141 | * @return mixed The value of the item from the cache, or $default in case of cache miss. |
| 142 | 142 | * |
| 143 | 143 | */ |
| 144 | - public function get($key){ |
|
| 144 | + public function get($key) { |
|
| 145 | 145 | |
| 146 | - $cacheFile = implode('.',[$key,$this->ext]); |
|
| 147 | - $cacheLocation = $this->fs . DIRECTORY_SEPARATOR . $cacheFile; |
|
| 146 | + $cacheFile = implode('.', [$key, $this->ext]); |
|
| 147 | + $cacheLocation = $this->fs.DIRECTORY_SEPARATOR.$cacheFile; |
|
| 148 | 148 | |
| 149 | - if ($this->has($key)){ |
|
| 149 | + if ($this->has($key)) { |
|
| 150 | 150 | $data = \file_get_contents($cacheLocation); |
| 151 | 151 | $cacheData = json_decode($data, TRUE); |
| 152 | 152 | return $cacheData[1]; |
@@ -174,14 +174,14 @@ discard block |
||
| 174 | 174 | * |
| 175 | 175 | * @return bool True on success and false on failure. |
| 176 | 176 | */ |
| 177 | - public function clear(){ |
|
| 178 | - if (is_dir( $this->fs )){ |
|
| 177 | + public function clear() { |
|
| 178 | + if (is_dir($this->fs)) { |
|
| 179 | 179 | array_map('unlink', glob("$this->fs/*.*")); |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | $data = glob("$this->fs/*.*"); |
| 183 | 183 | |
| 184 | - if (!empty($data)){ |
|
| 184 | + if (!empty($data)) { |
|
| 185 | 185 | return false; |
| 186 | 186 | } |
| 187 | 187 | |