@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * @Property |
| 37 | 37 | * @var int |
| 38 | 38 | */ |
| 39 | - private $defaultTimeToLive; |
|
| 39 | + private $defaultTimeToLive; |
|
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * The logger used to trace the cache activity. |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * |
| 45 | 45 | * @var LoggerInterface|LogInterface |
| 46 | 46 | */ |
| 47 | - private $log; |
|
| 47 | + private $log; |
|
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | 50 | * The directory the files are stored in. |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | * @Property |
| 55 | 55 | * @var string |
| 56 | 56 | */ |
| 57 | - private $cacheDirectory; |
|
| 57 | + private $cacheDirectory; |
|
| 58 | 58 | |
| 59 | 59 | /** |
| 60 | 60 | * Whether the directory is relative to the system temp directory or not. |
@@ -62,43 +62,43 @@ discard block |
||
| 62 | 62 | * @Property |
| 63 | 63 | * @var boolean |
| 64 | 64 | */ |
| 65 | - private $relativeToSystemTempDirectory = true; |
|
| 65 | + private $relativeToSystemTempDirectory = true; |
|
| 66 | 66 | |
| 67 | - private $hashDepth = 2; |
|
| 67 | + private $hashDepth = 2; |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * @param int $defaultTimeToLive |
|
| 71 | - * @param LoggerInterface|LogInterface $log |
|
| 72 | - * @param string $cacheDirectory |
|
| 73 | - * @param boolean $relativeToSystemTempDirectory |
|
| 74 | - * @param int $hashDepth |
|
| 75 | - */ |
|
| 76 | - function __construct($defaultTimeToLive, $log, $cacheDirectory, $relativeToSystemTempDirectory) |
|
| 77 | - {
|
|
| 78 | - $this->defaultTimeToLive = $defaultTimeToLive; |
|
| 79 | - $this->log = $log; |
|
| 80 | - $this->cacheDirectory = $cacheDirectory; |
|
| 81 | - $this->relativeToSystemTempDirectory = $relativeToSystemTempDirectory; |
|
| 82 | - } |
|
| 69 | + /** |
|
| 70 | + * @param int $defaultTimeToLive |
|
| 71 | + * @param LoggerInterface|LogInterface $log |
|
| 72 | + * @param string $cacheDirectory |
|
| 73 | + * @param boolean $relativeToSystemTempDirectory |
|
| 74 | + * @param int $hashDepth |
|
| 75 | + */ |
|
| 76 | + function __construct($defaultTimeToLive, $log, $cacheDirectory, $relativeToSystemTempDirectory) |
|
| 77 | + {
|
|
| 78 | + $this->defaultTimeToLive = $defaultTimeToLive; |
|
| 79 | + $this->log = $log; |
|
| 80 | + $this->cacheDirectory = $cacheDirectory; |
|
| 81 | + $this->relativeToSystemTempDirectory = $relativeToSystemTempDirectory; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Sets the length of the subdirectory. |
|
| 86 | - * See Class documentation for more details |
|
| 87 | - * |
|
| 88 | - * @param int $hashDepth |
|
| 89 | - */ |
|
| 90 | - public function setHashDepth($hashDepth) |
|
| 91 | - {
|
|
| 92 | - if ($hashDepth > 4 || $hashDepth < 1){
|
|
| 93 | - throw new \Exception("hashDepth property should be betwwen 1 and 4");
|
|
| 94 | - } |
|
| 95 | - $this->hashDepth = $hashDepth; |
|
| 96 | - } |
|
| 84 | + /** |
|
| 85 | + * Sets the length of the subdirectory. |
|
| 86 | + * See Class documentation for more details |
|
| 87 | + * |
|
| 88 | + * @param int $hashDepth |
|
| 89 | + */ |
|
| 90 | + public function setHashDepth($hashDepth) |
|
| 91 | + {
|
|
| 92 | + if ($hashDepth > 4 || $hashDepth < 1){
|
|
| 93 | + throw new \Exception("hashDepth property should be betwwen 1 and 4");
|
|
| 94 | + } |
|
| 95 | + $this->hashDepth = $hashDepth; |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | 98 | |
| 99 | 99 | |
| 100 | 100 | |
| 101 | - /** |
|
| 101 | + /** |
|
| 102 | 102 | * Returns the cached value for the key passed in parameter. |
| 103 | 103 | * |
| 104 | 104 | * @param string $key |
@@ -108,11 +108,11 @@ discard block |
||
| 108 | 108 | $filename = $this->getFileName($key); |
| 109 | 109 | |
| 110 | 110 | if (is_readable($filename)) {
|
| 111 | - $fp = fopen($filename, "r"); |
|
| 112 | - if ($fp === false) {//File may have been deleted between is_readable and fopen
|
|
| 113 | - return null; |
|
| 114 | - } |
|
| 115 | - $timeout = fgets($fp); |
|
| 111 | + $fp = fopen($filename, "r"); |
|
| 112 | + if ($fp === false) {//File may have been deleted between is_readable and fopen
|
|
| 113 | + return null; |
|
| 114 | + } |
|
| 115 | + $timeout = fgets($fp); |
|
| 116 | 116 | |
| 117 | 117 | if ($timeout > time() || $timeout==0) {
|
| 118 | 118 | $contents = ""; |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | } |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - $oldUmask = umask(0); |
|
| 175 | + $oldUmask = umask(0); |
|
| 176 | 176 | $subfolder = $this->getDirectory($key); |
| 177 | 177 | if (!is_writable($filename)) {
|
| 178 | 178 | if (!file_exists($subfolder)) {
|
@@ -194,10 +194,10 @@ discard block |
||
| 194 | 194 | fwrite($fp, $timeOut."\n"); |
| 195 | 195 | fwrite($fp, serialize($value)); |
| 196 | 196 | fclose($fp); |
| 197 | - // Cache is shared with group, not with the rest of the world. |
|
| 198 | - chmod($filename, 0660); |
|
| 197 | + // Cache is shared with group, not with the rest of the world. |
|
| 198 | + chmod($filename, 0660); |
|
| 199 | 199 | |
| 200 | - umask($oldUmask); |
|
| 200 | + umask($oldUmask); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
@@ -231,13 +231,13 @@ discard block |
||
| 231 | 231 | $this->log->trace("Purging the whole file cache.");
|
| 232 | 232 | } |
| 233 | 233 | } |
| 234 | - self::rrmdir($this->getDirectory()); |
|
| 234 | + self::rrmdir($this->getDirectory()); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - /** |
|
| 238 | - * @param mixed $key : if set, this function will return the cache directory WITH subfolder |
|
| 239 | - * @return string |
|
| 240 | - */ |
|
| 237 | + /** |
|
| 238 | + * @param mixed $key : if set, this function will return the cache directory WITH subfolder |
|
| 239 | + * @return string |
|
| 240 | + */ |
|
| 241 | 241 | protected function getDirectory($key = null) {
|
| 242 | 242 | |
| 243 | 243 | $dir = ""; |
@@ -250,26 +250,26 @@ discard block |
||
| 250 | 250 | $dir .= "filecache/"; |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | - if ($key){
|
|
| 254 | - $subFolder = substr(hash("sha256", $key), 0, $this->hashDepth) . "/";
|
|
| 255 | - }else{
|
|
| 256 | - $subFolder = ""; |
|
| 257 | - } |
|
| 253 | + if ($key){
|
|
| 254 | + $subFolder = substr(hash("sha256", $key), 0, $this->hashDepth) . "/";
|
|
| 255 | + }else{
|
|
| 256 | + $subFolder = ""; |
|
| 257 | + } |
|
| 258 | 258 | |
| 259 | 259 | return $dir.$subFolder; |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | protected function getFileName($key) {
|
| 263 | - $subFolder = $this->getDirectory($key); |
|
| 263 | + $subFolder = $this->getDirectory($key); |
|
| 264 | 264 | // Remove any "/" and ":" from the name, and replace those with "_" ... |
| 265 | 265 | $key = str_replace(array("_", "/", "\\", ":"), array("___", "_s_", "_b_", "_d_"), $key);
|
| 266 | 266 | |
| 267 | - // Windows full path need to be less than 260 characters. We need to limit the size of the filename |
|
| 268 | - $fullPath = $subFolder.$key.".cache"; |
|
| 267 | + // Windows full path need to be less than 260 characters. We need to limit the size of the filename |
|
| 268 | + $fullPath = $subFolder.$key.".cache"; |
|
| 269 | 269 | |
| 270 | - // Approximative value due to NTFS short file names (e.g. PROGRA~1) that get longer when evaluated by Windows |
|
| 271 | - if (strlen($fullPath)<160) {
|
|
| 272 | - return $fullPath; |
|
| 270 | + // Approximative value due to NTFS short file names (e.g. PROGRA~1) that get longer when evaluated by Windows |
|
| 271 | + if (strlen($fullPath)<160) {
|
|
| 272 | + return $fullPath; |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | |
@@ -277,18 +277,18 @@ discard block |
||
| 277 | 277 | return $subFolder.md5($key).'.cache'; |
| 278 | 278 | } |
| 279 | 279 | |
| 280 | - private static function rrmdir($dir) {
|
|
| 281 | - if (is_dir($dir)) {
|
|
| 282 | - $objects = scandir($dir); |
|
| 283 | - foreach ($objects as $object) {
|
|
| 284 | - if ($object != "." && $object != "..") {
|
|
| 285 | - if (filetype($dir."/".$object) == "dir") |
|
| 286 | - self::rrmdir($dir."/".$object); |
|
| 287 | - else unlink ($dir."/".$object); |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - reset($objects); |
|
| 291 | - rmdir($dir); |
|
| 292 | - } |
|
| 293 | - } |
|
| 280 | + private static function rrmdir($dir) {
|
|
| 281 | + if (is_dir($dir)) {
|
|
| 282 | + $objects = scandir($dir); |
|
| 283 | + foreach ($objects as $object) {
|
|
| 284 | + if ($object != "." && $object != "..") {
|
|
| 285 | + if (filetype($dir."/".$object) == "dir") |
|
| 286 | + self::rrmdir($dir."/".$object); |
|
| 287 | + else unlink ($dir."/".$object); |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + reset($objects); |
|
| 291 | + rmdir($dir); |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | 294 | } |