Completed
Push — 2.2 ( 709002...7184e8 )
by Kevin
04:01
created
src/FileCache.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -66,11 +66,11 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 	}
Please login to merge, or discard this patch.
src/FileCacheInstaller.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -9,30 +9,30 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
src/PhpFileCache.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
src/BigFileCache.php 1 patch
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.