@@ -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); |
@@ -1,7 +1,7 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace Mouf\Utils\Cache; |
| 3 | 3 | |
| 4 | -use Mouf\Utils\Log\LogInterface; |
|
| 4 | +use Mouf\Utils\Log\LogInterface; |
|
| 5 | 5 | use Psr\Log\LoggerInterface; |
| 6 | 6 | |
| 7 | 7 | /** |
@@ -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); |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | |
| 257 | 257 | if ($key){
|
| 258 | 258 | $subFolder = substr(hash("sha256", $key), 0, $this->hashDepth) . "/";
|
| 259 | - }else{
|
|
| 259 | + } else{
|
|
| 260 | 260 | $subFolder = ""; |
| 261 | 261 | } |
| 262 | 262 | |
@@ -286,9 +286,11 @@ discard block |
||
| 286 | 286 | $objects = scandir($dir); |
| 287 | 287 | foreach ($objects as $object) {
|
| 288 | 288 | if ($object != "." && $object != "..") {
|
| 289 | - if (filetype($dir."/".$object) == "dir") |
|
| 290 | - self::rrmdir($dir."/".$object); |
|
| 291 | - else unlink ($dir."/".$object); |
|
| 289 | + if (filetype($dir."/".$object) == "dir") {
|
|
| 290 | + self::rrmdir($dir."/".$object); |
|
| 291 | + } else {
|
|
| 292 | + unlink ($dir."/".$object); |
|
| 293 | + } |
|
| 292 | 294 | } |
| 293 | 295 | } |
| 294 | 296 | reset($objects); |
@@ -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 | } |
@@ -1,7 +1,7 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace Mouf\Utils\Cache; |
| 3 | 3 | |
| 4 | -use Mouf\Installer\PackageInstallerInterface; |
|
| 4 | +use Mouf\Installer\PackageInstallerInterface; |
|
| 5 | 5 | use Mouf\MoufManager; |
| 6 | 6 | |
| 7 | 7 | /** |
@@ -9,30 +9,30 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class FileCacheInstaller implements PackageInstallerInterface {
|
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * (non-PHPdoc) |
|
| 14 | - * @see \Mouf\Installer\PackageInstallerInterface::install() |
|
| 15 | - */ |
|
| 16 | - public static function install(MoufManager $moufManager) {
|
|
| 17 | - if (!$moufManager->instanceExists("fileCacheService")) {
|
|
| 18 | - $fileCacheService = $moufManager->createInstance("Mouf\\Utils\\Cache\\FileCache");
|
|
| 19 | - $fileCacheService->setName("fileCacheService");
|
|
| 20 | - $fileCacheService->getProperty("defaultTimeToLive")->setValue(3600);
|
|
| 21 | - /*if ($moufManager->instanceExists("psr.errorLogLogger")) {
|
|
| 12 | + /** |
|
| 13 | + * (non-PHPdoc) |
|
| 14 | + * @see \Mouf\Installer\PackageInstallerInterface::install() |
|
| 15 | + */ |
|
| 16 | + public static function install(MoufManager $moufManager) {
|
|
| 17 | + if (!$moufManager->instanceExists("fileCacheService")) {
|
|
| 18 | + $fileCacheService = $moufManager->createInstance("Mouf\\Utils\\Cache\\FileCache");
|
|
| 19 | + $fileCacheService->setName("fileCacheService");
|
|
| 20 | + $fileCacheService->getProperty("defaultTimeToLive")->setValue(3600);
|
|
| 21 | + /*if ($moufManager->instanceExists("psr.errorLogLogger")) {
|
|
| 22 | 22 | $fileCacheService->getProperty("log")->setValue($moufManager->getInstanceDescriptor("psr.errorLogLogger"));
|
| 23 | 23 | }*/ |
| 24 | - } else {
|
|
| 25 | - $fileCacheService = $moufManager->getInstanceDescriptor("fileCacheService");
|
|
| 26 | - } |
|
| 24 | + } else {
|
|
| 25 | + $fileCacheService = $moufManager->getInstanceDescriptor("fileCacheService");
|
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - $configManager = $moufManager->getConfigManager(); |
|
| 29 | - $constants = $configManager->getMergedConstants(); |
|
| 30 | - if (isset($constants['SECRET'])) {
|
|
| 31 | - $fileCacheService->getProperty('prefix')->setValue('SECRET')->setOrigin('config');
|
|
| 32 | - } |
|
| 28 | + $configManager = $moufManager->getConfigManager(); |
|
| 29 | + $constants = $configManager->getMergedConstants(); |
|
| 30 | + if (isset($constants['SECRET'])) {
|
|
| 31 | + $fileCacheService->getProperty('prefix')->setValue('SECRET')->setOrigin('config');
|
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - // Let's rewrite the MoufComponents.php file to save the component |
|
| 35 | - $moufManager->rewriteMouf(); |
|
| 36 | - } |
|
| 34 | + // Let's rewrite the MoufComponents.php file to save the component |
|
| 35 | + $moufManager->rewriteMouf(); |
|
| 36 | + } |
|
| 37 | 37 | } |
| 38 | 38 | ?> |
| 39 | 39 | \ No newline at end of file |
@@ -66,11 +66,11 @@ discard block |
||
| 66 | 66 | $filename = $this->getFileName($key); |
| 67 | 67 | |
| 68 | 68 | if (is_readable($filename)) {
|
| 69 | - $fp = fopen($filename, "r"); |
|
| 70 | - if ($fp === false) {//File may have been deleted between is_readable and fopen
|
|
| 71 | - return null; |
|
| 72 | - } |
|
| 73 | - $timeout = fgets($fp); |
|
| 69 | + $fp = fopen($filename, "r"); |
|
| 70 | + if ($fp === false) {//File may have been deleted between is_readable and fopen
|
|
| 71 | + return null; |
|
| 72 | + } |
|
| 73 | + $timeout = fgets($fp); |
|
| 74 | 74 | |
| 75 | 75 | if ($timeout > time() || $timeout==0) {
|
| 76 | 76 | $contents = ""; |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - $oldUmask = umask(0); |
|
| 133 | + $oldUmask = umask(0); |
|
| 134 | 134 | |
| 135 | 135 | if (!is_writable($filename)) {
|
| 136 | 136 | if (!file_exists($this->getDirectory())) {
|
@@ -152,10 +152,10 @@ discard block |
||
| 152 | 152 | fwrite($fp, $timeOut."\n"); |
| 153 | 153 | fwrite($fp, serialize($value)); |
| 154 | 154 | fclose($fp); |
| 155 | - // Cache is shared with group, not with the rest of the world. |
|
| 156 | - chmod($filename, 0660); |
|
| 155 | + // Cache is shared with group, not with the rest of the world. |
|
| 156 | + chmod($filename, 0660); |
|
| 157 | 157 | |
| 158 | - umask($oldUmask); |
|
| 158 | + umask($oldUmask); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | /** |
@@ -190,10 +190,10 @@ discard block |
||
| 190 | 190 | } |
| 191 | 191 | } |
| 192 | 192 | $files = glob($this->getDirectory()."*"); |
| 193 | - $prefixFile = str_replace(array("_", "/", "\\", ":"), array("___", "_s_", "_b_", "_d_"), $this->prefix);
|
|
| 193 | + $prefixFile = str_replace(array("_", "/", "\\", ":"), array("___", "_s_", "_b_", "_d_"), $this->prefix);
|
|
| 194 | 194 | foreach ($files as $filename) {
|
| 195 | 195 | if (empty($prefixFile) || strpos(basename($filename), $prefixFile) === 0) {
|
| 196 | - unlink($filename); |
|
| 196 | + unlink($filename); |
|
| 197 | 197 | } |
| 198 | 198 | } |
| 199 | 199 | } |
@@ -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 | |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - $oldUmask = umask(0); |
|
| 86 | + $oldUmask = umask(0); |
|
| 87 | 87 | |
| 88 | 88 | if (!is_writable($filename)) {
|
| 89 | 89 | if (!file_exists($this->getDirectory())) {
|
@@ -106,20 +106,20 @@ discard block |
||
| 106 | 106 | 'data' => $value |
| 107 | 107 | ); |
| 108 | 108 | |
| 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));
|
|
| 112 | - file_put_contents($filename, $code); |
|
| 113 | - }else{
|
|
| 114 | - $data = var_export($data, true); |
|
| 115 | - $code = sprintf('<?php return %s;', $data);
|
|
| 116 | - file_put_contents($filename, $code); |
|
| 117 | - } |
|
| 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));
|
|
| 112 | + file_put_contents($filename, $code); |
|
| 113 | + }else{
|
|
| 114 | + $data = var_export($data, true); |
|
| 115 | + $code = sprintf('<?php return %s;', $data);
|
|
| 116 | + file_put_contents($filename, $code); |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - // Cache is shared with group, not with the rest of the world. |
|
| 120 | - chmod($filename, 0660); |
|
| 119 | + // Cache is shared with group, not with the rest of the world. |
|
| 120 | + chmod($filename, 0660); |
|
| 121 | 121 | |
| 122 | - umask($oldUmask); |
|
| 122 | + umask($oldUmask); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | } |
@@ -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 | |
@@ -110,7 +110,7 @@ |
||
| 110 | 110 | if(strpos($serializeData, 'r:') !== false || (is_object($value) && !method_exists($value, '__set_state'))){
|
| 111 | 111 | $code = sprintf('<?php return unserialize(%s);', var_export($serializeData, true));
|
| 112 | 112 | file_put_contents($filename, $code); |
| 113 | - }else{
|
|
| 113 | + } else{
|
|
| 114 | 114 | $data = var_export($data, true); |
| 115 | 115 | $code = sprintf('<?php return %s;', $data);
|
| 116 | 116 | file_put_contents($filename, $code); |