@@ -69,7 +69,6 @@ discard block |
||
| 69 | 69 | * @param LoggerInterface|LogInterface $log |
| 70 | 70 | * @param string $cacheDirectory |
| 71 | 71 | * @param boolean $relativeToSystemTempDirectory |
| 72 | - * @param int $hashDepth |
|
| 73 | 72 | */ |
| 74 | 73 | function __construct($defaultTimeToLive, $log, $cacheDirectory, $relativeToSystemTempDirectory) |
| 75 | 74 | {
|
@@ -263,6 +262,9 @@ discard block |
||
| 263 | 262 | return $dir.$subFolder; |
| 264 | 263 | } |
| 265 | 264 | |
| 265 | + /** |
|
| 266 | + * @param string $key |
|
| 267 | + */ |
|
| 266 | 268 | protected function getFileName($key) {
|
| 267 | 269 | $subFolder = $this->getDirectory($key); |
| 268 | 270 | // Remove any "/" and ":" from the name, and replace those with "_" ... |
@@ -281,6 +283,9 @@ discard block |
||
| 281 | 283 | return $subFolder.md5($key).'.cache'; |
| 282 | 284 | } |
| 283 | 285 | |
| 286 | + /** |
|
| 287 | + * @param string $dir |
|
| 288 | + */ |
|
| 284 | 289 | private static function rrmdir($dir) {
|
| 285 | 290 | if (is_dir($dir)) {
|
| 286 | 291 | $objects = scandir($dir); |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | */ |
| 94 | 94 | public function setHashDepth($hashDepth) |
| 95 | 95 | {
|
| 96 | - if ($hashDepth > 4 || $hashDepth < 1){
|
|
| 96 | + if ($hashDepth > 4 || $hashDepth < 1) {
|
|
| 97 | 97 | throw new \Exception("hashDepth property should be betwwen 1 and 4");
|
| 98 | 98 | } |
| 99 | 99 | $this->hashDepth = $hashDepth; |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | } |
| 119 | 119 | $timeout = fgets($fp); |
| 120 | 120 | |
| 121 | - if ($timeout > time() || $timeout==0) {
|
|
| 121 | + if ($timeout > time() || $timeout == 0) {
|
|
| 122 | 122 | $contents = ""; |
| 123 | 123 | while (!feof($fp)) {
|
| 124 | 124 | $contents .= fread($fp, 65536); |
@@ -254,9 +254,9 @@ discard block |
||
| 254 | 254 | $dir .= "filecache/"; |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - if ($key){
|
|
| 258 | - $subFolder = substr(hash("sha256", $key), 0, $this->hashDepth) . "/";
|
|
| 259 | - }else{
|
|
| 257 | + if ($key) {
|
|
| 258 | + $subFolder = substr(hash("sha256", $key), 0, $this->hashDepth)."/";
|
|
| 259 | + } else {
|
|
| 260 | 260 | $subFolder = ""; |
| 261 | 261 | } |
| 262 | 262 | |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | $fullPath = $subFolder.$key.".cache"; |
| 273 | 273 | |
| 274 | 274 | // Approximative value due to NTFS short file names (e.g. PROGRA~1) that get longer when evaluated by Windows |
| 275 | - if (strlen($fullPath)<160) {
|
|
| 275 | + if (strlen($fullPath) < 160) {
|
|
| 276 | 276 | return $fullPath; |
| 277 | 277 | } |
| 278 | 278 | |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | if ($object != "." && $object != "..") {
|
| 289 | 289 | if (filetype($dir."/".$object) == "dir") |
| 290 | 290 | self::rrmdir($dir."/".$object); |
| 291 | - else unlink ($dir."/".$object); |
|
| 291 | + else unlink($dir."/".$object); |
|
| 292 | 292 | } |
| 293 | 293 | } |
| 294 | 294 | reset($objects); |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | } |
| 73 | 73 | $timeout = fgets($fp); |
| 74 | 74 | |
| 75 | - if ($timeout > time() || $timeout==0) {
|
|
| 75 | + if ($timeout > time() || $timeout == 0) {
|
|
| 76 | 76 | $contents = ""; |
| 77 | 77 | while (!feof($fp)) {
|
| 78 | 78 | $contents .= fread($fp, 65536); |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | $fullPath = $this->getDirectory().$key.".cache"; |
| 221 | 221 | |
| 222 | 222 | // Approximative value due to NTFS short file names (e.g. PROGRA~1) that get longer when evaluated by Windows |
| 223 | - if (strlen($fullPath)<160) {
|
|
| 223 | + if (strlen($fullPath) < 160) {
|
|
| 224 | 224 | return $fullPath; |
| 225 | 225 | } |
| 226 | 226 | |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | public function get($key) {
|
| 32 | 32 | $filename = $this->getFileName($key); |
| 33 | 33 | |
| 34 | - if ( ! is_file($filename)) {
|
|
| 34 | + if (!is_file($filename)) {
|
|
| 35 | 35 | if ($this->log) {
|
| 36 | 36 | if ($this->log instanceof LoggerInterface) {
|
| 37 | 37 | $this->log->info("Retrieving key '{key}' from file cache: cache miss.", array('key'=>$key));
|
@@ -107,12 +107,12 @@ discard block |
||
| 107 | 107 | ); |
| 108 | 108 | |
| 109 | 109 | $serializeData = serialize($data); |
| 110 | - if(strpos($serializeData, 'r:') !== false || (is_object($value) && !method_exists($value, '__set_state'))){
|
|
| 111 | - $code = sprintf('<?php return unserialize(%s);', var_export($serializeData, true));
|
|
| 110 | + if (strpos($serializeData, 'r:') !== false || (is_object($value) && !method_exists($value, '__set_state'))) {
|
|
| 111 | + $code = sprintf('<?php return unserialize(%s);', var_export($serializeData, true));
|
|
| 112 | 112 | file_put_contents($filename, $code); |
| 113 | - }else{
|
|
| 114 | - $data = var_export($data, true); |
|
| 115 | - $code = sprintf('<?php return %s;', $data);
|
|
| 113 | + } else {
|
|
| 114 | + $data = var_export($data, true); |
|
| 115 | + $code = sprintf('<?php return %s;', $data);
|
|
| 116 | 116 | file_put_contents($filename, $code); |
| 117 | 117 | } |
| 118 | 118 | |