22/**
33 * SCSSPHP
44 *
5- * @copyright 2012-2019 Leaf Corcoran
5+ * @copyright 2012-2020 Leaf Corcoran
66 *
77 * @license http://opensource.org/licenses/MIT MIT
88 *
2222 * taking in account options that affects the result
2323 *
2424 * The cache manager is agnostic about data format and only the operation is expected to be described by string
25- *
2625 */
2726
2827/**
2928 * SCSS cache
3029 *
31- * @author Cedric Morin
30+ * @author Cedric Morin <[email protected] > 3231 */
3332class Cache
3433{
@@ -57,12 +56,12 @@ class Cache
5756 public function __construct ($ options )
5857 {
5958 // check $cacheDir
60- if (isset ($ options ['cache_dir ' ])) {
61- self ::$ cacheDir = $ options ['cache_dir ' ];
59+ if (isset ($ options ['cacheDir ' ])) {
60+ self ::$ cacheDir = $ options ['cacheDir ' ];
6261 }
6362
6463 if (empty (self ::$ cacheDir )) {
65- throw new Exception ('cache_dir not set ' );
64+ throw new Exception ('cacheDir not set ' );
6665 }
6766
6867 if (isset ($ options ['prefix ' ])) {
@@ -74,7 +73,7 @@ public function __construct($options)
7473 }
7574
7675 if (isset ($ options ['forceRefresh ' ])) {
77- self ::$ forceRefresh = $ options ['force_refresh ' ];
76+ self ::$ forceRefresh = $ options ['forceRefresh ' ];
7877 }
7978
8079 self ::checkCacheDir ();
@@ -97,18 +96,18 @@ public function getCache($operation, $what, $options = [], $lastModified = null)
9796 {
9897 $ fileCache = self ::$ cacheDir . self ::cacheName ($ operation , $ what , $ options );
9998
100- if ((! self ::$ forceRefresh || (self ::$ forceRefresh === 'once ' &&
99+ if ((( self ::$ forceRefresh === false ) || (self ::$ forceRefresh === 'once ' &&
101100 isset (self ::$ refreshed [$ fileCache ]))) && file_exists ($ fileCache )
102101 ) {
103102 $ cacheTime = filemtime ($ fileCache );
104103
105- if ((is_null ($ lastModified ) || $ cacheTime > $ lastModified ) &&
104+ if ((\ is_null ($ lastModified ) || $ cacheTime > $ lastModified ) &&
106105 $ cacheTime + self ::$ gcLifetime > time ()
107106 ) {
108107 $ c = file_get_contents ($ fileCache );
109108 $ c = unserialize ($ c );
110109
111- if (is_array ($ c ) && isset ($ c ['value ' ])) {
110+ if (\ is_array ($ c ) && isset ($ c ['value ' ])) {
112111 return $ c ['value ' ];
113112 }
114113 }
@@ -132,6 +131,7 @@ public function setCache($operation, $what, $value, $options = [])
132131
133132 $ c = ['value ' => $ value ];
134133 $ c = serialize ($ c );
134+
135135 file_put_contents ($ fileCache , $ c );
136136
137137 if (self ::$ forceRefresh === 'once ' ) {
@@ -176,13 +176,13 @@ public static function checkCacheDir()
176176 self ::$ cacheDir = str_replace ('\\' , '/ ' , self ::$ cacheDir );
177177 self ::$ cacheDir = rtrim (self ::$ cacheDir , '/ ' ) . '/ ' ;
178178
179- if (! file_exists (self ::$ cacheDir )) {
179+ if (! is_dir (self ::$ cacheDir )) {
180180 if (! mkdir (self ::$ cacheDir )) {
181181 throw new Exception ('Cache directory couldn \'t be created: ' . self ::$ cacheDir );
182182 }
183- } elseif (! is_dir ( self :: $ cacheDir )) {
184- throw new Exception ( ' Cache directory doesn \' t exist: ' . self :: $ cacheDir );
185- } elseif (! is_writable (self ::$ cacheDir )) {
183+ }
184+
185+ if (! is_writable (self ::$ cacheDir )) {
186186 throw new Exception ('Cache directory isn \'t writable: ' . self ::$ cacheDir );
187187 }
188188 }
0 commit comments