Completed
Branch scrutinizer (4d54e2)
by Fabio
15:49
created
framework/I18N/core/MessageSource_gettext.php 3 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -200,6 +200,9 @@  discard block
 block discarded – undo
200 200
 		return false;
201 201
 	}
202 202
 
203
+	/**
204
+	 * @param string $MOFile
205
+	 */
203 206
 	private function getPOFile($MOFile)
204 207
 	{
205 208
 		$filebase = substr($MOFile, 0, strlen($MOFile)-strlen($this->dataExt));
@@ -422,6 +425,9 @@  discard block
 block discarded – undo
422 425
 		return $catalogue;
423 426
 	}
424 427
 
428
+	/**
429
+	 * @param string $catalogue
430
+	 */
425 431
 	protected function createMessageTemplate($catalogue)
426 432
 	{
427 433
 		if($catalogue === null) {
Please login to merge, or discard this patch.
Spacing   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -20,12 +20,12 @@  discard block
 block discarded – undo
20 20
 /**
21 21
  * Get the MessageSource class file.
22 22
  */
23
-require_once(dirname(__FILE__).'/MessageSource.php');
23
+require_once(dirname(__FILE__) . '/MessageSource.php');
24 24
 
25 25
 /**
26 26
  * Get the Gettext class.
27 27
  */
28
-require_once(dirname(__FILE__).'/Gettext/TGettext.php');
28
+require_once(dirname(__FILE__) . '/Gettext/TGettext.php');
29 29
 
30 30
 /**
31 31
  * MessageSource_gettext class.
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 
62 62
 	function __construct($source)
63 63
 	{
64
-		$this->source = (string)$source;
64
+		$this->source = (string) $source;
65 65
 	}
66 66
 
67 67
 
@@ -72,13 +72,13 @@  discard block
 block discarded – undo
72 72
 	 */
73 73
 	protected function &loadData($filename)
74 74
 	{
75
-		$mo = TGettext::factory('MO',$filename);
75
+		$mo = TGettext::factory('MO', $filename);
76 76
 		$mo->load();
77 77
 		$result = $mo->toArray();
78 78
 
79 79
 		$results = array();
80
-		$count=0;
81
-		foreach($result['strings'] as $source => $target)
80
+		$count = 0;
81
+		foreach ($result['strings'] as $source => $target)
82 82
 		{
83 83
 			$results[$source][] = $target; //target
84 84
 			$results[$source][] = $count++; //id
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 	 */
106 106
 	protected function getSource($variant)
107 107
 	{
108
-		return $this->source.'/'.$variant;
108
+		return $this->source . '/' . $variant;
109 109
 	}
110 110
 
111 111
 	/**
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 	 */
117 117
 	protected function getLastModified($source)
118 118
 	{
119
-		if(is_file($source))
119
+		if (is_file($source))
120 120
 			return filemtime($source);
121 121
 		else
122 122
 			return 0;
@@ -129,24 +129,24 @@  discard block
 block discarded – undo
129 129
 	 */
130 130
 	protected function getCatalogueList($catalogue)
131 131
 	{
132
-		$variants = explode('_',$this->culture);
133
-		$source = $catalogue.$this->dataExt;
132
+		$variants = explode('_', $this->culture);
133
+		$source = $catalogue . $this->dataExt;
134 134
 
135 135
 		$catalogues = array($source);
136 136
 
137 137
 		$variant = null;
138 138
 
139
-		for($i = 0, $k = count($variants); $i < $k; ++$i)
139
+		for ($i = 0, $k = count($variants); $i < $k; ++$i)
140 140
 		{
141
-			if(isset($variants[$i]{0}))
141
+			if (isset($variants[$i]{0}))
142 142
 			{
143
-				$variant .= ($variant)?'_'.$variants[$i]:$variants[$i];
144
-				$catalogues[] = $catalogue.$this->dataSeparator.
145
-								$variant.$this->dataExt;
143
+				$variant .= ($variant) ? '_' . $variants[$i] : $variants[$i];
144
+				$catalogues[] = $catalogue . $this->dataSeparator .
145
+								$variant . $this->dataExt;
146 146
 			}
147 147
 		}
148 148
 		$byDir = $this->getCatalogueByDir($catalogue);
149
-		$catalogues = array_merge($byDir,array_reverse($catalogues));
149
+		$catalogues = array_merge($byDir, array_reverse($catalogues));
150 150
 		return $catalogues;
151 151
 	}
152 152
 
@@ -160,17 +160,17 @@  discard block
 block discarded – undo
160 160
 	 */
161 161
 	private function getCatalogueByDir($catalogue)
162 162
 	{
163
-		$variants = explode('_',$this->culture);
163
+		$variants = explode('_', $this->culture);
164 164
 		$catalogues = array();
165 165
 
166 166
 		$variant = null;
167 167
 
168
-		for($i = 0, $k = count($variants); $i < $k; ++$i)
168
+		for ($i = 0, $k = count($variants); $i < $k; ++$i)
169 169
 		{
170
-			if(isset($variants[$i]{0}))
170
+			if (isset($variants[$i]{0}))
171 171
 			{
172
-				$variant .= ($variant)?'_'.$variants[$i]:$variants[$i];
173
-				$catalogues[] = $variant.'/'.$catalogue.$this->dataExt;
172
+				$variant .= ($variant) ? '_' . $variants[$i] : $variants[$i];
173
+				$catalogues[] = $variant . '/' . $catalogue . $this->dataExt;
174 174
 			}
175 175
 		}
176 176
 		return array_reverse($catalogues);
@@ -184,17 +184,17 @@  discard block
 block discarded – undo
184 184
 	 * @see update()
185 185
 	 * @see delete()
186 186
 	 */
187
-	private function getVariants($catalogue='messages')
187
+	private function getVariants($catalogue = 'messages')
188 188
 	{
189
-		if($catalogue === null) {
189
+		if ($catalogue === null) {
190 190
 			$catalogue = 'messages';
191 191
 		}
192 192
 
193
-		foreach($this->getCatalogueList($catalogue) as $variant)
193
+		foreach ($this->getCatalogueList($catalogue) as $variant)
194 194
 		{
195 195
 			$file = $this->getSource($variant);
196 196
 			$po = $this->getPOFile($file);
197
-			if(is_file($file) || is_file($po))
197
+			if (is_file($file) || is_file($po))
198 198
 				return array($variant, $file, $po);
199 199
 		}
200 200
 		return false;
@@ -202,8 +202,8 @@  discard block
 block discarded – undo
202 202
 
203 203
 	private function getPOFile($MOFile)
204 204
 	{
205
-		$filebase = substr($MOFile, 0, strlen($MOFile)-strlen($this->dataExt));
206
-		return $filebase.$this->poExt;
205
+		$filebase = substr($MOFile, 0, strlen($MOFile) - strlen($this->dataExt));
206
+		return $filebase . $this->poExt;
207 207
 	}
208 208
 
209 209
 	/**
@@ -213,51 +213,51 @@  discard block
 block discarded – undo
213 213
 	 * @param string the catalogue to add to
214 214
 	 * @return boolean true if saved successfuly, false otherwise.
215 215
 	 */
216
-	function save($catalogue='messages')
216
+	function save($catalogue = 'messages')
217 217
 	{
218 218
 		$messages = $this->untranslated;
219 219
 
220
-		if(count($messages) <= 0) return false;
220
+		if (count($messages) <= 0) return false;
221 221
 
222 222
 		$variants = $this->getVariants($catalogue);
223 223
 
224
-		if($variants)
224
+		if ($variants)
225 225
 			list($variant, $MOFile, $POFile) = $variants;
226 226
 		else
227 227
 			list($variant, $MOFile, $POFile) = $this->createMessageTemplate($catalogue);
228 228
 
229
-		if(is_writable($MOFile) == false)
229
+		if (is_writable($MOFile) == false)
230 230
 			throw new TIOException("Unable to save to file {$MOFile}, file must be writable.");
231
-		if(is_writable($POFile) == false)
231
+		if (is_writable($POFile) == false)
232 232
 			throw new TIOException("Unable to save to file {$POFile}, file must be writable.");
233 233
 
234 234
 		//set the strings as untranslated.
235 235
 		$strings = array();
236
-		foreach($messages as $message)
236
+		foreach ($messages as $message)
237 237
 			$strings[$message] = '';
238 238
 
239 239
 		//load the PO
240
-		$po = TGettext::factory('PO',$POFile);
240
+		$po = TGettext::factory('PO', $POFile);
241 241
 		$po->load();
242 242
 		$result = $po->toArray();
243 243
 
244 244
 		$existing = count($result['strings']);
245 245
 
246 246
 		//add to strings to the existing message list
247
-		$result['strings'] = array_merge($result['strings'],$strings);
247
+		$result['strings'] = array_merge($result['strings'], $strings);
248 248
 
249 249
 		$new = count($result['strings']);
250 250
 
251
-		if($new > $existing)
251
+		if ($new > $existing)
252 252
 		{
253 253
 			//change the date 2004-12-25 12:26
254 254
 			$result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s');
255 255
 
256 256
 			$po->fromArray($result);
257 257
 			$mo = $po->toMO();
258
-			if($po->save() && $mo->save($MOFile))
258
+			if ($po->save() && $mo->save($MOFile))
259 259
 			{
260
-				if(!empty($this->cache))
260
+				if (!empty($this->cache))
261 261
 					$this->cache->clean($variant, $this->culture);
262 262
 				return true;
263 263
 			}
@@ -273,35 +273,35 @@  discard block
 block discarded – undo
273 273
 	 * @param string the catalogue to delete from.
274 274
 	 * @return boolean true if deleted, false otherwise.
275 275
 	 */
276
-	function delete($message, $catalogue='messages')
276
+	function delete($message, $catalogue = 'messages')
277 277
 	{
278 278
 		$variants = $this->getVariants($catalogue);
279
-		if($variants)
279
+		if ($variants)
280 280
 			list($variant, $MOFile, $POFile) = $variants;
281 281
 		else
282 282
 			return false;
283 283
 
284
-		if(is_writable($MOFile) == false)
284
+		if (is_writable($MOFile) == false)
285 285
 			throw new TIOException("Unable to modify file {$MOFile}, file must be writable.");
286
-		if(is_writable($POFile) == false)
286
+		if (is_writable($POFile) == false)
287 287
 			throw new TIOException("Unable to modify file {$POFile}, file must be writable.");
288 288
 
289
-		$po = TGettext::factory('PO',$POFile);
289
+		$po = TGettext::factory('PO', $POFile);
290 290
 		$po->load();
291 291
 		$result = $po->toArray();
292 292
 
293
-		foreach($result['strings'] as $string => $value)
293
+		foreach ($result['strings'] as $string => $value)
294 294
 		{
295
-			if($string == $message)
295
+			if ($string == $message)
296 296
 			{
297 297
 				$result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s');
298 298
 				unset($result['strings'][$string]);
299 299
 
300 300
 				$po->fromArray($result);
301 301
 				$mo = $po->toMO();
302
-				if($po->save() && $mo->save($MOFile))
302
+				if ($po->save() && $mo->save($MOFile))
303 303
 				{
304
-					if(!empty($this->cache))
304
+					if (!empty($this->cache))
305 305
 						$this->cache->clean($variant, $this->culture);
306 306
 					return true;
307 307
 				}
@@ -321,27 +321,27 @@  discard block
 block discarded – undo
321 321
 	 * @param string the catalogue of the translation.
322 322
 	 * @return boolean true if translation was updated, false otherwise.
323 323
 	 */
324
-	function update($text, $target, $comments, $catalogue='messages')
324
+	function update($text, $target, $comments, $catalogue = 'messages')
325 325
 	{
326 326
 		$variants = $this->getVariants($catalogue);
327
-		if($variants)
327
+		if ($variants)
328 328
 			list($variant, $MOFile, $POFile) = $variants;
329 329
 		else
330 330
 			return false;
331 331
 
332
-		if(is_writable($MOFile) == false)
332
+		if (is_writable($MOFile) == false)
333 333
 			throw new TIOException("Unable to update file {$MOFile}, file must be writable.");
334
-		if(is_writable($POFile) == false)
334
+		if (is_writable($POFile) == false)
335 335
 			throw new TIOException("Unable to update file {$POFile}, file must be writable.");
336 336
 
337 337
 
338
-		$po = TGettext::factory('PO',$POFile);
338
+		$po = TGettext::factory('PO', $POFile);
339 339
 		$po->load();
340 340
 		$result = $po->toArray();
341 341
 
342
-		foreach($result['strings'] as $string => $value)
342
+		foreach ($result['strings'] as $string => $value)
343 343
 		{
344
-			if($string == $text)
344
+			if ($string == $text)
345 345
 			{
346 346
 				$result['strings'][$string] = $target;
347 347
 				$result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s');
@@ -349,9 +349,9 @@  discard block
 block discarded – undo
349 349
 				$po->fromArray($result);
350 350
 				$mo = $po->toMO();
351 351
 
352
-				if($po->save() && $mo->save($MOFile))
352
+				if ($po->save() && $mo->save($MOFile))
353 353
 				{
354
-					if(!empty($this->cache))
354
+					if (!empty($this->cache))
355 355
 						$this->cache->clean($variant, $this->culture);
356 356
 					return true;
357 357
 				}
@@ -379,36 +379,36 @@  discard block
 block discarded – undo
379 379
 	 * E.g. array('messages','en_AU')
380 380
 	 * @return array list of catalogues
381 381
 	 */
382
-	protected function getCatalogues($dir=null,$variant=null)
382
+	protected function getCatalogues($dir = null, $variant = null)
383 383
 	{
384
-		$dir = $dir?$dir:$this->source;
384
+		$dir = $dir ? $dir : $this->source;
385 385
 		$files = scandir($dir);
386 386
 
387 387
 		$catalogue = array();
388 388
 
389
-		foreach($files as $file)
389
+		foreach ($files as $file)
390 390
 		{
391
-			if(is_dir($dir.'/'.$file)
392
-				&& preg_match('/^[a-z]{2}(_[A-Z]{2,3})?$/',$file))
391
+			if (is_dir($dir . '/' . $file)
392
+				&& preg_match('/^[a-z]{2}(_[A-Z]{2,3})?$/', $file))
393 393
 			{
394 394
 
395 395
 				$catalogue = array_merge($catalogue,
396
-								$this->getCatalogues($dir.'/'.$file, $file));
396
+								$this->getCatalogues($dir . '/' . $file, $file));
397 397
 			}
398 398
 
399
-			$pos = strpos($file,$this->dataExt);
399
+			$pos = strpos($file, $this->dataExt);
400 400
 
401
-			if($pos >0
402
-				&& substr($file,-1*strlen($this->dataExt)) == $this->dataExt)
401
+			if ($pos > 0
402
+				&& substr($file, -1 * strlen($this->dataExt)) == $this->dataExt)
403 403
 			{
404
-				$name = substr($file,0,$pos);
405
-				$dot = strrpos($name,$this->dataSeparator);
404
+				$name = substr($file, 0, $pos);
405
+				$dot = strrpos($name, $this->dataSeparator);
406 406
 				$culture = $variant;
407 407
 				$cat = $name;
408
-				if(is_int($dot))
408
+				if (is_int($dot))
409 409
 				{
410
-					$culture = substr($name, $dot+1,strlen($name));
411
-					$cat = substr($name,0,$dot);
410
+					$culture = substr($name, $dot + 1, strlen($name));
411
+					$cat = substr($name, 0, $dot);
412 412
 				}
413 413
 				$details[0] = $cat;
414 414
 				$details[1] = $culture;
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
 
425 425
 	protected function createMessageTemplate($catalogue)
426 426
 	{
427
-		if($catalogue === null) {
427
+		if ($catalogue === null) {
428 428
 			$catalogue = 'messages';
429 429
 		}
430 430
 		$variants = $this->getCatalogueList($catalogue);
@@ -433,21 +433,21 @@  discard block
 block discarded – undo
433 433
 		$po_file = $this->getPOFile($mo_file);
434 434
 
435 435
 		$dir = dirname($mo_file);
436
-		if(!is_dir($dir))
436
+		if (!is_dir($dir))
437 437
 		{
438 438
 			@mkdir($dir);
439
-			@chmod($dir,PRADO_CHMOD);
439
+			@chmod($dir, PRADO_CHMOD);
440 440
 		}
441
-		if(!is_dir($dir))
441
+		if (!is_dir($dir))
442 442
 			throw new TException("Unable to create directory $dir");
443 443
 
444
-		$po = TGettext::factory('PO',$po_file);
444
+		$po = TGettext::factory('PO', $po_file);
445 445
 		$result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s');
446 446
 		$result['strings'] = array();
447 447
 
448 448
 		$po->fromArray($result);
449 449
 		$mo = $po->toMO();
450
-		if($po->save() && $mo->save($mo_file))
450
+		if ($po->save() && $mo->save($mo_file))
451 451
 			return array($variant, $mo_file, $po_file);
452 452
 		else
453 453
 			throw new TException("Unable to create file $po_file and $mo_file");
Please login to merge, or discard this patch.
Braces   +6 added lines, -8 removed lines patch added patch discarded remove patch
@@ -233,8 +233,9 @@  discard block
 block discarded – undo
233 233
 
234 234
 		//set the strings as untranslated.
235 235
 		$strings = array();
236
-		foreach($messages as $message)
237
-			$strings[$message] = '';
236
+		foreach($messages as $message) {
237
+					$strings[$message] = '';
238
+		}
238 239
 
239 240
 		//load the PO
240 241
 		$po = TGettext::factory('PO',$POFile);
@@ -260,8 +261,7 @@  discard block
 block discarded – undo
260 261
 				if(!empty($this->cache))
261 262
 					$this->cache->clean($variant, $this->culture);
262 263
 				return true;
263
-			}
264
-			else
264
+			} else
265 265
 				return false;
266 266
 		}
267 267
 		return false;
@@ -304,8 +304,7 @@  discard block
 block discarded – undo
304 304
 					if(!empty($this->cache))
305 305
 						$this->cache->clean($variant, $this->culture);
306 306
 					return true;
307
-				}
308
-				else
307
+				} else
309 308
 					return false;
310 309
 			}
311 310
 		}
@@ -354,8 +353,7 @@  discard block
 block discarded – undo
354 353
 					if(!empty($this->cache))
355 354
 						$this->cache->clean($variant, $this->culture);
356 355
 					return true;
357
-				}
358
-				else
356
+				} else
359 357
 					return false;
360 358
 			}
361 359
 		}
Please login to merge, or discard this patch.
framework/I18N/core/MessageSource_SQLite.php 2 patches
Doc Comments   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -198,7 +198,9 @@
 block discarded – undo
198 198
 	
199 199
 	/**
200 200
 	 * Update the catalogue last modified time.
201
-	 * @return boolean true if updated, false otherwise. 
201
+	 * @param integer $cat_id
202
+	 * @param string $variant
203
+	 * @return SQLiteResult true if updated, false otherwise. 
202 204
 	 */
203 205
 	private function updateCatalogueTime($cat_id, $variant, $db)
204 206
 	{
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -20,12 +20,12 @@  discard block
 block discarded – undo
20 20
 /**
21 21
  * Get the MessageSource class file.
22 22
  */
23
-require_once(dirname(__FILE__).'/MessageSource.php');
23
+require_once(dirname(__FILE__) . '/MessageSource.php');
24 24
 
25 25
 /**
26 26
  * Get the I18N utility file, contains the DSN parser.
27 27
  */
28
-require_once(dirname(__FILE__).'/util.php');
28
+require_once(dirname(__FILE__) . '/util.php');
29 29
 
30 30
 /**
31 31
  * MessageSource_SQLite class.
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 	 */
55 55
 	function __construct($source)
56 56
 	{
57
-		$dsn = parseDSN((string)$source);
57
+		$dsn = parseDSN((string) $source);
58 58
 		$this->source = $dsn['database'];
59 59
 	}
60 60
 	
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 			
81 81
 		$result = array();
82 82
 		
83
-		while($row = sqlite_fetch_array($rs,SQLITE_NUM))
83
+		while ($row = sqlite_fetch_array($rs, SQLITE_NUM))
84 84
 		{
85 85
 			$source = $row[1];
86 86
 			$result[$source][] = $row[2]; //target
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 			"SELECT date_modified FROM catalogue WHERE name = '{$source}'",
110 110
 			$db);
111 111
 			
112
-		$result = $rs ? (int)sqlite_fetch_single($rs) : 0;
112
+		$result = $rs ? (int) sqlite_fetch_single($rs) : 0;
113 113
 		
114 114
 		sqlite_close($db);		
115 115
 	
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 		$rs = sqlite_query(
130 130
 			"SELECT COUNT(*) FROM catalogue WHERE name = '{$variant}'",
131 131
 			$db);
132
-		$result = $rs && (int)sqlite_fetch_single($rs);	
132
+		$result = $rs && (int) sqlite_fetch_single($rs);	
133 133
 		sqlite_close($db);
134 134
 
135 135
 		return $result;
@@ -142,18 +142,18 @@  discard block
 block discarded – undo
142 142
 	 */
143 143
 	protected function getCatalogueList($catalogue)
144 144
 	{
145
-		$variants = explode('_',$this->culture);
145
+		$variants = explode('_', $this->culture);
146 146
 		
147 147
 		$catalogues = array($catalogue);
148 148
 
149 149
 		$variant = null;
150 150
 				
151
-		for($i = 0, $k = count($variants); $i < $k; ++$i)
151
+		for ($i = 0, $k = count($variants); $i < $k; ++$i)
152 152
 		{						
153
-			if(isset($variants[$i]{0}))
153
+			if (isset($variants[$i]{0}))
154 154
 			{
155
-				$variant .= ($variant)?'_'.$variants[$i]:$variants[$i];
156
-				$catalogues[] = $catalogue.'.'.$variant;
155
+				$variant .= ($variant) ? '_' . $variants[$i] : $variants[$i];
156
+				$catalogues[] = $catalogue . '.' . $variant;
157 157
 			}
158 158
 		}
159 159
 		return array_reverse($catalogues);	
@@ -164,12 +164,12 @@  discard block
 block discarded – undo
164 164
 	 * @param string catalogue
165 165
 	 * @return array catalogue details, array($cat_id, $variant, $count). 
166 166
 	 */
167
-	private function getCatalogueDetails($catalogue='messages')
167
+	private function getCatalogueDetails($catalogue = 'messages')
168 168
 	{
169
-		if(empty($catalogue))
169
+		if (empty($catalogue))
170 170
 			$catalogue = 'messages';
171 171
 
172
-		$variant = $catalogue.'.'.$this->culture;
172
+		$variant = $catalogue . '.' . $this->culture;
173 173
 		
174 174
 		$name = sqlite_escape_string($this->getSource($variant));	
175 175
 			
@@ -178,10 +178,10 @@  discard block
 block discarded – undo
178 178
 		$rs = sqlite_query("SELECT cat_id
179 179
 					FROM catalogue WHERE name = '{$name}'", $db);
180 180
 		
181
-		if(sqlite_num_rows($rs) != 1)
181
+		if (sqlite_num_rows($rs) != 1)
182 182
 			return false;
183 183
 		
184
-		$cat_id = (int)sqlite_fetch_single($rs);
184
+		$cat_id = (int) sqlite_fetch_single($rs);
185 185
 		
186 186
 		//first get the catalogue ID
187 187
 		$rs = sqlite_query(
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 				FROM trans_unit
190 190
 				WHERE cat_id = {$cat_id}", $db);
191 191
 
192
-		$count = (int)sqlite_fetch_single($rs);
192
+		$count = (int) sqlite_fetch_single($rs);
193 193
 
194 194
 		sqlite_close($db);	
195 195
 		
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 							SET date_modified = {$time}
209 209
 							WHERE cat_id = {$cat_id}", $db);
210 210
 
211
-		if(!empty($this->cache))		
211
+		if (!empty($this->cache))		
212 212
 			$this->cache->clean($variant, $this->culture);	
213 213
 		
214 214
 		return $result;
@@ -221,37 +221,37 @@  discard block
 block discarded – undo
221 221
 	 * @param string the catalogue to add to
222 222
 	 * @return boolean true if saved successfuly, false otherwise.
223 223
 	 */
224
-	function save($catalogue='messages')
224
+	function save($catalogue = 'messages')
225 225
 	{
226 226
 		$messages = $this->untranslated;
227 227
 		
228
-		if(count($messages) <= 0) return false;				
228
+		if (count($messages) <= 0) return false;				
229 229
 		
230 230
 		$details = $this->getCatalogueDetails($catalogue);	
231 231
 		
232
-		if($details)
232
+		if ($details)
233 233
 			list($cat_id, $variant, $count) = $details;
234 234
 		else
235 235
 			return false;
236 236
 		
237
-		if($cat_id <= 0) return false;
237
+		if ($cat_id <= 0) return false;
238 238
 		$inserted = 0;
239 239
 		
240 240
 		$db = sqlite_open($this->source);
241 241
 		$time = time();
242 242
 
243
-		foreach($messages as $message)
243
+		foreach ($messages as $message)
244 244
 		{
245 245
 			$message = sqlite_escape_string($message);
246 246
 			$statement = "INSERT INTO trans_unit
247 247
 				(cat_id,id,source,date_added) VALUES
248 248
 				({$cat_id}, {$count},'{$message}',$time)";
249
-			if(sqlite_query($statement, $db))
249
+			if (sqlite_query($statement, $db))
250 250
 			{
251 251
 				$count++; $inserted++;			
252 252
 			}
253 253
 		}
254
-		if($inserted > 0)
254
+		if ($inserted > 0)
255 255
 			$this->updateCatalogueTime($cat_id, $variant, $db);
256 256
 	
257 257
 		sqlite_close($db);	
@@ -267,10 +267,10 @@  discard block
 block discarded – undo
267 267
 	 * @param string the catalogue of the translation.
268 268
 	 * @return boolean true if translation was updated, false otherwise. 
269 269
 	 */	
270
-	function update($text, $target, $comments, $catalogue='messages')
270
+	function update($text, $target, $comments, $catalogue = 'messages')
271 271
 	{
272 272
 		$details = $this->getCatalogueDetails($catalogue);
273
-		if($details)
273
+		if ($details)
274 274
 			list($cat_id, $variant, $count) = $details;
275 275
 		else
276 276
 			return false;
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 		
293 293
 		$updated = false;
294 294
 		
295
-		if(sqlite_query($statement, $db))
295
+		if (sqlite_query($statement, $db))
296 296
 			$updated = $this->updateCatalogueTime($cat_id, $variant, $db);
297 297
 		
298 298
 		sqlite_close($db);			
@@ -306,10 +306,10 @@  discard block
 block discarded – undo
306 306
 	 * @param string the catalogue to delete from.
307 307
 	 * @return boolean true if deleted, false otherwise. 
308 308
 	 */
309
-	function delete($message, $catalogue='messages')
309
+	function delete($message, $catalogue = 'messages')
310 310
 	{
311 311
 		$details = $this->getCatalogueDetails($catalogue);
312
-		if($details)
312
+		if ($details)
313 313
 			list($cat_id, $variant, $count) = $details;
314 314
 		else
315 315
 			return false;
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
 						cat_id = {$cat_id} AND source = '{$message}'";
322 322
 		$deleted = false;
323 323
 				
324
-		if(sqlite_query($statement, $db))
324
+		if (sqlite_query($statement, $db))
325 325
 			$deleted = $this->updateCatalogueTime($cat_id, $variant, $db);		
326 326
 			
327 327
 		sqlite_close($db);	
@@ -339,10 +339,10 @@  discard block
 block discarded – undo
339 339
 		$statement = 'SELECT name FROM catalogue ORDER BY name';
340 340
 		$rs = sqlite_query($statement, $db);
341 341
 		$result = array();
342
-		while($row = sqlite_fetch_array($rs,SQLITE_NUM))
342
+		while ($row = sqlite_fetch_array($rs, SQLITE_NUM))
343 343
 		{
344
-			$details = explode('.',$row[0]);
345
-			if(!isset($details[1])) $details[1] = null;
344
+			$details = explode('.', $row[0]);
345
+			if (!isset($details[1])) $details[1] = null;
346 346
 			
347 347
 			$result[] = $details;
348 348
 		}
Please login to merge, or discard this patch.
framework/I18N/core/MessageSource_XLIFF.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -486,6 +486,9 @@
 block discarded – undo
486 486
 		return false;
487 487
 	}
488 488
 
489
+	/**
490
+	 * @param string $catalogue
491
+	 */
489 492
 	protected function createMessageTemplate($catalogue)
490 493
 	{
491 494
 		if($catalogue === null) {
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -290,7 +290,7 @@
 block discarded – undo
290 290
 
291 291
 		//find the body element
292 292
 		$xpath = new DomXPath($dom);
293
-    	$body = $xpath->query('//body')->item(0);
293
+		$body = $xpath->query('//body')->item(0);
294 294
 
295 295
 		$lastNodes = $xpath->query('//trans-unit[last()]');
296 296
 		if(($last=$lastNodes->item(0))!==null) {
Please login to merge, or discard this patch.
Spacing   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 /**
21 21
  * Get the MessageSource class file.
22 22
  */
23
-require_once(dirname(__FILE__).'/MessageSource.php');
23
+require_once(dirname(__FILE__) . '/MessageSource.php');
24 24
 
25 25
 /**
26 26
  * MessageSource_XLIFF class.
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 	 */
59 59
 	function __construct($source)
60 60
 	{
61
-		$this->source = (string)$source;
61
+		$this->source = (string) $source;
62 62
 	}
63 63
 
64 64
 	/**
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	protected function &loadData($filename)
70 70
 	{
71 71
 		//load it.
72
-		if(false === ($XML = simplexml_load_file($filename))) {
72
+		if (false === ($XML = simplexml_load_file($filename))) {
73 73
 			return false;
74 74
 		}
75 75
 
@@ -77,12 +77,12 @@  discard block
 block discarded – undo
77 77
 
78 78
 		$translations = array();
79 79
 
80
-		foreach($translationUnit as $unit)
80
+		foreach ($translationUnit as $unit)
81 81
 		{
82
-			$source = (string)$unit->source;
83
-			$translations[$source][] = (string)$unit->target;
84
-			$translations[$source][] = (string)$unit['id'];
85
-			$translations[$source][] = (string)$unit->note;
82
+			$source = (string) $unit->source;
83
+			$translations[$source][] = (string) $unit->target;
84
+			$translations[$source][] = (string) $unit['id'];
85
+			$translations[$source][] = (string) $unit->note;
86 86
 		}
87 87
 
88 88
 		return $translations;
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 	 */
108 108
 	protected function getSource($variant)
109 109
 	{
110
-		return $this->source.'/'.$variant;
110
+		return $this->source . '/' . $variant;
111 111
 	}
112 112
 
113 113
 	/**
@@ -127,25 +127,25 @@  discard block
 block discarded – undo
127 127
 	 */
128 128
 	protected function getCatalogueList($catalogue)
129 129
 	{
130
-		$variants = explode('_',$this->culture);
131
-		$source = $catalogue.$this->dataExt;
130
+		$variants = explode('_', $this->culture);
131
+		$source = $catalogue . $this->dataExt;
132 132
 		$catalogues = array($source);
133 133
 		$variant = null;
134 134
 
135
-		for($i = 0, $k = count($variants); $i < $k; ++$i)
135
+		for ($i = 0, $k = count($variants); $i < $k; ++$i)
136 136
 		{
137
-			if(isset($variants[$i]{0}))
137
+			if (isset($variants[$i]{0}))
138 138
 			{
139
-				$variant .= ($variant)?'_'.$variants[$i]:$variants[$i];
140
-				$catalogues[] = $catalogue.$this->dataSeparator.$variant.$this->dataExt;
139
+				$variant .= ($variant) ? '_' . $variants[$i] : $variants[$i];
140
+				$catalogues[] = $catalogue . $this->dataSeparator . $variant . $this->dataExt;
141 141
 			}
142 142
 		}
143 143
 
144 144
 		$byDir = $this->getCatalogueByDir($catalogue);
145
-		$catalogues = array_merge($byDir,array_reverse($catalogues));
145
+		$catalogues = array_merge($byDir, array_reverse($catalogues));
146 146
 		$files = array();
147 147
 
148
-		foreach($catalogues as $file)
148
+		foreach ($catalogues as $file)
149 149
 		{
150 150
 			$files[] = $file;
151 151
 			$files[] = preg_replace('/\.xml$/', '.xlf', $file);
@@ -163,16 +163,16 @@  discard block
 block discarded – undo
163 163
 	 */
164 164
 	private function getCatalogueByDir($catalogue)
165 165
 	{
166
-		$variants = explode('_',$this->culture);
166
+		$variants = explode('_', $this->culture);
167 167
 		$catalogues = array();
168 168
 		$variant = null;
169 169
 
170
-		for($i = 0, $k = count($variants); $i < $k; ++$i)
170
+		for ($i = 0, $k = count($variants); $i < $k; ++$i)
171 171
 		{
172
-			if(isset($variants[$i]{0}))
172
+			if (isset($variants[$i]{0}))
173 173
 			{
174
-				$variant .= ($variant)?'_'.$variants[$i]:$variants[$i];
175
-				$catalogues[] = $variant.'/'.$catalogue.$this->dataExt;
174
+				$variant .= ($variant) ? '_' . $variants[$i] : $variants[$i];
175
+				$catalogues[] = $variant . '/' . $catalogue . $this->dataExt;
176 176
 			}
177 177
 		}
178 178
 
@@ -196,32 +196,32 @@  discard block
 block discarded – undo
196 196
 	 * E.g. array('messages','en_AU')
197 197
 	 * @return array list of catalogues
198 198
 	 */
199
-	protected function getCatalogues($dir=null,$variant=null)
199
+	protected function getCatalogues($dir = null, $variant = null)
200 200
 	{
201
-		$dir = $dir?$dir:$this->source;
201
+		$dir = $dir ? $dir : $this->source;
202 202
 		$files = scandir($dir);
203 203
 		$catalogue = array();
204 204
 
205
-		foreach($files as $file)
205
+		foreach ($files as $file)
206 206
 		{
207
-			if(is_dir($dir.'/'.$file) && preg_match('/^[a-z]{2}(_[A-Z]{2,3})?$/',$file)) {
207
+			if (is_dir($dir . '/' . $file) && preg_match('/^[a-z]{2}(_[A-Z]{2,3})?$/', $file)) {
208 208
 				$catalogue = array_merge(
209 209
 					$catalogue,
210
-					$this->getCatalogues($dir.'/'.$file, $file)
210
+					$this->getCatalogues($dir . '/' . $file, $file)
211 211
 				);
212 212
 			}
213 213
 
214
-			$pos = strpos($file,$this->dataExt);
215
-			if($pos >0 && substr($file, -1*strlen($this->dataExt)) == $this->dataExt)
214
+			$pos = strpos($file, $this->dataExt);
215
+			if ($pos > 0 && substr($file, -1 * strlen($this->dataExt)) == $this->dataExt)
216 216
 			{
217
-				$name = substr($file,0,$pos);
218
-				$dot = strrpos($name,$this->dataSeparator);
217
+				$name = substr($file, 0, $pos);
218
+				$dot = strrpos($name, $this->dataSeparator);
219 219
 				$culture = $variant;
220 220
 				$cat = $name;
221 221
 
222
-				if(is_int($dot))
222
+				if (is_int($dot))
223 223
 				{
224
-					$culture = substr($name, $dot+1, strlen($name));
224
+					$culture = substr($name, $dot + 1, strlen($name));
225 225
 					$cat = substr($name, 0, $dot);
226 226
 				}
227 227
 
@@ -242,16 +242,16 @@  discard block
 block discarded – undo
242 242
 	 * @see update()
243 243
 	 * @see delete()
244 244
 	 */
245
-	private function getVariants($catalogue='messages')
245
+	private function getVariants($catalogue = 'messages')
246 246
 	{
247
-		if($catalogue === null) {
247
+		if ($catalogue === null) {
248 248
 			$catalogue = 'messages';
249 249
 		}
250 250
 
251
-		foreach($this->getCatalogueList($catalogue) as $variant)
251
+		foreach ($this->getCatalogueList($catalogue) as $variant)
252 252
 		{
253 253
 			$file = $this->getSource($variant);
254
-			if(is_file($file)) {
254
+			if (is_file($file)) {
255 255
 				return array($variant, $file);
256 256
 			}
257 257
 		}
@@ -265,22 +265,22 @@  discard block
 block discarded – undo
265 265
 	 * @param string the catalogue to add to
266 266
 	 * @return boolean true if saved successfuly, false otherwise.
267 267
 	 */
268
-	public function save($catalogue='messages')
268
+	public function save($catalogue = 'messages')
269 269
 	{
270 270
 		$messages = $this->untranslated;
271
-		if(count($messages) <= 0) {
271
+		if (count($messages) <= 0) {
272 272
 			return false;
273 273
 		}
274 274
 
275 275
 		$variants = $this->getVariants($catalogue);
276 276
 
277
-		if($variants) {
277
+		if ($variants) {
278 278
 			list($variant, $filename) = $variants;
279 279
 		} else {
280 280
 			list($variant, $filename) = $this->createMessageTemplate($catalogue);
281 281
 		}
282 282
 
283
-		if(is_writable($filename) == false) {
283
+		if (is_writable($filename) == false) {
284 284
 			throw new TIOException("Unable to save to file {$filename}, file must be writable.");
285 285
 		}
286 286
 
@@ -293,17 +293,17 @@  discard block
 block discarded – undo
293 293
     	$body = $xpath->query('//body')->item(0);
294 294
 
295 295
 		$lastNodes = $xpath->query('//trans-unit[last()]');
296
-		if(($last=$lastNodes->item(0))!==null) {
297
-			$count = (int)$last->getAttribute('id');
296
+		if (($last = $lastNodes->item(0)) !== null) {
297
+			$count = (int) $last->getAttribute('id');
298 298
 		} else {
299 299
 			$count = 0;
300 300
 		}
301 301
 
302 302
 		//for each message add it to the XML file using DOM
303
-		foreach($messages as $message)
303
+		foreach ($messages as $message)
304 304
 		{
305 305
 			$unit = $dom->createElement('trans-unit');
306
-			$unit->setAttribute('id',++$count);
306
+			$unit->setAttribute('id', ++$count);
307 307
 
308 308
 			$source = $dom->createElement('source');
309 309
 			$source->appendChild($dom->createCDATASection($message));
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
 
329 329
 		//save it and clear the cache for this variant
330 330
 		$dom->save($filename);
331
-		if(!empty($this->cache)) {
331
+		if (!empty($this->cache)) {
332 332
 			$this->cache->clean($variant, $this->culture);
333 333
 		}
334 334
 
@@ -343,17 +343,17 @@  discard block
 block discarded – undo
343 343
 	 * @param string the catalogue to save to.
344 344
 	 * @return boolean true if translation was updated, false otherwise.
345 345
 	 */
346
-	public function update($text, $target, $comments, $catalogue='messages')
346
+	public function update($text, $target, $comments, $catalogue = 'messages')
347 347
 	{
348 348
 		$variants = $this->getVariants($catalogue);
349 349
 
350
-		if($variants) {
350
+		if ($variants) {
351 351
 			list($variant, $filename) = $variants;
352 352
 		} else {
353 353
 			return false;
354 354
 		}
355 355
 
356
-		if(is_writable($filename) == false) {
356
+		if (is_writable($filename) == false) {
357 357
 			throw new TIOException("Unable to update file {$filename}, file must be writable.");
358 358
 		}
359 359
 
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
 		$units = $xpath->query('//trans-unit');
366 366
 
367 367
 		//for each of the existin units
368
-		foreach($units as $unit)
368
+		foreach ($units as $unit)
369 369
 		{
370 370
 			$found = false;
371 371
 			$targetted = false;
@@ -373,25 +373,25 @@  discard block
 block discarded – undo
373 373
 
374 374
 			//in each unit, need to find the source, target and comment nodes
375 375
 			//it will assume that the source is before the target.
376
-			foreach($unit->childNodes as $node)
376
+			foreach ($unit->childNodes as $node)
377 377
 			{
378 378
 				//source node
379
-				if($node->nodeName == 'source' && $node->firstChild->wholeText == $text) {
379
+				if ($node->nodeName == 'source' && $node->firstChild->wholeText == $text) {
380 380
 					$found = true;
381 381
 				}
382 382
 
383 383
 				//found source, get the target and notes
384
-				if($found)
384
+				if ($found)
385 385
 				{
386 386
 					//set the new translated string
387
-					if($node->nodeName == 'target')
387
+					if ($node->nodeName == 'target')
388 388
 					{
389 389
 						$node->nodeValue = $target;
390 390
 						$targetted = true;
391 391
 					}
392 392
 
393 393
 					//set the notes
394
-					if(!empty($comments) && $node->nodeName == 'note')
394
+					if (!empty($comments) && $node->nodeName == 'note')
395 395
 					{
396 396
 						$node->nodeValue = $comments;
397 397
 						$commented = true;
@@ -400,17 +400,17 @@  discard block
 block discarded – undo
400 400
 			}
401 401
 
402 402
 			//append a target
403
-			if($found && !$targetted) {
404
-				$unit->appendChild($dom->createElement('target',$target));
403
+			if ($found && !$targetted) {
404
+				$unit->appendChild($dom->createElement('target', $target));
405 405
 			}
406 406
 
407 407
 			//append a note
408
-			if($found && !$commented && !empty($comments)) {
409
-				$unit->appendChild($dom->createElement('note',$comments));
408
+			if ($found && !$commented && !empty($comments)) {
409
+				$unit->appendChild($dom->createElement('note', $comments));
410 410
 			}
411 411
 
412 412
 			//finished searching
413
-			if($found) {
413
+			if ($found) {
414 414
 				break;
415 415
 			}
416 416
 		}
@@ -418,9 +418,9 @@  discard block
 block discarded – undo
418 418
 		$fileNode = $xpath->query('//file')->item(0);
419 419
 		$fileNode->setAttribute('date', @date('Y-m-d\TH:i:s\Z'));
420 420
 
421
-		if($dom->save($filename) >0)
421
+		if ($dom->save($filename) > 0)
422 422
 		{
423
-			if(!empty($this->cache)) {
423
+			if (!empty($this->cache)) {
424 424
 				$this->cache->clean($variant, $this->culture);
425 425
 			}
426 426
 
@@ -436,16 +436,16 @@  discard block
 block discarded – undo
436 436
 	 * @param string the catalogue to delete from.
437 437
 	 * @return boolean true if deleted, false otherwise.
438 438
 	 */
439
-	public function delete($message, $catalogue='messages')
439
+	public function delete($message, $catalogue = 'messages')
440 440
 	{
441 441
 		$variants = $this->getVariants($catalogue);
442
-		if($variants) {
442
+		if ($variants) {
443 443
 			list($variant, $filename) = $variants;
444 444
 		} else {
445 445
 			return false;
446 446
 		}
447 447
 
448
-		if(is_writable($filename) == false) {
448
+		if (is_writable($filename) == false) {
449 449
 			throw new TIOException("Unable to modify file {$filename}, file must be writable.");
450 450
 		}
451 451
 
@@ -457,22 +457,22 @@  discard block
 block discarded – undo
457 457
 		$units = $xpath->query('//trans-unit');
458 458
 
459 459
 		//for each of the existin units
460
-		foreach($units as $unit)
460
+		foreach ($units as $unit)
461 461
 		{
462 462
 			//in each unit, need to find the source, target and comment nodes
463 463
 			//it will assume that the source is before the target.
464
-			foreach($unit->childNodes as $node)
464
+			foreach ($unit->childNodes as $node)
465 465
 			{
466 466
 				//source node
467
-				if($node->nodeName == 'source' && $node->firstChild->wholeText == $message)
467
+				if ($node->nodeName == 'source' && $node->firstChild->wholeText == $message)
468 468
 				{
469 469
 					//we found it, remove and save the xml file.
470 470
 					$unit->parentNode->removeChild($unit);
471 471
 					$fileNode = $xpath->query('//file')->item(0);
472 472
 					$fileNode->setAttribute('date', @date('Y-m-d\TH:i:s\Z'));
473 473
 
474
-					if(false !== $dom->save($filename)) {
475
-						if(!empty($this->cache)) {
474
+					if (false !== $dom->save($filename)) {
475
+						if (!empty($this->cache)) {
476 476
 							$this->cache->clean($variant, $this->culture);
477 477
 						}
478 478
 						return true;
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
 
489 489
 	protected function createMessageTemplate($catalogue)
490 490
 	{
491
-		if($catalogue === null) {
491
+		if ($catalogue === null) {
492 492
 			$catalogue = 'messages';
493 493
 		}
494 494
 		
@@ -497,12 +497,12 @@  discard block
 block discarded – undo
497 497
 		$file = $this->getSource($variant);
498 498
 		$dir = dirname($file);
499 499
 
500
-		if(!is_dir($dir)) {
500
+		if (!is_dir($dir)) {
501 501
 			@mkdir($dir);
502
-			@chmod($dir,PRADO_CHMOD);
502
+			@chmod($dir, PRADO_CHMOD);
503 503
 		}
504 504
 
505
-		if(!is_dir($dir)) {
505
+		if (!is_dir($dir)) {
506 506
 			throw new TException("Unable to create directory $dir");
507 507
 		}
508 508
 		
Please login to merge, or discard this patch.
framework/I18N/core/NumberFormatInfo.php 4 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -170,6 +170,7 @@
 block discarded – undo
170 170
      * @param int the number formatting type, it should be
171 171
      * NumberFormatInfo::DECIMAL, NumberFormatInfo::CURRENCY,
172 172
      * NumberFormatInfo::PERCENTAGE, or NumberFormatInfo::SCIENTIFIC
173
+     * @param integer $type
173 174
      * @return NumberFormatInfo NumberFormatInfo for the specified
174 175
      * culture.
175 176
      * @see getCurrencyInstance();
Please login to merge, or discard this patch.
Indentation   +368 added lines, -368 removed lines patch added patch discarded remove patch
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 	/**
123 123
 	 * Set the pattern for a specific number pattern. The validate patterns
124 124
 	 * NumberFormatInfo::DECIMAL, NumberFormatInfo::CURRENCY,
125
-     * NumberFormatInfo::PERCENTAGE, or NumberFormatInfo::SCIENTIFIC
125
+	 * NumberFormatInfo::PERCENTAGE, or NumberFormatInfo::SCIENTIFIC
126 126
 	 * @param int pattern type.
127 127
 	 */
128 128
 	public function setPattern($type=NumberFormatInfo::DECIMAL)
@@ -152,94 +152,94 @@  discard block
 block discarded – undo
152 152
 	 * (invariant).
153 153
 	 * @return NumberFormatInfo default NumberFormatInfo.
154 154
 	 */
155
-    public static function getInvariantInfo($type=NumberFormatInfo::DECIMAL)
156
-    {
157
-        static $invariant;
155
+	public static function getInvariantInfo($type=NumberFormatInfo::DECIMAL)
156
+	{
157
+		static $invariant;
158 158
 		if($invariant === null)
159
-        {
160
-            $culture = CultureInfo::getInvariantCulture();
161
-            $invariant = $culture->NumberFormat;
162
-            $invariant->setPattern($type);
163
-        }
159
+		{
160
+			$culture = CultureInfo::getInvariantCulture();
161
+			$invariant = $culture->NumberFormat;
162
+			$invariant->setPattern($type);
163
+		}
164 164
 		return $invariant;
165
-    }
166
-
167
-    /**
168
-     * Returns the NumberFormatInfo associated with the specified culture.
169
-     * @param CultureInfo the culture that gets the NumberFormat property.
170
-     * @param int the number formatting type, it should be
171
-     * NumberFormatInfo::DECIMAL, NumberFormatInfo::CURRENCY,
172
-     * NumberFormatInfo::PERCENTAGE, or NumberFormatInfo::SCIENTIFIC
173
-     * @return NumberFormatInfo NumberFormatInfo for the specified
174
-     * culture.
175
-     * @see getCurrencyInstance();
176
-     * @see getPercentageInstance();
177
-     * @see getScientificInstance();
178
-     */
179
-    public static function getInstance($culture=null,
180
-    								   $type=NumberFormatInfo::DECIMAL)
181
-    {
165
+	}
166
+
167
+	/**
168
+	 * Returns the NumberFormatInfo associated with the specified culture.
169
+	 * @param CultureInfo the culture that gets the NumberFormat property.
170
+	 * @param int the number formatting type, it should be
171
+	 * NumberFormatInfo::DECIMAL, NumberFormatInfo::CURRENCY,
172
+	 * NumberFormatInfo::PERCENTAGE, or NumberFormatInfo::SCIENTIFIC
173
+	 * @return NumberFormatInfo NumberFormatInfo for the specified
174
+	 * culture.
175
+	 * @see getCurrencyInstance();
176
+	 * @see getPercentageInstance();
177
+	 * @see getScientificInstance();
178
+	 */
179
+	public static function getInstance($culture=null,
180
+									   $type=NumberFormatInfo::DECIMAL)
181
+	{
182 182
    		if ($culture instanceof CultureInfo)
183 183
    		{
184
-            $formatInfo = $culture->NumberFormat;
185
-            $formatInfo->setPattern($type);
186
-            return $formatInfo;
184
+			$formatInfo = $culture->NumberFormat;
185
+			$formatInfo->setPattern($type);
186
+			return $formatInfo;
187 187
    		}
188
-       	else if(is_string($culture))
189
-       	{
190
-       		$cultureInfo = new CultureInfo($culture);
191
-       		$formatInfo = $cultureInfo->NumberFormat;
192
-       		$formatInfo->setPattern($type);
193
-       		return $formatInfo;
194
-       	}
195
-       	else
196
-       	{
197
-            $cultureInfo = new CultureInfo();
198
-       		$formatInfo = $cultureInfo->NumberFormat;
199
-       		$formatInfo->setPattern($type);
200
-       		return $formatInfo;
201
-       	}
202
-    }
203
-
204
-    /**
205
-     * Returns the currency format info associated with the specified culture.
206
-     * @param CultureInfo the culture that gets the NumberFormat property.
207
-     * @return NumberFormatInfo NumberFormatInfo for the specified
208
-     * culture.
209
-     */
210
-    public static function getCurrencyInstance($culture=null)
211
-    {
212
-        return self::getInstance($culture, self::CURRENCY);
213
-    }
214
-
215
-    /**
216
-     * Returns the percentage format info associated with the specified culture.
217
-     * @param CultureInfo the culture that gets the NumberFormat property.
218
-     * @return NumberFormatInfo NumberFormatInfo for the specified
219
-     * culture.
220
-     */
221
-    public static function getPercentageInstance($culture=null)
222
-    {
223
-        return self::getInstance($culture, self::PERCENTAGE);
224
-    }
225
-
226
-    /**
227
-     * Returns the scientific format info associated with the specified culture.
228
-     * @param CultureInfo the culture that gets the NumberFormat property.
229
-     * @return NumberFormatInfo NumberFormatInfo for the specified
230
-     * culture.
231
-     */
232
-    public static function getScientificInstance($culture=null)
233
-    {
234
-        return self::getInstance($culture, self::SCIENTIFIC);
235
-    }
236
-
237
-    /**
238
-     * Parse the given pattern and return a list of known properties.
239
-     * @param string a number pattern.
240
-     * @return array list of pattern properties.
241
-     */
242
-    protected function parsePattern($pattern)
188
+	   	else if(is_string($culture))
189
+	   	{
190
+	   		$cultureInfo = new CultureInfo($culture);
191
+	   		$formatInfo = $cultureInfo->NumberFormat;
192
+	   		$formatInfo->setPattern($type);
193
+	   		return $formatInfo;
194
+	   	}
195
+	   	else
196
+	   	{
197
+			$cultureInfo = new CultureInfo();
198
+	   		$formatInfo = $cultureInfo->NumberFormat;
199
+	   		$formatInfo->setPattern($type);
200
+	   		return $formatInfo;
201
+	   	}
202
+	}
203
+
204
+	/**
205
+	 * Returns the currency format info associated with the specified culture.
206
+	 * @param CultureInfo the culture that gets the NumberFormat property.
207
+	 * @return NumberFormatInfo NumberFormatInfo for the specified
208
+	 * culture.
209
+	 */
210
+	public static function getCurrencyInstance($culture=null)
211
+	{
212
+		return self::getInstance($culture, self::CURRENCY);
213
+	}
214
+
215
+	/**
216
+	 * Returns the percentage format info associated with the specified culture.
217
+	 * @param CultureInfo the culture that gets the NumberFormat property.
218
+	 * @return NumberFormatInfo NumberFormatInfo for the specified
219
+	 * culture.
220
+	 */
221
+	public static function getPercentageInstance($culture=null)
222
+	{
223
+		return self::getInstance($culture, self::PERCENTAGE);
224
+	}
225
+
226
+	/**
227
+	 * Returns the scientific format info associated with the specified culture.
228
+	 * @param CultureInfo the culture that gets the NumberFormat property.
229
+	 * @return NumberFormatInfo NumberFormatInfo for the specified
230
+	 * culture.
231
+	 */
232
+	public static function getScientificInstance($culture=null)
233
+	{
234
+		return self::getInstance($culture, self::SCIENTIFIC);
235
+	}
236
+
237
+	/**
238
+	 * Parse the given pattern and return a list of known properties.
239
+	 * @param string a number pattern.
240
+	 * @return array list of pattern properties.
241
+	 */
242
+	protected function parsePattern($pattern)
243 243
 	{
244 244
 		$pattern = explode(';',$pattern);
245 245
 
@@ -355,296 +355,296 @@  discard block
 block discarded – undo
355 355
 	}
356 356
 
357 357
 
358
-    /**
359
-     * Indicates the number of decimal places.
360
-     * @return int number of decimal places.
361
-     */
362
-    function getDecimalDigits()
363
-    {
364
-    	return $this->pattern['decimalPoints'];
365
-    }
366
-
367
-    /**
368
-     * Set the number of decimal places.
369
-     * @param int number of decimal places.
370
-     */
371
-    function setDecimalDigits($value)
372
-    {
373
-    	return $this->pattern['decimalPoints'] = $value;
374
-    }
375
-
376
-    function getDigitSize()
377
-    {
378
-    	return $this->pattern['digitSize'];
379
-    }
380
-
381
-    function setDigitSize($value)
382
-    {
383
-    	$this->pattern['digitSize'] = $value;
384
-    }
385
-
386
-    /**
387
-     * Gets the string to use as the decimal separator.
388
-     * @return string decimal separator.
389
-     */
390
-    function getDecimalSeparator()
391
-    {
392
-    	return $this->data['NumberElements'][0];
393
-    }
394
-
395
-    /**
396
-     * Set the string to use as the decimal separator.
397
-     * @param string the decimal point
398
-     */
399
-    function setDecimalSeparator($value)
400
-    {
401
-    	return $this->data['NumberElements'][0] = $value;
402
-    }
403
-
404
-    /**
405
-     * Gets the string that separates groups of digits to the left
406
-     * of the decimal in currency values.
407
-     * @param parameter
408
-     * @return string currency group separator.
409
-     */
410
-    function getGroupSeparator()
411
-    {
412
-    	return $this->data['NumberElements'][1];
413
-    }
414
-
415
-    /**
416
-     * Set the string to use as the group separator.
417
-     * @param string the group separator.
418
-     */
419
-    function setGroupSeparator($value)
420
-    {
421
-    	return $this->data['NumberElements'][1] = $value;
422
-    }
423
-
424
-    /**
425
-     * Gets the number of digits in each group to the left of the decimal
426
-     * There can be two grouping sizes, this fucntion
427
-     * returns <b>array(group1, group2)</b>, if there is only 1 grouping size,
428
-     * group2 will be false.
429
-     * @return array grouping size(s).
430
-     */
431
-    function getGroupSizes()
432
-    {
433
-    	$group1 = $this->pattern['groupSize1'];
434
-    	$group2 = $this->pattern['groupSize2'];
435
-
436
-    	return array($group1, $group2);
437
-    }
438
-
439
-    /**
440
-     * Set the number of digits in each group to the left of the decimal.
441
-     * There can be two grouping sizes, the value should
442
-     * be an <b>array(group1, group2)</b>, if there is only 1 grouping size,
443
-     * group2 should be false.
444
-     * @param array grouping size(s).
445
-     */
446
-    function setGroupSizes($groupSize)
447
-    {
358
+	/**
359
+	 * Indicates the number of decimal places.
360
+	 * @return int number of decimal places.
361
+	 */
362
+	function getDecimalDigits()
363
+	{
364
+		return $this->pattern['decimalPoints'];
365
+	}
366
+
367
+	/**
368
+	 * Set the number of decimal places.
369
+	 * @param int number of decimal places.
370
+	 */
371
+	function setDecimalDigits($value)
372
+	{
373
+		return $this->pattern['decimalPoints'] = $value;
374
+	}
375
+
376
+	function getDigitSize()
377
+	{
378
+		return $this->pattern['digitSize'];
379
+	}
380
+
381
+	function setDigitSize($value)
382
+	{
383
+		$this->pattern['digitSize'] = $value;
384
+	}
385
+
386
+	/**
387
+	 * Gets the string to use as the decimal separator.
388
+	 * @return string decimal separator.
389
+	 */
390
+	function getDecimalSeparator()
391
+	{
392
+		return $this->data['NumberElements'][0];
393
+	}
394
+
395
+	/**
396
+	 * Set the string to use as the decimal separator.
397
+	 * @param string the decimal point
398
+	 */
399
+	function setDecimalSeparator($value)
400
+	{
401
+		return $this->data['NumberElements'][0] = $value;
402
+	}
403
+
404
+	/**
405
+	 * Gets the string that separates groups of digits to the left
406
+	 * of the decimal in currency values.
407
+	 * @param parameter
408
+	 * @return string currency group separator.
409
+	 */
410
+	function getGroupSeparator()
411
+	{
412
+		return $this->data['NumberElements'][1];
413
+	}
414
+
415
+	/**
416
+	 * Set the string to use as the group separator.
417
+	 * @param string the group separator.
418
+	 */
419
+	function setGroupSeparator($value)
420
+	{
421
+		return $this->data['NumberElements'][1] = $value;
422
+	}
423
+
424
+	/**
425
+	 * Gets the number of digits in each group to the left of the decimal
426
+	 * There can be two grouping sizes, this fucntion
427
+	 * returns <b>array(group1, group2)</b>, if there is only 1 grouping size,
428
+	 * group2 will be false.
429
+	 * @return array grouping size(s).
430
+	 */
431
+	function getGroupSizes()
432
+	{
433
+		$group1 = $this->pattern['groupSize1'];
434
+		$group2 = $this->pattern['groupSize2'];
435
+
436
+		return array($group1, $group2);
437
+	}
438
+
439
+	/**
440
+	 * Set the number of digits in each group to the left of the decimal.
441
+	 * There can be two grouping sizes, the value should
442
+	 * be an <b>array(group1, group2)</b>, if there is only 1 grouping size,
443
+	 * group2 should be false.
444
+	 * @param array grouping size(s).
445
+	 */
446
+	function setGroupSizes($groupSize)
447
+	{
448 448
    		$this->pattern['groupSize1'] = $groupSize[0];
449 449
    		$this->pattern['groupSize2'] = $groupSize[1];
450
-    }
451
-
452
-    /**
453
-     * Gets the format pattern for negative values.
454
-     * The negative pattern is composed of a prefix, and postfix.
455
-     * This function returns <b>array(prefix, postfix)</b>.
456
-     * @return arary negative pattern.
457
-     */
458
-    function getNegativePattern()
459
-    {
460
-    	$prefix = $this->pattern['negPref'];
461
-    	$postfix = $this->pattern['negPost'];
462
-    	return array($prefix, $postfix);
463
-    }
464
-
465
-    /**
466
-     * Set the format pattern for negative values.
467
-     * The negative pattern is composed of a prefix, and postfix in the form
468
-     * <b>array(prefix, postfix)</b>.
469
-     * @param arary negative pattern.
470
-     */
471
-    function setNegativePattern($pattern)
472
-    {
473
-    	$this->pattern['negPref'] = $pattern[0];
474
-    	$this->pattern['negPost'] = $pattern[1];
475
-    }
476
-
477
-    /**
478
-     * Gets the format pattern for positive values.
479
-     * The positive pattern is composed of a prefix, and postfix.
480
-     * This function returns <b>array(prefix, postfix)</b>.
481
-     * @return arary positive pattern.
482
-     */
483
-    function getPositivePattern()
484
-    {
485
-    	$prefix = $this->pattern['posPref'];
486
-    	$postfix = $this->pattern['posPost'];
487
-    	return array($prefix, $postfix);
488
-    }
489
-
490
-    /**
491
-     * Set the format pattern for positive values.
492
-     * The positive pattern is composed of a prefix, and postfix in the form
493
-     * <b>array(prefix, postfix)</b>.
494
-     * @param arary positive pattern.
495
-     */
496
-    function setPositivePattern($pattern)
497
-    {
498
-    	$this->pattern['posPref'] = $pattern[0];
499
-    	$this->pattern['posPost'] = $pattern[1];
500
-    }
501
-
502
-    /**
503
-     * Gets the string to use as the currency symbol.
504
-     * @return string currency symbol.
505
-     */
506
-    function getCurrencySymbol($currency='USD')
507
-    {
508
-    	if(isset($this->pattern['symbol']))
450
+	}
451
+
452
+	/**
453
+	 * Gets the format pattern for negative values.
454
+	 * The negative pattern is composed of a prefix, and postfix.
455
+	 * This function returns <b>array(prefix, postfix)</b>.
456
+	 * @return arary negative pattern.
457
+	 */
458
+	function getNegativePattern()
459
+	{
460
+		$prefix = $this->pattern['negPref'];
461
+		$postfix = $this->pattern['negPost'];
462
+		return array($prefix, $postfix);
463
+	}
464
+
465
+	/**
466
+	 * Set the format pattern for negative values.
467
+	 * The negative pattern is composed of a prefix, and postfix in the form
468
+	 * <b>array(prefix, postfix)</b>.
469
+	 * @param arary negative pattern.
470
+	 */
471
+	function setNegativePattern($pattern)
472
+	{
473
+		$this->pattern['negPref'] = $pattern[0];
474
+		$this->pattern['negPost'] = $pattern[1];
475
+	}
476
+
477
+	/**
478
+	 * Gets the format pattern for positive values.
479
+	 * The positive pattern is composed of a prefix, and postfix.
480
+	 * This function returns <b>array(prefix, postfix)</b>.
481
+	 * @return arary positive pattern.
482
+	 */
483
+	function getPositivePattern()
484
+	{
485
+		$prefix = $this->pattern['posPref'];
486
+		$postfix = $this->pattern['posPost'];
487
+		return array($prefix, $postfix);
488
+	}
489
+
490
+	/**
491
+	 * Set the format pattern for positive values.
492
+	 * The positive pattern is composed of a prefix, and postfix in the form
493
+	 * <b>array(prefix, postfix)</b>.
494
+	 * @param arary positive pattern.
495
+	 */
496
+	function setPositivePattern($pattern)
497
+	{
498
+		$this->pattern['posPref'] = $pattern[0];
499
+		$this->pattern['posPost'] = $pattern[1];
500
+	}
501
+
502
+	/**
503
+	 * Gets the string to use as the currency symbol.
504
+	 * @return string currency symbol.
505
+	 */
506
+	function getCurrencySymbol($currency='USD')
507
+	{
508
+		if(isset($this->pattern['symbol']))
509 509
 			return $this->pattern['symbol'];
510
-    	else
511
-    		return $this->data['Currencies'][$currency][0];
512
-    }
513
-
514
-
515
-    /**
516
-     * Set the string to use as the currency symbol.
517
-     * @param string currency symbol.
518
-     */
519
-    function setCurrencySymbol($symbol)
520
-    {
521
-    	$this->pattern['symbol'] = $symbol;
522
-    }
523
-
524
-    /**
525
-     * Gets the string that represents negative infinity.
526
-     * @return string negative infinity.
527
-     */
528
-    function getNegativeInfinitySymbol()
529
-    {
510
+		else
511
+			return $this->data['Currencies'][$currency][0];
512
+	}
513
+
514
+
515
+	/**
516
+	 * Set the string to use as the currency symbol.
517
+	 * @param string currency symbol.
518
+	 */
519
+	function setCurrencySymbol($symbol)
520
+	{
521
+		$this->pattern['symbol'] = $symbol;
522
+	}
523
+
524
+	/**
525
+	 * Gets the string that represents negative infinity.
526
+	 * @return string negative infinity.
527
+	 */
528
+	function getNegativeInfinitySymbol()
529
+	{
530 530
 		return $this->pattern['negInfty'];
531
-    }
532
-
533
-    /**
534
-     * Set the string that represents negative infinity.
535
-     * @param string negative infinity.
536
-     */
537
-    function setNegativeInfinitySymbol($value)
538
-    {
531
+	}
532
+
533
+	/**
534
+	 * Set the string that represents negative infinity.
535
+	 * @param string negative infinity.
536
+	 */
537
+	function setNegativeInfinitySymbol($value)
538
+	{
539 539
 		$this->pattern['negInfty'] = $value;
540
-    }
541
-
542
-    /**
543
-     * Gets the string that represents positive infinity.
544
-     * @return string positive infinity.
545
-     */
546
-    function getPositiveInfinitySymbol()
547
-    {
540
+	}
541
+
542
+	/**
543
+	 * Gets the string that represents positive infinity.
544
+	 * @return string positive infinity.
545
+	 */
546
+	function getPositiveInfinitySymbol()
547
+	{
548 548
 		return $this->pattern['posInfty'];
549
-    }
550
-
551
-    /**
552
-     * Set the string that represents positive infinity.
553
-     * @param string positive infinity.
554
-     */
555
-    function setPositiveInfinitySymbol($value)
556
-    {
549
+	}
550
+
551
+	/**
552
+	 * Set the string that represents positive infinity.
553
+	 * @param string positive infinity.
554
+	 */
555
+	function setPositiveInfinitySymbol($value)
556
+	{
557 557
 		$this->pattern['posInfty'] = $value;
558
-    }
559
-
560
-    /**
561
-     * Gets the string that denotes that the associated number is negative.
562
-     * @return string negative sign.
563
-     */
564
-    function getNegativeSign()
565
-    {
566
-    	return $this->data['NumberElements'][6];
567
-    }
568
-
569
-    /**
570
-     * Set the string that denotes that the associated number is negative.
571
-     * @param string negative sign.
572
-     */
573
-    function setNegativeSign($value)
574
-    {
575
-    	$this->data['NumberElements'][6] = $value;
576
-    }
577
-
578
-    /**
579
-     * Gets the string that denotes that the associated number is positive.
580
-     * @return string positive sign.
581
-     */
582
-    function getPositiveSign()
583
-    {
584
-    	return $this->data['NumberElements'][11];
585
-    }
586
-
587
-    /**
588
-     * Set the string that denotes that the associated number is positive.
589
-     * @param string positive sign.
590
-     */
591
-    function setPositiveSign($value)
592
-    {
593
-    	$this->data['NumberElements'][11] = $value;
594
-    }
595
-
596
-    /**
597
-     * Gets the string that represents the IEEE NaN (not a number) value.
598
-     * @return string NaN symbol.
599
-     */
600
-    function getNaNSymbol()
601
-    {
602
-    	return $this->data['NumberElements'][10];
603
-    }
604
-
605
-    /**
606
-     * Set the string that represents the IEEE NaN (not a number) value.
607
-     * @param string NaN symbol.
608
-     */
609
-    function setNaNSymbol($value)
610
-    {
611
-    	$this->data['NumberElements'][10] = $value;
612
-    }
613
-
614
-    /**
615
-     * Gets the string to use as the percent symbol.
616
-     * @return string percent symbol.
617
-     */
618
-    function getPercentSymbol()
619
-    {
620
-    	return $this->data['NumberElements'][3];
621
-    }
622
-
623
-    /**
624
-     * Set the string to use as the percent symbol.
625
-     * @param string percent symbol.
626
-     */
627
-    function setPercentSymbol($value)
628
-    {
629
-    	$this->data['NumberElements'][3] = $value;
630
-    }
631
-
632
-    /**
633
-     * Gets the string to use as the per mille symbol.
634
-     * @return string percent symbol.
635
-     */
636
-    function getPerMilleSymbol()
637
-    {
638
-    	return $this->data['NumberElements'][8];
639
-    }
640
-
641
-    /**
642
-     * Set the string to use as the per mille symbol.
643
-     * @param string percent symbol.
644
-     */
645
-    function setPerMilleSymbol($value)
646
-    {
647
-    	$this->data['NumberElements'][8] = $value;
648
-    }
558
+	}
559
+
560
+	/**
561
+	 * Gets the string that denotes that the associated number is negative.
562
+	 * @return string negative sign.
563
+	 */
564
+	function getNegativeSign()
565
+	{
566
+		return $this->data['NumberElements'][6];
567
+	}
568
+
569
+	/**
570
+	 * Set the string that denotes that the associated number is negative.
571
+	 * @param string negative sign.
572
+	 */
573
+	function setNegativeSign($value)
574
+	{
575
+		$this->data['NumberElements'][6] = $value;
576
+	}
577
+
578
+	/**
579
+	 * Gets the string that denotes that the associated number is positive.
580
+	 * @return string positive sign.
581
+	 */
582
+	function getPositiveSign()
583
+	{
584
+		return $this->data['NumberElements'][11];
585
+	}
586
+
587
+	/**
588
+	 * Set the string that denotes that the associated number is positive.
589
+	 * @param string positive sign.
590
+	 */
591
+	function setPositiveSign($value)
592
+	{
593
+		$this->data['NumberElements'][11] = $value;
594
+	}
595
+
596
+	/**
597
+	 * Gets the string that represents the IEEE NaN (not a number) value.
598
+	 * @return string NaN symbol.
599
+	 */
600
+	function getNaNSymbol()
601
+	{
602
+		return $this->data['NumberElements'][10];
603
+	}
604
+
605
+	/**
606
+	 * Set the string that represents the IEEE NaN (not a number) value.
607
+	 * @param string NaN symbol.
608
+	 */
609
+	function setNaNSymbol($value)
610
+	{
611
+		$this->data['NumberElements'][10] = $value;
612
+	}
613
+
614
+	/**
615
+	 * Gets the string to use as the percent symbol.
616
+	 * @return string percent symbol.
617
+	 */
618
+	function getPercentSymbol()
619
+	{
620
+		return $this->data['NumberElements'][3];
621
+	}
622
+
623
+	/**
624
+	 * Set the string to use as the percent symbol.
625
+	 * @param string percent symbol.
626
+	 */
627
+	function setPercentSymbol($value)
628
+	{
629
+		$this->data['NumberElements'][3] = $value;
630
+	}
631
+
632
+	/**
633
+	 * Gets the string to use as the per mille symbol.
634
+	 * @return string percent symbol.
635
+	 */
636
+	function getPerMilleSymbol()
637
+	{
638
+		return $this->data['NumberElements'][8];
639
+	}
640
+
641
+	/**
642
+	 * Set the string to use as the per mille symbol.
643
+	 * @param string percent symbol.
644
+	 */
645
+	function setPerMilleSymbol($value)
646
+	{
647
+		$this->data['NumberElements'][8] = $value;
648
+	}
649 649
 }
650 650
 
Please login to merge, or discard this patch.
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 /**
21 21
  * Get the CultureInfo class file.
22 22
  */
23
-require_once(dirname(__FILE__).'/CultureInfo.php');
23
+require_once(dirname(__FILE__) . '/CultureInfo.php');
24 24
 
25 25
 /**
26 26
  * NumberFormatInfo class
@@ -78,11 +78,11 @@  discard block
 block discarded – undo
78 78
 	 */
79 79
 	public function __get($name)
80 80
 	{
81
-		$getProperty = 'get'.$name;
82
-		if(in_array($getProperty, $this->properties))
81
+		$getProperty = 'get' . $name;
82
+		if (in_array($getProperty, $this->properties))
83 83
 			return $this->$getProperty();
84 84
 		else
85
-			throw new Exception('Property '.$name.' does not exists.');
85
+			throw new Exception('Property ' . $name . ' does not exists.');
86 86
 	}
87 87
 
88 88
 	/**
@@ -91,11 +91,11 @@  discard block
 block discarded – undo
91 91
 	 */
92 92
 	public function __set($name, $value)
93 93
 	{
94
-		$setProperty = 'set'.$name;
95
-		if(in_array($setProperty, $this->properties))
94
+		$setProperty = 'set' . $name;
95
+		if (in_array($setProperty, $this->properties))
96 96
 			$this->$setProperty($value);
97 97
 		else
98
-			throw new Exception('Property '.$name.' can not be set.');
98
+			throw new Exception('Property ' . $name . ' can not be set.');
99 99
 	}
100 100
 
101 101
 	/**
@@ -107,11 +107,11 @@  discard block
 block discarded – undo
107 107
 	 * @param array ICU data for date time formatting.
108 108
 	 * @see getInstance()
109 109
 	 */
110
-	public function __construct($data=array(), $type=NumberFormatInfo::DECIMAL)
110
+	public function __construct($data = array(), $type = NumberFormatInfo::DECIMAL)
111 111
 	{
112 112
 		$this->properties = get_class_methods($this);
113 113
 
114
-		if(empty($data))
114
+		if (empty($data))
115 115
 			throw new Exception('Please provide the ICU data to initialize.');
116 116
 
117 117
 		$this->data = $data;
@@ -125,20 +125,20 @@  discard block
 block discarded – undo
125 125
      * NumberFormatInfo::PERCENTAGE, or NumberFormatInfo::SCIENTIFIC
126 126
 	 * @param int pattern type.
127 127
 	 */
128
-	public function setPattern($type=NumberFormatInfo::DECIMAL)
128
+	public function setPattern($type = NumberFormatInfo::DECIMAL)
129 129
 	{
130
-		if(is_int($type))
130
+		if (is_int($type))
131 131
 			$this->pattern =
132 132
 				$this->parsePattern($this->data['NumberPatterns'][$type]);
133 133
 		else
134 134
 			$this->pattern = $this->parsePattern($type);
135 135
 
136 136
 		$this->pattern['negInfty'] =
137
-			$this->data['NumberElements'][6].
137
+			$this->data['NumberElements'][6] .
138 138
 			$this->data['NumberElements'][9];
139 139
 
140 140
 		$this->pattern['posInfty'] =
141
-			$this->data['NumberElements'][11].
141
+			$this->data['NumberElements'][11] .
142 142
 			$this->data['NumberElements'][9];
143 143
 	}
144 144
 
@@ -152,10 +152,10 @@  discard block
 block discarded – undo
152 152
 	 * (invariant).
153 153
 	 * @return NumberFormatInfo default NumberFormatInfo.
154 154
 	 */
155
-    public static function getInvariantInfo($type=NumberFormatInfo::DECIMAL)
155
+    public static function getInvariantInfo($type = NumberFormatInfo::DECIMAL)
156 156
     {
157 157
         static $invariant;
158
-		if($invariant === null)
158
+		if ($invariant === null)
159 159
         {
160 160
             $culture = CultureInfo::getInvariantCulture();
161 161
             $invariant = $culture->NumberFormat;
@@ -176,8 +176,8 @@  discard block
 block discarded – undo
176 176
      * @see getPercentageInstance();
177 177
      * @see getScientificInstance();
178 178
      */
179
-    public static function getInstance($culture=null,
180
-    								   $type=NumberFormatInfo::DECIMAL)
179
+    public static function getInstance($culture = null,
180
+    								   $type = NumberFormatInfo::DECIMAL)
181 181
     {
182 182
    		if ($culture instanceof CultureInfo)
183 183
    		{
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
             $formatInfo->setPattern($type);
186 186
             return $formatInfo;
187 187
    		}
188
-       	else if(is_string($culture))
188
+       	else if (is_string($culture))
189 189
        	{
190 190
        		$cultureInfo = new CultureInfo($culture);
191 191
        		$formatInfo = $cultureInfo->NumberFormat;
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
      * @return NumberFormatInfo NumberFormatInfo for the specified
208 208
      * culture.
209 209
      */
210
-    public static function getCurrencyInstance($culture=null)
210
+    public static function getCurrencyInstance($culture = null)
211 211
     {
212 212
         return self::getInstance($culture, self::CURRENCY);
213 213
     }
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
      * @return NumberFormatInfo NumberFormatInfo for the specified
219 219
      * culture.
220 220
      */
221
-    public static function getPercentageInstance($culture=null)
221
+    public static function getPercentageInstance($culture = null)
222 222
     {
223 223
         return self::getInstance($culture, self::PERCENTAGE);
224 224
     }
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
      * @return NumberFormatInfo NumberFormatInfo for the specified
230 230
      * culture.
231 231
      */
232
-    public static function getScientificInstance($culture=null)
232
+    public static function getScientificInstance($culture = null)
233 233
     {
234 234
         return self::getInstance($culture, self::SCIENTIFIC);
235 235
     }
@@ -241,10 +241,10 @@  discard block
 block discarded – undo
241 241
      */
242 242
     protected function parsePattern($pattern)
243 243
 	{
244
-		$pattern = explode(';',$pattern);
244
+		$pattern = explode(';', $pattern);
245 245
 
246 246
 		$negative = null;
247
-		if(count($pattern) > 1)
247
+		if (count($pattern) > 1)
248 248
 			$negative = $pattern[1];
249 249
 		$pattern = $pattern[0];
250 250
 
@@ -254,13 +254,13 @@  discard block
 block discarded – undo
254 254
 		$hash = '#';
255 255
 
256 256
 		//find the first group point, and decimal point
257
-		$groupPos1 = strrpos($pattern,$comma);
258
-		$decimalPos = strrpos($pattern,$dot);
257
+		$groupPos1 = strrpos($pattern, $comma);
258
+		$decimalPos = strrpos($pattern, $dot);
259 259
 
260 260
 		$groupPos2 = false;
261 261
 		$groupSize1 = false;
262 262
 		$groupSize2 = false;
263
-		$decimalPoints = is_int($decimalPos)?-1:false;
263
+		$decimalPoints = is_int($decimalPos) ?-1 : false;
264 264
 
265 265
 		$info['negPref'] = $this->data['NumberElements'][6];
266 266
 		$info['negPost'] = '';
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
 		$info['positive'] = $pattern;
270 270
 
271 271
 		//find the negative prefix and postfix
272
-		if($negative)
272
+		if ($negative)
273 273
 		{
274 274
 			$prefixPostfix = $this->getPrePostfix($negative);
275 275
 			$info['negPref'] = $prefixPostfix[0];
@@ -282,24 +282,24 @@  discard block
 block discarded – undo
282 282
 
283 283
 		//var_dump($pattern);
284 284
 		//var_dump($decimalPos);
285
-		if(is_int($groupPos1))
285
+		if (is_int($groupPos1))
286 286
 		{
287 287
 			//get the second group
288
-			$groupPos2 = strrpos(substr($pattern,0,$groupPos1),$comma);
288
+			$groupPos2 = strrpos(substr($pattern, 0, $groupPos1), $comma);
289 289
 
290 290
 			//get the number of decimal digits
291
-			if(is_int($decimalPos))
291
+			if (is_int($decimalPos))
292 292
 			{
293
-				$groupSize1 = $decimalPos - $groupPos1-1;
293
+				$groupSize1 = $decimalPos - $groupPos1 - 1;
294 294
 
295 295
 			}
296 296
 			else
297 297
 			{
298 298
 				//no decimal point, so traverse from the back
299 299
 				//to find the groupsize 1.
300
-				for($i=strlen($pattern)-1; $i>=0; $i--)
300
+				for ($i = strlen($pattern) - 1; $i >= 0; $i--)
301 301
 				{
302
-					if($pattern{$i} == $digit || $pattern{$i}==$hash)
302
+					if ($pattern{$i} == $digit || $pattern{$i} == $hash)
303 303
 					{
304 304
 						$groupSize1 = $i - $groupPos1;
305 305
 						break;
@@ -308,16 +308,16 @@  discard block
 block discarded – undo
308 308
 			}
309 309
 
310 310
 			//get the second group size
311
-			if(is_int($groupPos2))
312
-				$groupSize2 = $groupPos1 - $groupPos2-1;
311
+			if (is_int($groupPos2))
312
+				$groupSize2 = $groupPos1 - $groupPos2 - 1;
313 313
 		}
314 314
 
315
-		if(is_int($decimalPos))
315
+		if (is_int($decimalPos))
316 316
 		{
317
-			for($i=strlen($pattern)-1; $i>=0; $i--)
317
+			for ($i = strlen($pattern) - 1; $i >= 0; $i--)
318 318
 			{
319
-				if($pattern{$i} == $dot) break;
320
-				if($pattern{$i} == $digit)
319
+				if ($pattern{$i} == $dot) break;
320
+				if ($pattern{$i} == $digit)
321 321
 				{
322 322
 					$decimalPoints = $i - $decimalPos;
323 323
 					break;
@@ -325,12 +325,12 @@  discard block
 block discarded – undo
325 325
 			}
326 326
 		}
327 327
 
328
-		if(is_int($decimalPos))
329
-			$digitPattern = substr($pattern,0,$decimalPos);
328
+		if (is_int($decimalPos))
329
+			$digitPattern = substr($pattern, 0, $decimalPos);
330 330
 		else
331
-			$digitPattern  = $pattern;
331
+			$digitPattern = $pattern;
332 332
 
333
-		$digitPattern  = preg_replace('/[^0]/','',$digitPattern);
333
+		$digitPattern = preg_replace('/[^0]/', '', $digitPattern);
334 334
 
335 335
 		$info['groupPos1'] = $groupPos1;
336 336
 		$info['groupSize1'] = $groupSize1;
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
 	{
352 352
 		$regexp = '/[#,\.0]+/';
353 353
 		$result = preg_split($regexp, $pattern);
354
-		return array($result[0],$result[1]);
354
+		return array($result[0], $result[1]);
355 355
 	}
356 356
 
357 357
 
@@ -503,9 +503,9 @@  discard block
 block discarded – undo
503 503
      * Gets the string to use as the currency symbol.
504 504
      * @return string currency symbol.
505 505
      */
506
-    function getCurrencySymbol($currency='USD')
506
+    function getCurrencySymbol($currency = 'USD')
507 507
     {
508
-    	if(isset($this->pattern['symbol']))
508
+    	if (isset($this->pattern['symbol']))
509 509
 			return $this->pattern['symbol'];
510 510
     	else
511 511
     		return $this->data['Currencies'][$currency][0];
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -184,15 +184,13 @@  discard block
 block discarded – undo
184 184
             $formatInfo = $culture->NumberFormat;
185 185
             $formatInfo->setPattern($type);
186 186
             return $formatInfo;
187
-   		}
188
-       	else if(is_string($culture))
187
+   		} else if(is_string($culture))
189 188
        	{
190 189
        		$cultureInfo = new CultureInfo($culture);
191 190
        		$formatInfo = $cultureInfo->NumberFormat;
192 191
        		$formatInfo->setPattern($type);
193 192
        		return $formatInfo;
194
-       	}
195
-       	else
193
+       	} else
196 194
        	{
197 195
             $cultureInfo = new CultureInfo();
198 196
        		$formatInfo = $cultureInfo->NumberFormat;
@@ -292,8 +290,7 @@  discard block
 block discarded – undo
292 290
 			{
293 291
 				$groupSize1 = $decimalPos - $groupPos1-1;
294 292
 
295
-			}
296
-			else
293
+			} else
297 294
 			{
298 295
 				//no decimal point, so traverse from the back
299 296
 				//to find the groupsize 1.
Please login to merge, or discard this patch.
framework/I18N/core/TCache_Lite.php 4 patches
Doc Comments   +2 added lines patch added patch discarded remove patch
@@ -485,6 +485,8 @@
 block discarded – undo
485 485
     /**
486 486
     *
487 487
     * @access private
488
+    * @param string $id
489
+    * @param string $data
488 490
     */
489 491
     function _memoryCacheAdd($id, $data)
490 492
     {
Please login to merge, or discard this patch.
Switch Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -611,15 +611,15 @@
 block discarded – undo
611 611
     function _hash($data, $controlType)
612 612
     {
613 613
         switch ($controlType) {
614
-        case 'md5':
615
-            return md5($data);
616
-        case 'crc32':
617
-            return sprintf('% 32d', crc32($data));
618
-        case 'strlen':
619
-            return sprintf('% 32d', strlen($data));
620
-        default:
621
-            $this->raiseError('Unknown controlType ! '.
622
-            '(available values are only \'md5\', \'crc32\', \'strlen\')', -5);
614
+        	case 'md5':
615
+            	return md5($data);
616
+        	case 'crc32':
617
+            	return sprintf('% 32d', crc32($data));
618
+        	case 'strlen':
619
+            	return sprintf('% 32d', strlen($data));
620
+        	default:
621
+            	$this->raiseError('Unknown controlType ! '.
622
+            	'(available values are only \'md5\', \'crc32\', \'strlen\')', -5);
623 623
         }
624 624
     }
625 625
 
Please login to merge, or discard this patch.
Indentation   +567 added lines, -567 removed lines patch added patch discarded remove patch
@@ -46,575 +46,575 @@
 block discarded – undo
46 46
 class TCache_Lite
47 47
 {
48 48
 
49
-    // --- Private properties ---
50
-
51
-    /**
52
-    * Directory where to put the cache files
53
-    * (make sure to add a trailing slash)
54
-    *
55
-    * @var string $_cacheDir
56
-    */
57
-    protected $_cacheDir = '/tmp/';
58
-
59
-    /**
60
-    * Enable / disable caching
61
-    *
62
-    * (can be very usefull for the debug of cached scripts)
63
-    *
64
-    * @var boolean $_caching
65
-    */
66
-    protected $_caching = true;
67
-
68
-    /**
69
-    * Cache lifetime (in seconds)
70
-    *
71
-    * @var int $_lifeTime
72
-    */
73
-    protected $_lifeTime = 3600;
74
-
75
-    /**
76
-    * Enable / disable fileLocking
77
-    *
78
-    * (can avoid cache corruption under bad circumstances)
79
-    *
80
-    * @var boolean $_fileLocking
81
-    */
82
-    protected $_fileLocking = true;
83
-
84
-    /**
85
-    * Timestamp of the last valid cache
86
-    *
87
-    * @var int $_refreshTime
88
-    */
89
-    protected $_refreshTime;
90
-
91
-    /**
92
-    * File name (with path)
93
-    *
94
-    * @var string $_file
95
-    */
96
-    protected $_file;
97
-
98
-    /**
99
-    * Enable / disable write control (the cache is read just after writing
100
-    * to detect corrupt entries)
101
-    *
102
-    * Enable write control will lightly slow the cache writing but not the
103
-    * cache reading. Write control can detect some corrupt cache files but
104
-    * maybe it's not a perfect control
105
-    *
106
-    * @var boolean $_writeControl
107
-    */
108
-    protected $_writeControl = true;
109
-
110
-    /**
111
-    * Enable / disable read control
112
-    *
113
-    * If enabled, a control key is embeded in cache file and this key is
114
-    * compared with the one calculated after the reading.
115
-    *
116
-    * @var boolean $_writeControl
117
-    */
118
-    protected $_readControl = true;
119
-
120
-    /**
121
-    * Type of read control (only if read control is enabled)
122
-    *
123
-    * Available values are :
124
-    * 'md5' for a md5 hash control (best but slowest)
125
-    * 'crc32' for a crc32 hash control (lightly less safe but faster,
126
-    * better choice)
127
-    * 'strlen' for a length only test (fastest)
128
-    *
129
-    * @var boolean $_readControlType
130
-    */
131
-    protected $_readControlType = 'crc32';
132
-
133
-    /**
134
-    * Current cache id
135
-    *
136
-    * @var string $_id
137
-    */
138
-    protected $_id;
139
-
140
-    /**
141
-    * Current cache group
142
-    *
143
-    * @var string $_group
144
-    */
145
-    protected $_group;
146
-
147
-    /**
148
-    * Enable / Disable "Memory Caching"
149
-    *
150
-    * NB : There is no lifetime for memory caching !
151
-    *
152
-    * @var boolean $_memoryCaching
153
-    */
154
-    protected $_memoryCaching = false;
155
-
156
-    /**
157
-    * Enable / Disable "Only Memory Caching"
158
-    * (be carefull, memory caching is "beta quality")
159
-    *
160
-    * @var boolean $_onlyMemoryCaching
161
-    */
162
-    protected $_onlyMemoryCaching = false;
163
-
164
-    /**
165
-    * Memory caching array
166
-    *
167
-    * @var array $_memoryCachingArray
168
-    */
169
-    protected $_memoryCachingArray = array();
170
-
171
-    /**
172
-    * Memory caching counter
173
-    *
174
-    * @var int $memoryCachingCounter
175
-    */
176
-    protected $_memoryCachingCounter = 0;
177
-
178
-    /**
179
-    * Memory caching limit
180
-    *
181
-    * @var int $memoryCachingLimit
182
-    */
183
-    protected $_memoryCachingLimit = 1000;
184
-
185
-    /**
186
-    * File Name protection
187
-    *
188
-    * if set to true, you can use any cache id or group name
189
-    * if set to false, it can be faster but cache ids and group names
190
-    * will be used directly in cache file names so be carefull with
191
-    * special characters...
192
-    *
193
-    * @var boolean $fileNameProtection
194
-    */
195
-    protected $_fileNameProtection = true;
196
-
197
-    /**
198
-    * Enable / disable automatic serialization
199
-    *
200
-    * it can be used to save directly datas which aren't strings
201
-    * (but it's slower)
202
-    *
203
-    * @var boolean $_serialize
204
-    */
205
-    protected $_automaticSerialization = false;
206
-
207
-    // --- Public methods ---
208
-
209
-    /**
210
-    * Constructor
211
-    *
212
-    * $options is an assoc. Available options are :
213
-    * $options = array(
214
-    * 'cacheDir' => directory where to put the cache files (string),
215
-    * 'caching' => enable / disable caching (boolean),
216
-    * 'lifeTime' => cache lifetime in seconds (int),
217
-    * 'fileLocking' => enable / disable fileLocking (boolean),
218
-    * 'writeControl' => enable / disable write control (boolean),
219
-    * 'readControl' => enable / disable read control (boolean),
220
-    * 'readControlType' => type of read control 'crc32', 'md5', 'strlen',
221
-    * 'memoryCaching' => enable / disable memory caching (boolean),
222
-    * 'onlyMemoryCaching' => enable / disable only memory caching (boolean),
223
-    * 'memoryCachingLimit' => max nbr of records in memory caching (int),
224
-    * 'fileNameProtection' => enable / disable file name protection (boolean),
225
-    * 'automaticSerialization' => enable / disable serialization (boolean)
226
-    * );
227
-    *
228
-    * @param array $options options
229
-    * @access public
230
-    */
231
-    function TCache_Lite($options = array(null))
232
-    {
233
-        $availableOptions = array(	'automaticSerialization',
234
-        							'fileNameProtection',
235
-        							'memoryCaching',
236
-        							'onlyMemoryCaching',
237
-        							'memoryCachingLimit',
238
-        							'cacheDir',
239
-        							'caching',
240
-        							'lifeTime',
241
-        							'fileLocking',
242
-        							'writeControl',
243
-        							'readControl',
244
-        							'readControlType');
245
-        foreach($options as $key => $value) {
246
-            if(in_array($key, $availableOptions)) {
247
-                $property = '_'.$key;
248
-                $this->$property = $value;
249
-            }
250
-        }
251
-        $this->_refreshTime = time() - $this->_lifeTime;
49
+	// --- Private properties ---
50
+
51
+	/**
52
+	 * Directory where to put the cache files
53
+	 * (make sure to add a trailing slash)
54
+	 *
55
+	 * @var string $_cacheDir
56
+	 */
57
+	protected $_cacheDir = '/tmp/';
58
+
59
+	/**
60
+	 * Enable / disable caching
61
+	 *
62
+	 * (can be very usefull for the debug of cached scripts)
63
+	 *
64
+	 * @var boolean $_caching
65
+	 */
66
+	protected $_caching = true;
67
+
68
+	/**
69
+	 * Cache lifetime (in seconds)
70
+	 *
71
+	 * @var int $_lifeTime
72
+	 */
73
+	protected $_lifeTime = 3600;
74
+
75
+	/**
76
+	 * Enable / disable fileLocking
77
+	 *
78
+	 * (can avoid cache corruption under bad circumstances)
79
+	 *
80
+	 * @var boolean $_fileLocking
81
+	 */
82
+	protected $_fileLocking = true;
83
+
84
+	/**
85
+	 * Timestamp of the last valid cache
86
+	 *
87
+	 * @var int $_refreshTime
88
+	 */
89
+	protected $_refreshTime;
90
+
91
+	/**
92
+	 * File name (with path)
93
+	 *
94
+	 * @var string $_file
95
+	 */
96
+	protected $_file;
97
+
98
+	/**
99
+	 * Enable / disable write control (the cache is read just after writing
100
+	 * to detect corrupt entries)
101
+	 *
102
+	 * Enable write control will lightly slow the cache writing but not the
103
+	 * cache reading. Write control can detect some corrupt cache files but
104
+	 * maybe it's not a perfect control
105
+	 *
106
+	 * @var boolean $_writeControl
107
+	 */
108
+	protected $_writeControl = true;
109
+
110
+	/**
111
+	 * Enable / disable read control
112
+	 *
113
+	 * If enabled, a control key is embeded in cache file and this key is
114
+	 * compared with the one calculated after the reading.
115
+	 *
116
+	 * @var boolean $_writeControl
117
+	 */
118
+	protected $_readControl = true;
119
+
120
+	/**
121
+	 * Type of read control (only if read control is enabled)
122
+	 *
123
+	 * Available values are :
124
+	 * 'md5' for a md5 hash control (best but slowest)
125
+	 * 'crc32' for a crc32 hash control (lightly less safe but faster,
126
+	 * better choice)
127
+	 * 'strlen' for a length only test (fastest)
128
+	 *
129
+	 * @var boolean $_readControlType
130
+	 */
131
+	protected $_readControlType = 'crc32';
132
+
133
+	/**
134
+	 * Current cache id
135
+	 *
136
+	 * @var string $_id
137
+	 */
138
+	protected $_id;
139
+
140
+	/**
141
+	 * Current cache group
142
+	 *
143
+	 * @var string $_group
144
+	 */
145
+	protected $_group;
146
+
147
+	/**
148
+	 * Enable / Disable "Memory Caching"
149
+	 *
150
+	 * NB : There is no lifetime for memory caching !
151
+	 *
152
+	 * @var boolean $_memoryCaching
153
+	 */
154
+	protected $_memoryCaching = false;
155
+
156
+	/**
157
+	 * Enable / Disable "Only Memory Caching"
158
+	 * (be carefull, memory caching is "beta quality")
159
+	 *
160
+	 * @var boolean $_onlyMemoryCaching
161
+	 */
162
+	protected $_onlyMemoryCaching = false;
163
+
164
+	/**
165
+	 * Memory caching array
166
+	 *
167
+	 * @var array $_memoryCachingArray
168
+	 */
169
+	protected $_memoryCachingArray = array();
170
+
171
+	/**
172
+	 * Memory caching counter
173
+	 *
174
+	 * @var int $memoryCachingCounter
175
+	 */
176
+	protected $_memoryCachingCounter = 0;
177
+
178
+	/**
179
+	 * Memory caching limit
180
+	 *
181
+	 * @var int $memoryCachingLimit
182
+	 */
183
+	protected $_memoryCachingLimit = 1000;
184
+
185
+	/**
186
+	 * File Name protection
187
+	 *
188
+	 * if set to true, you can use any cache id or group name
189
+	 * if set to false, it can be faster but cache ids and group names
190
+	 * will be used directly in cache file names so be carefull with
191
+	 * special characters...
192
+	 *
193
+	 * @var boolean $fileNameProtection
194
+	 */
195
+	protected $_fileNameProtection = true;
196
+
197
+	/**
198
+	 * Enable / disable automatic serialization
199
+	 *
200
+	 * it can be used to save directly datas which aren't strings
201
+	 * (but it's slower)
202
+	 *
203
+	 * @var boolean $_serialize
204
+	 */
205
+	protected $_automaticSerialization = false;
206
+
207
+	// --- Public methods ---
208
+
209
+	/**
210
+	 * Constructor
211
+	 *
212
+	 * $options is an assoc. Available options are :
213
+	 * $options = array(
214
+	 * 'cacheDir' => directory where to put the cache files (string),
215
+	 * 'caching' => enable / disable caching (boolean),
216
+	 * 'lifeTime' => cache lifetime in seconds (int),
217
+	 * 'fileLocking' => enable / disable fileLocking (boolean),
218
+	 * 'writeControl' => enable / disable write control (boolean),
219
+	 * 'readControl' => enable / disable read control (boolean),
220
+	 * 'readControlType' => type of read control 'crc32', 'md5', 'strlen',
221
+	 * 'memoryCaching' => enable / disable memory caching (boolean),
222
+	 * 'onlyMemoryCaching' => enable / disable only memory caching (boolean),
223
+	 * 'memoryCachingLimit' => max nbr of records in memory caching (int),
224
+	 * 'fileNameProtection' => enable / disable file name protection (boolean),
225
+	 * 'automaticSerialization' => enable / disable serialization (boolean)
226
+	 * );
227
+	 *
228
+	 * @param array $options options
229
+	 * @access public
230
+	 */
231
+	function TCache_Lite($options = array(null))
232
+	{
233
+		$availableOptions = array(	'automaticSerialization',
234
+									'fileNameProtection',
235
+									'memoryCaching',
236
+									'onlyMemoryCaching',
237
+									'memoryCachingLimit',
238
+									'cacheDir',
239
+									'caching',
240
+									'lifeTime',
241
+									'fileLocking',
242
+									'writeControl',
243
+									'readControl',
244
+									'readControlType');
245
+		foreach($options as $key => $value) {
246
+			if(in_array($key, $availableOptions)) {
247
+				$property = '_'.$key;
248
+				$this->$property = $value;
249
+			}
250
+		}
251
+		$this->_refreshTime = time() - $this->_lifeTime;
252 252
 	}
253 253
 
254
-    /**
255
-    * Test if a cache is available and (if yes) return it
256
-    *
257
-    * @param string $id cache id
258
-    * @param string $group name of the cache group
259
-    * @param boolean $doNotTestCacheValidity if set to true, the cache
260
-    * validity won't be tested
261
-    * @return string data of the cache (or false if no cache available)
262
-    * @access public
263
-    */
264
-    function get($id, $group = 'default', $doNotTestCacheValidity = false)
265
-    {
266
-        $this->_id = $id;
267
-        $this->_group = $group;
268
-        $data = false;
269
-        if ($this->_caching) {
270
-            $this->_setFileName($id, $group);
271
-            if ($this->_memoryCaching) {
272
-                if (isset($this->_memoryCachingArray[$this->_file])) {
273
-                    if ($this->_automaticSerialization) {
274
-                        return unserialize(
275
-                        			$this->_memoryCachingArray[$this->_file]);
276
-                    } else {
277
-                        return $this->_memoryCachingArray[$this->_file];
278
-                    }
279
-                } else {
280
-                    if ($this->_onlyMemoryCaching) {
281
-                        return false;
282
-                    }
283
-                }
284
-            }
285
-            if ($doNotTestCacheValidity) {
286
-                if (file_exists($this->_file)) {
287
-                    $data = $this->_read();
288
-                }
289
-            } else {
290
-                if (@filemtime($this->_file) > $this->_refreshTime) {
291
-                    $data = $this->_read();
292
-                }
293
-            }
294
-            if (($data) and ($this->_memoryCaching)) {
295
-                $this->_memoryCacheAdd($this->_file, $data);
296
-            }
297
-            if ($this->_automaticSerialization && is_string($data)) {
298
-                $data = unserialize($data);
299
-            }
300
-            return $data;
301
-        }
302
-        return false;
303
-    }
304
-
305
-    /**
306
-    * Save some data in a cache file
307
-    *
308
-    * @param string $data data to put in cache (can be another type than strings
309
-    * if automaticSerialization is on)
310
-    * @param string $id cache id
311
-    * @param string $group name of the cache group
312
-    * @return boolean true if no problem
313
-    * @access public
314
-    */
315
-    function save($data, $id = null, $group = 'default')
316
-    {
317
-        if ($this->_caching) {
318
-            if ($this->_automaticSerialization) {
319
-                $data = serialize($data);
320
-            }
321
-            if (isset($id)) {
322
-                $this->_setFileName($id, $group);
323
-            }
324
-            if ($this->_memoryCaching) {
325
-                $this->_memoryCacheAdd($this->_file, $data);
326
-                if ($this->_onlyMemoryCaching) {
327
-                    return true;
328
-                }
329
-            }
330
-            if ($this->_writeControl) {
331
-                if (!$this->_writeAndControl($data)) {
332
-                    @touch($this->_file, time() - 2*abs($this->_lifeTime));
333
-                    return false;
334
-                } else {
335
-                    return true;
336
-                }
337
-            } else {
338
-                return $this->_write($data);
339
-            }
340
-        }
341
-        return false;
342
-    }
343
-
344
-    /**
345
-    * Remove a cache file
346
-    *
347
-    * @param string $id cache id
348
-    * @param string $group name of the cache group
349
-    * @return boolean true if no problem
350
-    * @access public
351
-    */
352
-    function remove($id, $group = 'default')
353
-    {
354
-        $this->_setFileName($id, $group);
355
-        if (!@unlink($this->_file)) {
356
-            $this->raiseError('TCache_Lite : Unable to remove cache !', -3);
357
-            return false;
358
-        }
359
-        return true;
360
-    }
361
-
362
-    /**
363
-    * Clean the cache
364
-    *
365
-    * if no group is specified all cache files will be destroyed
366
-    * else only cache files of the specified group will be destroyed
367
-    *
368
-    * @param string $group name of the cache group
369
-    * @return boolean true if no problem
370
-    * @access public
371
-    */
372
-    function clean($group = false)
373
-    {
374
-        if ($this->_fileNameProtection) {
375
-            $motif = ($group) ? 'cache_'.md5($group).'_' : 'cache_';
376
-        } else {
377
-            $motif = ($group) ? 'cache_'.$group.'_' : 'cache_';
378
-        }
379
-        if ($this->_memoryCaching) {
380
-            while (list($key, $value) = each($this->_memoryCaching)) {
381
-                if (strpos($key, $motif, 0)) {
382
-                    unset($this->_memoryCaching[$key]);
383
-                    $this->_memoryCachingCounter =
384
-                    		$this->_memoryCachingCounter - 1;
385
-                }
386
-            }
387
-            if ($this->_onlyMemoryCaching) {
388
-                return true;
389
-            }
390
-        }
391
-        if (!($dh = opendir($this->_cacheDir))) {
392
-            $this->raiseError('TCache_Lite : Unable to open cache directory !');
393
-            return false;
394
-        }
395
-        while ($file = readdir($dh)) {
396
-            if (($file != '.') && ($file != '..')) {
397
-                $file = $this->_cacheDir . $file;
398
-                if (is_file($file)) {
399
-                    if (strpos($file, $motif, 0)) {
400
-                        if (!@unlink($file)) {
401
-             $this->raiseError('Cache_Lite : Unable to remove cache !', -3);
402
-                            return false;
403
-                        }
404
-                    }
405
-                }
406
-            }
407
-        }
408
-        return true;
409
-    }
410
-
411
-	    /**
412
-    * Set a new life time
413
-    *
414
-    * @param int $newLifeTime new life time (in seconds)
415
-    * @access public
416
-    */
417
-    function setLifeTime($newLifeTime)
418
-    {
419
-        $this->_lifeTime = $newLifeTime;
420
-        $this->_refreshTime = time() - $newLifeTime;
421
-    }
422
-
423
-    /**
424
-    *
425
-    * @access public
426
-    */
427
-    function saveMemoryCachingState($id, $group = 'default')
428
-    {
429
-        if ($this->_caching) {
430
-            $array = array(
431
-                'counter' => $this->_memoryCachingCounter,
432
-                'array' => $this->_memoryCachingState
433
-            );
434
-            $data = serialize($array);
435
-            $this->save($data, $id, $group);
436
-        }
437
-    }
438
-
439
-    /**
440
-    *
441
-    * @access public
442
-    */
443
-    function getMemoryCachingState($id, $group = 'default',
444
-    								$doNotTestCacheValidity = false)
445
-    {
446
-        if ($this->_caching) {
447
-            if ($data = $this->get($id, $group, $doNotTestCacheValidity))
448
-            {
449
-                $array = unserialize($data);
450
-                $this->_memoryCachingCounter = $array['counter'];
451
-                $this->_memoryCachingArray = $array['array'];
452
-            }
453
-        }
454
-    }
455
-
456
-    /**
457
-    * Return the cache last modification time
458
-    *
459
-    * BE CAREFUL : THIS METHOD IS FOR HACKING ONLY !
460
-    *
461
-    * @return int last modification time
462
-    */
463
-    function lastModified() {
464
-        return filemtime($this->cache->_file);
465
-    }
466
-
467
-    /**
468
-    * Trigger a PEAR error
469
-    *
470
-    * To improve performances, the PEAR.php file is included dynamically.
471
-    * The file is so included only when an error is triggered. So, in most
472
-    * cases, the file isn't included and perfs are much better.
473
-    *
474
-    * @param string $msg error message
475
-    * @param int $code error code
476
-    * @access public
477
-    */
478
-    function raiseError($msg, $code)
479
-    {
480
-       throw new Exception($msg);
481
-    }
482
-
483
-    // --- Private methods ---
484
-
485
-    /**
486
-    *
487
-    * @access private
488
-    */
489
-    function _memoryCacheAdd($id, $data)
490
-    {
491
-        $this->_memoryCachingArray[$this->_file] = $data;
492
-        if ($this->_memoryCachingCounter >= $this->_memoryCachingLimit) {
493
-            list($key, $value) = each($this->_memoryCachingArray);
494
-            unset($this->_memoryCachingArray[$key]);
495
-        } else {
496
-            $this->_memoryCachingCounter = $this->_memoryCachingCounter + 1;
497
-        }
498
-    }
499
-
500
-    /**
501
-    * Make a file name (with path)
502
-    *
503
-    * @param string $id cache id
504
-    * @param string $group name of the group
505
-    * @access private
506
-    */
507
-    function _setFileName($id, $group)
508
-    {
509
-        if ($this->_fileNameProtection) {
510
-            $this->_file = ($this->_cacheDir.'cache_'.md5($group).'_'
511
-            						.md5($id));
512
-        } else {
513
-            $this->_file = $this->_cacheDir.'cache_'.$group.'_'.$id;
514
-        }
515
-    }
516
-
517
-    function getCacheFile()
518
-    {
519
-    	return $this->_file;
520
-    }
521
-
522
-    /**
523
-    * Read the cache file and return the content
524
-    *
525
-    * @return string content of the cache file
526
-    * @access private
527
-    */
528
-    function _read()
529
-    {
530
-        $fp = @fopen($this->_file, "rb");
531
-        if ($this->_fileLocking) @flock($fp, LOCK_SH);
532
-        if ($fp) {
533
-        	// because the filesize can be cached by PHP itself...
534
-            clearstatcache();
535
-            $length = @filesize($this->_file);
536
-            if ($this->_readControl) {
537
-                $hashControl = @fread($fp, 32);
538
-                $length = $length - 32;
539
-            }
540
-            $data = @fread($fp, $length);
541
-            if ($this->_fileLocking) @flock($fp, LOCK_UN);
542
-            @fclose($fp);
543
-            if ($this->_readControl) {
544
-                $hashData = $this->_hash($data, $this->_readControlType);
545
-                if ($hashData != $hashControl) {
546
-                    @touch($this->_file, time() - 2*abs($this->_lifeTime));
547
-                    return false;
548
-                }
549
-            }
550
-            return $data;
551
-        }
552
-        $this->raiseError('Cache_Lite : Unable to read cache !', -2);
553
-        return false;
554
-    }
555
-
556
-    /**
557
-    * Write the given data in the cache file
558
-    *
559
-    * @param string $data data to put in cache
560
-    * @return boolean true if ok
561
-    * @access private
562
-    */
563
-    function _write($data)
564
-    {
565
-        $fp = @fopen($this->_file, "wb");
566
-        if ($fp) {
567
-            if ($this->_fileLocking) @flock($fp, LOCK_EX);
568
-            if ($this->_readControl) {
569
-                @fwrite($fp, $this->_hash($data, $this->_readControlType), 32);
570
-            }
571
-            $len = strlen($data);
572
-            @fwrite($fp, $data, $len);
573
-            if ($this->_fileLocking) @flock($fp, LOCK_UN);
574
-            @fclose($fp);
575
-            return true;
576
-        }
577
-        $this->raiseError('Cache_Lite : Unable to write cache !', -1);
578
-        return false;
579
-    }
580
-
581
-    /**
582
-    * Write the given data in the cache file and control it just after to avoid
583
-    * corrupted cache entries
584
-    *
585
-    * @param string $data data to put in cache
586
-    * @return boolean true if the test is ok
587
-    * @access private
588
-    */
589
-    function _writeAndControl($data)
590
-    {
591
-        $this->_write($data);
592
-        $dataRead = $this->_read($data);
593
-        return ($dataRead==$data);
594
-    }
595
-
596
-    /**
597
-    * Make a control key with the string containing datas
598
-    *
599
-    * @param string $data data
600
-    * @param string $controlType type of control 'md5', 'crc32' or 'strlen'
601
-    * @return string control key
602
-    * @access private
603
-    */
604
-    function _hash($data, $controlType)
605
-    {
606
-        switch ($controlType) {
607
-        case 'md5':
608
-            return md5($data);
609
-        case 'crc32':
610
-            return sprintf('% 32d', crc32($data));
611
-        case 'strlen':
612
-            return sprintf('% 32d', strlen($data));
613
-        default:
614
-            $this->raiseError('Unknown controlType ! '.
615
-            '(available values are only \'md5\', \'crc32\', \'strlen\')', -5);
616
-        }
617
-    }
254
+	/**
255
+	 * Test if a cache is available and (if yes) return it
256
+	 *
257
+	 * @param string $id cache id
258
+	 * @param string $group name of the cache group
259
+	 * @param boolean $doNotTestCacheValidity if set to true, the cache
260
+	 * validity won't be tested
261
+	 * @return string data of the cache (or false if no cache available)
262
+	 * @access public
263
+	 */
264
+	function get($id, $group = 'default', $doNotTestCacheValidity = false)
265
+	{
266
+		$this->_id = $id;
267
+		$this->_group = $group;
268
+		$data = false;
269
+		if ($this->_caching) {
270
+			$this->_setFileName($id, $group);
271
+			if ($this->_memoryCaching) {
272
+				if (isset($this->_memoryCachingArray[$this->_file])) {
273
+					if ($this->_automaticSerialization) {
274
+						return unserialize(
275
+									$this->_memoryCachingArray[$this->_file]);
276
+					} else {
277
+						return $this->_memoryCachingArray[$this->_file];
278
+					}
279
+				} else {
280
+					if ($this->_onlyMemoryCaching) {
281
+						return false;
282
+					}
283
+				}
284
+			}
285
+			if ($doNotTestCacheValidity) {
286
+				if (file_exists($this->_file)) {
287
+					$data = $this->_read();
288
+				}
289
+			} else {
290
+				if (@filemtime($this->_file) > $this->_refreshTime) {
291
+					$data = $this->_read();
292
+				}
293
+			}
294
+			if (($data) and ($this->_memoryCaching)) {
295
+				$this->_memoryCacheAdd($this->_file, $data);
296
+			}
297
+			if ($this->_automaticSerialization && is_string($data)) {
298
+				$data = unserialize($data);
299
+			}
300
+			return $data;
301
+		}
302
+		return false;
303
+	}
304
+
305
+	/**
306
+	 * Save some data in a cache file
307
+	 *
308
+	 * @param string $data data to put in cache (can be another type than strings
309
+	 * if automaticSerialization is on)
310
+	 * @param string $id cache id
311
+	 * @param string $group name of the cache group
312
+	 * @return boolean true if no problem
313
+	 * @access public
314
+	 */
315
+	function save($data, $id = null, $group = 'default')
316
+	{
317
+		if ($this->_caching) {
318
+			if ($this->_automaticSerialization) {
319
+				$data = serialize($data);
320
+			}
321
+			if (isset($id)) {
322
+				$this->_setFileName($id, $group);
323
+			}
324
+			if ($this->_memoryCaching) {
325
+				$this->_memoryCacheAdd($this->_file, $data);
326
+				if ($this->_onlyMemoryCaching) {
327
+					return true;
328
+				}
329
+			}
330
+			if ($this->_writeControl) {
331
+				if (!$this->_writeAndControl($data)) {
332
+					@touch($this->_file, time() - 2*abs($this->_lifeTime));
333
+					return false;
334
+				} else {
335
+					return true;
336
+				}
337
+			} else {
338
+				return $this->_write($data);
339
+			}
340
+		}
341
+		return false;
342
+	}
343
+
344
+	/**
345
+	 * Remove a cache file
346
+	 *
347
+	 * @param string $id cache id
348
+	 * @param string $group name of the cache group
349
+	 * @return boolean true if no problem
350
+	 * @access public
351
+	 */
352
+	function remove($id, $group = 'default')
353
+	{
354
+		$this->_setFileName($id, $group);
355
+		if (!@unlink($this->_file)) {
356
+			$this->raiseError('TCache_Lite : Unable to remove cache !', -3);
357
+			return false;
358
+		}
359
+		return true;
360
+	}
361
+
362
+	/**
363
+	 * Clean the cache
364
+	 *
365
+	 * if no group is specified all cache files will be destroyed
366
+	 * else only cache files of the specified group will be destroyed
367
+	 *
368
+	 * @param string $group name of the cache group
369
+	 * @return boolean true if no problem
370
+	 * @access public
371
+	 */
372
+	function clean($group = false)
373
+	{
374
+		if ($this->_fileNameProtection) {
375
+			$motif = ($group) ? 'cache_'.md5($group).'_' : 'cache_';
376
+		} else {
377
+			$motif = ($group) ? 'cache_'.$group.'_' : 'cache_';
378
+		}
379
+		if ($this->_memoryCaching) {
380
+			while (list($key, $value) = each($this->_memoryCaching)) {
381
+				if (strpos($key, $motif, 0)) {
382
+					unset($this->_memoryCaching[$key]);
383
+					$this->_memoryCachingCounter =
384
+							$this->_memoryCachingCounter - 1;
385
+				}
386
+			}
387
+			if ($this->_onlyMemoryCaching) {
388
+				return true;
389
+			}
390
+		}
391
+		if (!($dh = opendir($this->_cacheDir))) {
392
+			$this->raiseError('TCache_Lite : Unable to open cache directory !');
393
+			return false;
394
+		}
395
+		while ($file = readdir($dh)) {
396
+			if (($file != '.') && ($file != '..')) {
397
+				$file = $this->_cacheDir . $file;
398
+				if (is_file($file)) {
399
+					if (strpos($file, $motif, 0)) {
400
+						if (!@unlink($file)) {
401
+			 $this->raiseError('Cache_Lite : Unable to remove cache !', -3);
402
+							return false;
403
+						}
404
+					}
405
+				}
406
+			}
407
+		}
408
+		return true;
409
+	}
410
+
411
+		/**
412
+		 * Set a new life time
413
+		 *
414
+		 * @param int $newLifeTime new life time (in seconds)
415
+		 * @access public
416
+		 */
417
+	function setLifeTime($newLifeTime)
418
+	{
419
+		$this->_lifeTime = $newLifeTime;
420
+		$this->_refreshTime = time() - $newLifeTime;
421
+	}
422
+
423
+	/**
424
+	 *
425
+	 * @access public
426
+	 */
427
+	function saveMemoryCachingState($id, $group = 'default')
428
+	{
429
+		if ($this->_caching) {
430
+			$array = array(
431
+				'counter' => $this->_memoryCachingCounter,
432
+				'array' => $this->_memoryCachingState
433
+			);
434
+			$data = serialize($array);
435
+			$this->save($data, $id, $group);
436
+		}
437
+	}
438
+
439
+	/**
440
+	 *
441
+	 * @access public
442
+	 */
443
+	function getMemoryCachingState($id, $group = 'default',
444
+									$doNotTestCacheValidity = false)
445
+	{
446
+		if ($this->_caching) {
447
+			if ($data = $this->get($id, $group, $doNotTestCacheValidity))
448
+			{
449
+				$array = unserialize($data);
450
+				$this->_memoryCachingCounter = $array['counter'];
451
+				$this->_memoryCachingArray = $array['array'];
452
+			}
453
+		}
454
+	}
455
+
456
+	/**
457
+	 * Return the cache last modification time
458
+	 *
459
+	 * BE CAREFUL : THIS METHOD IS FOR HACKING ONLY !
460
+	 *
461
+	 * @return int last modification time
462
+	 */
463
+	function lastModified() {
464
+		return filemtime($this->cache->_file);
465
+	}
466
+
467
+	/**
468
+	 * Trigger a PEAR error
469
+	 *
470
+	 * To improve performances, the PEAR.php file is included dynamically.
471
+	 * The file is so included only when an error is triggered. So, in most
472
+	 * cases, the file isn't included and perfs are much better.
473
+	 *
474
+	 * @param string $msg error message
475
+	 * @param int $code error code
476
+	 * @access public
477
+	 */
478
+	function raiseError($msg, $code)
479
+	{
480
+	   throw new Exception($msg);
481
+	}
482
+
483
+	// --- Private methods ---
484
+
485
+	/**
486
+	 *
487
+	 * @access private
488
+	 */
489
+	function _memoryCacheAdd($id, $data)
490
+	{
491
+		$this->_memoryCachingArray[$this->_file] = $data;
492
+		if ($this->_memoryCachingCounter >= $this->_memoryCachingLimit) {
493
+			list($key, $value) = each($this->_memoryCachingArray);
494
+			unset($this->_memoryCachingArray[$key]);
495
+		} else {
496
+			$this->_memoryCachingCounter = $this->_memoryCachingCounter + 1;
497
+		}
498
+	}
499
+
500
+	/**
501
+	 * Make a file name (with path)
502
+	 *
503
+	 * @param string $id cache id
504
+	 * @param string $group name of the group
505
+	 * @access private
506
+	 */
507
+	function _setFileName($id, $group)
508
+	{
509
+		if ($this->_fileNameProtection) {
510
+			$this->_file = ($this->_cacheDir.'cache_'.md5($group).'_'
511
+									.md5($id));
512
+		} else {
513
+			$this->_file = $this->_cacheDir.'cache_'.$group.'_'.$id;
514
+		}
515
+	}
516
+
517
+	function getCacheFile()
518
+	{
519
+		return $this->_file;
520
+	}
521
+
522
+	/**
523
+	 * Read the cache file and return the content
524
+	 *
525
+	 * @return string content of the cache file
526
+	 * @access private
527
+	 */
528
+	function _read()
529
+	{
530
+		$fp = @fopen($this->_file, "rb");
531
+		if ($this->_fileLocking) @flock($fp, LOCK_SH);
532
+		if ($fp) {
533
+			// because the filesize can be cached by PHP itself...
534
+			clearstatcache();
535
+			$length = @filesize($this->_file);
536
+			if ($this->_readControl) {
537
+				$hashControl = @fread($fp, 32);
538
+				$length = $length - 32;
539
+			}
540
+			$data = @fread($fp, $length);
541
+			if ($this->_fileLocking) @flock($fp, LOCK_UN);
542
+			@fclose($fp);
543
+			if ($this->_readControl) {
544
+				$hashData = $this->_hash($data, $this->_readControlType);
545
+				if ($hashData != $hashControl) {
546
+					@touch($this->_file, time() - 2*abs($this->_lifeTime));
547
+					return false;
548
+				}
549
+			}
550
+			return $data;
551
+		}
552
+		$this->raiseError('Cache_Lite : Unable to read cache !', -2);
553
+		return false;
554
+	}
555
+
556
+	/**
557
+	 * Write the given data in the cache file
558
+	 *
559
+	 * @param string $data data to put in cache
560
+	 * @return boolean true if ok
561
+	 * @access private
562
+	 */
563
+	function _write($data)
564
+	{
565
+		$fp = @fopen($this->_file, "wb");
566
+		if ($fp) {
567
+			if ($this->_fileLocking) @flock($fp, LOCK_EX);
568
+			if ($this->_readControl) {
569
+				@fwrite($fp, $this->_hash($data, $this->_readControlType), 32);
570
+			}
571
+			$len = strlen($data);
572
+			@fwrite($fp, $data, $len);
573
+			if ($this->_fileLocking) @flock($fp, LOCK_UN);
574
+			@fclose($fp);
575
+			return true;
576
+		}
577
+		$this->raiseError('Cache_Lite : Unable to write cache !', -1);
578
+		return false;
579
+	}
580
+
581
+	/**
582
+	 * Write the given data in the cache file and control it just after to avoid
583
+	 * corrupted cache entries
584
+	 *
585
+	 * @param string $data data to put in cache
586
+	 * @return boolean true if the test is ok
587
+	 * @access private
588
+	 */
589
+	function _writeAndControl($data)
590
+	{
591
+		$this->_write($data);
592
+		$dataRead = $this->_read($data);
593
+		return ($dataRead==$data);
594
+	}
595
+
596
+	/**
597
+	 * Make a control key with the string containing datas
598
+	 *
599
+	 * @param string $data data
600
+	 * @param string $controlType type of control 'md5', 'crc32' or 'strlen'
601
+	 * @return string control key
602
+	 * @access private
603
+	 */
604
+	function _hash($data, $controlType)
605
+	{
606
+		switch ($controlType) {
607
+		case 'md5':
608
+			return md5($data);
609
+		case 'crc32':
610
+			return sprintf('% 32d', crc32($data));
611
+		case 'strlen':
612
+			return sprintf('% 32d', strlen($data));
613
+		default:
614
+			$this->raiseError('Unknown controlType ! '.
615
+			'(available values are only \'md5\', \'crc32\', \'strlen\')', -5);
616
+		}
617
+	}
618 618
 
619 619
 }
620 620
 
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
     */
231 231
     function TCache_Lite($options = array(null))
232 232
     {
233
-        $availableOptions = array(	'automaticSerialization',
233
+        $availableOptions = array('automaticSerialization',
234 234
         							'fileNameProtection',
235 235
         							'memoryCaching',
236 236
         							'onlyMemoryCaching',
@@ -242,9 +242,9 @@  discard block
 block discarded – undo
242 242
         							'writeControl',
243 243
         							'readControl',
244 244
         							'readControlType');
245
-        foreach($options as $key => $value) {
246
-            if(in_array($key, $availableOptions)) {
247
-                $property = '_'.$key;
245
+        foreach ($options as $key => $value) {
246
+            if (in_array($key, $availableOptions)) {
247
+                $property = '_' . $key;
248 248
                 $this->$property = $value;
249 249
             }
250 250
         }
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
             }
330 330
             if ($this->_writeControl) {
331 331
                 if (!$this->_writeAndControl($data)) {
332
-                    @touch($this->_file, time() - 2*abs($this->_lifeTime));
332
+                    @touch($this->_file, time() - 2 * abs($this->_lifeTime));
333 333
                     return false;
334 334
                 } else {
335 335
                     return true;
@@ -372,9 +372,9 @@  discard block
 block discarded – undo
372 372
     function clean($group = false)
373 373
     {
374 374
         if ($this->_fileNameProtection) {
375
-            $motif = ($group) ? 'cache_'.md5($group).'_' : 'cache_';
375
+            $motif = ($group) ? 'cache_' . md5($group) . '_' : 'cache_';
376 376
         } else {
377
-            $motif = ($group) ? 'cache_'.$group.'_' : 'cache_';
377
+            $motif = ($group) ? 'cache_' . $group . '_' : 'cache_';
378 378
         }
379 379
         if ($this->_memoryCaching) {
380 380
             while (list($key, $value) = each($this->_memoryCaching)) {
@@ -507,10 +507,10 @@  discard block
 block discarded – undo
507 507
     function _setFileName($id, $group)
508 508
     {
509 509
         if ($this->_fileNameProtection) {
510
-            $this->_file = ($this->_cacheDir.'cache_'.md5($group).'_'
510
+            $this->_file = ($this->_cacheDir . 'cache_' . md5($group) . '_'
511 511
             						.md5($id));
512 512
         } else {
513
-            $this->_file = $this->_cacheDir.'cache_'.$group.'_'.$id;
513
+            $this->_file = $this->_cacheDir . 'cache_' . $group . '_' . $id;
514 514
         }
515 515
     }
516 516
 
@@ -543,7 +543,7 @@  discard block
 block discarded – undo
543 543
             if ($this->_readControl) {
544 544
                 $hashData = $this->_hash($data, $this->_readControlType);
545 545
                 if ($hashData != $hashControl) {
546
-                    @touch($this->_file, time() - 2*abs($this->_lifeTime));
546
+                    @touch($this->_file, time() - 2 * abs($this->_lifeTime));
547 547
                     return false;
548 548
                 }
549 549
             }
@@ -590,7 +590,7 @@  discard block
 block discarded – undo
590 590
     {
591 591
         $this->_write($data);
592 592
         $dataRead = $this->_read($data);
593
-        return ($dataRead==$data);
593
+        return ($dataRead == $data);
594 594
     }
595 595
 
596 596
     /**
@@ -611,7 +611,7 @@  discard block
 block discarded – undo
611 611
         case 'strlen':
612 612
             return sprintf('% 32d', strlen($data));
613 613
         default:
614
-            $this->raiseError('Unknown controlType ! '.
614
+            $this->raiseError('Unknown controlType ! ' .
615 615
             '(available values are only \'md5\', \'crc32\', \'strlen\')', -5);
616 616
         }
617 617
     }
Please login to merge, or discard this patch.
framework/I18N/core/util.php 3 patches
Doc Comments   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,6 +29,7 @@  discard block
 block discarded – undo
29 29
 	 * send a note to [email protected] so we can mail you a copy immediately.
30 30
 	 *
31 31
 	 * @param string DSN format, similar to PEAR's DB
32
+	 * @param string $dsn
32 33
 	 * @return array DSN information. 
33 34
 	 * @author     Stig Bakken <[email protected]>
34 35
 	 * @author     Tomas V.V.Cox <[email protected]>
@@ -172,7 +173,7 @@  discard block
 block discarded – undo
172 173
 	/** 
173 174
 	 * Convert UTF-8 strings to a different encoding. NB. The result
174 175
 	 * may not have been encoded if iconv fails.
175
-	 * @param string the UTF-8 string for conversion
176
+	 * @param string string UTF-8 string for conversion
176 177
 	 * @return string encoded string.
177 178
 	 */
178 179
 	function I18N_toEncoding($string, $to)
Please login to merge, or discard this patch.
Indentation   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 	/**
22 22
 	 * For a given DSN (database connection string), return some information
23 23
 	 * about the DSN. This function comes from PEAR's DB package.
24
-  	 *
24
+	 *
25 25
 	 * LICENSE: This source file is subject to version 3.0 of the PHP license
26 26
 	 * that is available through the world-wide-web at the following URI:
27 27
 	 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
@@ -37,120 +37,120 @@  discard block
 block discarded – undo
37 37
 	 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
38 38
 	 * @link       http://pear.php.net/package/DB
39 39
 	 */
40
-    function parseDSN($dsn)
41
-    {
42
-        if (is_array($dsn)) {
43
-            return $dsn;
44
-        }
40
+	function parseDSN($dsn)
41
+	{
42
+		if (is_array($dsn)) {
43
+			return $dsn;
44
+		}
45 45
 
46
-        $parsed = array(
47
-            'phptype'  => false,
48
-            'dbsyntax' => false,
49
-            'username' => false,
50
-            'password' => false,
51
-            'protocol' => false,
52
-            'hostspec' => false,
53
-            'port'     => false,
54
-            'socket'   => false,
55
-            'database' => false
56
-        );
46
+		$parsed = array(
47
+			'phptype'  => false,
48
+			'dbsyntax' => false,
49
+			'username' => false,
50
+			'password' => false,
51
+			'protocol' => false,
52
+			'hostspec' => false,
53
+			'port'     => false,
54
+			'socket'   => false,
55
+			'database' => false
56
+		);
57 57
 
58
-        // Find phptype and dbsyntax
59
-        if (($pos = strpos($dsn, '://')) !== false) {
60
-            $str = substr($dsn, 0, $pos);
61
-            $dsn = substr($dsn, $pos + 3);
62
-        } else {
63
-            $str = $dsn;
64
-            $dsn = null;
65
-        }
58
+		// Find phptype and dbsyntax
59
+		if (($pos = strpos($dsn, '://')) !== false) {
60
+			$str = substr($dsn, 0, $pos);
61
+			$dsn = substr($dsn, $pos + 3);
62
+		} else {
63
+			$str = $dsn;
64
+			$dsn = null;
65
+		}
66 66
 
67
-        // Get phptype and dbsyntax
68
-        // $str => phptype(dbsyntax)
69
-        if (preg_match('|^(.+?)\((.*?)\)$|', $str, $arr)) {
70
-            $parsed['phptype']  = $arr[1];
71
-            $parsed['dbsyntax'] = (empty($arr[2])) ? $arr[1] : $arr[2];
72
-        } else {
73
-            $parsed['phptype']  = $str;
74
-            $parsed['dbsyntax'] = $str;
75
-        }
67
+		// Get phptype and dbsyntax
68
+		// $str => phptype(dbsyntax)
69
+		if (preg_match('|^(.+?)\((.*?)\)$|', $str, $arr)) {
70
+			$parsed['phptype']  = $arr[1];
71
+			$parsed['dbsyntax'] = (empty($arr[2])) ? $arr[1] : $arr[2];
72
+		} else {
73
+			$parsed['phptype']  = $str;
74
+			$parsed['dbsyntax'] = $str;
75
+		}
76 76
 
77
-        if (empty($dsn)) {
78
-            return $parsed;
79
-        }
77
+		if (empty($dsn)) {
78
+			return $parsed;
79
+		}
80 80
 
81
-        // Get (if found): username and password
82
-        // $dsn => username:password@protocol+hostspec/database
83
-        if (($at = strrpos($dsn,'@')) !== false) {
84
-            $str = substr($dsn, 0, $at);
85
-            $dsn = substr($dsn, $at + 1);
86
-            if (($pos = strpos($str, ':')) !== false) {
87
-                $parsed['username'] = rawurldecode(substr($str, 0, $pos));
88
-                $parsed['password'] = rawurldecode(substr($str, $pos + 1));
89
-            } else {
90
-                $parsed['username'] = rawurldecode($str);
91
-            }
92
-        }
81
+		// Get (if found): username and password
82
+		// $dsn => username:password@protocol+hostspec/database
83
+		if (($at = strrpos($dsn,'@')) !== false) {
84
+			$str = substr($dsn, 0, $at);
85
+			$dsn = substr($dsn, $at + 1);
86
+			if (($pos = strpos($str, ':')) !== false) {
87
+				$parsed['username'] = rawurldecode(substr($str, 0, $pos));
88
+				$parsed['password'] = rawurldecode(substr($str, $pos + 1));
89
+			} else {
90
+				$parsed['username'] = rawurldecode($str);
91
+			}
92
+		}
93 93
 
94
-        // Find protocol and hostspec
94
+		// Find protocol and hostspec
95 95
 
96
-        // $dsn => proto(proto_opts)/database
97
-        if (preg_match('|^([^(]+)\((.*?)\)/?(.*?)$|', $dsn, $match)) {
98
-            $proto       = $match[1];
99
-            $proto_opts  = (!empty($match[2])) ? $match[2] : false;
100
-            $dsn         = $match[3];
96
+		// $dsn => proto(proto_opts)/database
97
+		if (preg_match('|^([^(]+)\((.*?)\)/?(.*?)$|', $dsn, $match)) {
98
+			$proto       = $match[1];
99
+			$proto_opts  = (!empty($match[2])) ? $match[2] : false;
100
+			$dsn         = $match[3];
101 101
 
102
-        // $dsn => protocol+hostspec/database (old format)
103
-        } else {
104
-            if (strpos($dsn, '+') !== false) {
105
-                list($proto, $dsn) = explode('+', $dsn, 2);
106
-            }
107
-            if (strpos($dsn, '/') !== false) {
108
-                list($proto_opts, $dsn) = explode('/', $dsn, 2);
109
-            } else {
110
-                $proto_opts = $dsn;
111
-                $dsn = null;
112
-            }
113
-        }
102
+		// $dsn => protocol+hostspec/database (old format)
103
+		} else {
104
+			if (strpos($dsn, '+') !== false) {
105
+				list($proto, $dsn) = explode('+', $dsn, 2);
106
+			}
107
+			if (strpos($dsn, '/') !== false) {
108
+				list($proto_opts, $dsn) = explode('/', $dsn, 2);
109
+			} else {
110
+				$proto_opts = $dsn;
111
+				$dsn = null;
112
+			}
113
+		}
114 114
 
115
-        // process the different protocol options
116
-        $parsed['protocol'] = (!empty($proto)) ? $proto : 'tcp';
117
-        $proto_opts = rawurldecode($proto_opts);
118
-        if ($parsed['protocol'] == 'tcp') {
119
-            if (strpos($proto_opts, ':') !== false) {
120
-                list($parsed['hostspec'], $parsed['port']) = explode(':', $proto_opts);
121
-            } else {
122
-                $parsed['hostspec'] = $proto_opts;
123
-            }
124
-        } elseif ($parsed['protocol'] == 'unix') {
125
-            $parsed['socket'] = $proto_opts;
126
-        }
115
+		// process the different protocol options
116
+		$parsed['protocol'] = (!empty($proto)) ? $proto : 'tcp';
117
+		$proto_opts = rawurldecode($proto_opts);
118
+		if ($parsed['protocol'] == 'tcp') {
119
+			if (strpos($proto_opts, ':') !== false) {
120
+				list($parsed['hostspec'], $parsed['port']) = explode(':', $proto_opts);
121
+			} else {
122
+				$parsed['hostspec'] = $proto_opts;
123
+			}
124
+		} elseif ($parsed['protocol'] == 'unix') {
125
+			$parsed['socket'] = $proto_opts;
126
+		}
127 127
 
128
-        // Get dabase if any
129
-        // $dsn => database
130
-        if (!empty($dsn)) {
131
-            // /database
132
-            if (($pos = strpos($dsn, '?')) === false) {
133
-                $parsed['database'] = $dsn;
134
-            // /database?param1=value1&param2=value2
135
-            } else {
136
-                $parsed['database'] = substr($dsn, 0, $pos);
137
-                $dsn = substr($dsn, $pos + 1);
138
-                if (strpos($dsn, '&') !== false) {
139
-                    $opts = explode('&', $dsn);
140
-                } else { // database?param1=value1
141
-                    $opts = array($dsn);
142
-                }
143
-                foreach ($opts as $opt) {
144
-                    list($key, $value) = explode('=', $opt);
145
-                    if (!isset($parsed[$key])) { // don't allow params overwrite
146
-                        $parsed[$key] = rawurldecode($value);
147
-                    }
148
-                }
149
-            }
150
-        }
128
+		// Get dabase if any
129
+		// $dsn => database
130
+		if (!empty($dsn)) {
131
+			// /database
132
+			if (($pos = strpos($dsn, '?')) === false) {
133
+				$parsed['database'] = $dsn;
134
+			// /database?param1=value1&param2=value2
135
+			} else {
136
+				$parsed['database'] = substr($dsn, 0, $pos);
137
+				$dsn = substr($dsn, $pos + 1);
138
+				if (strpos($dsn, '&') !== false) {
139
+					$opts = explode('&', $dsn);
140
+				} else { // database?param1=value1
141
+					$opts = array($dsn);
142
+				}
143
+				foreach ($opts as $opt) {
144
+					list($key, $value) = explode('=', $opt);
145
+					if (!isset($parsed[$key])) { // don't allow params overwrite
146
+						$parsed[$key] = rawurldecode($value);
147
+					}
148
+				}
149
+			}
150
+		}
151 151
 
152
-        return $parsed;
153
-    }
152
+		return $parsed;
153
+	}
154 154
     
155 155
    
156 156
 	/**
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 
81 81
         // Get (if found): username and password
82 82
         // $dsn => username:password@protocol+hostspec/database
83
-        if (($at = strrpos($dsn,'@')) !== false) {
83
+        if (($at = strrpos($dsn, '@')) !== false) {
84 84
             $str = substr($dsn, 0, $at);
85 85
             $dsn = substr($dsn, $at + 1);
86 86
             if (($pos = strpos($str, ':')) !== false) {
@@ -161,9 +161,9 @@  discard block
 block discarded – undo
161 161
 	 */
162 162
 	function I18N_toUTF8($string, $from)
163 163
 	{
164
-		if($from != 'UTF-8')
164
+		if ($from != 'UTF-8')
165 165
 		{
166
-			$s = iconv($from,'UTF-8',$string); //to UTF-8
166
+			$s = iconv($from, 'UTF-8', $string); //to UTF-8
167 167
 			return $s !== false ? $s : $string; //it could return false
168 168
 		}
169 169
 		return $string;
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
 	 */
178 178
 	function I18N_toEncoding($string, $to)
179 179
 	{
180
-		if($to != 'UTF-8')
180
+		if ($to != 'UTF-8')
181 181
 		{
182 182
 			$s = iconv('UTF-8', $to, $string);
183 183
 			return $s !== false ? $s : $string;
Please login to merge, or discard this patch.
framework/interfaces.php 2 patches
Doc Comments   +18 added lines patch added patch discarded remove patch
@@ -23,6 +23,7 @@  discard block
 block discarded – undo
23 23
 	/**
24 24
 	 * Initializes the module.
25 25
 	 * @param TXmlElement the configuration for the module
26
+	 * @return void
26 27
 	 */
27 28
 	public function init($config);
28 29
 	/**
@@ -31,6 +32,7 @@  discard block
 block discarded – undo
31 32
 	public function getID();
32 33
 	/**
33 34
 	 * @param string ID of the module
35
+	 * @return void
34 36
 	 */
35 37
 	public function setID($id);
36 38
 }
@@ -49,6 +51,7 @@  discard block
 block discarded – undo
49 51
 	/**
50 52
 	 * Initializes the service.
51 53
 	 * @param TXmlElement the configuration for the service
54
+	 * @return void
52 55
 	 */
53 56
 	public function init($config);
54 57
 	/**
@@ -57,6 +60,7 @@  discard block
 block discarded – undo
57 60
 	public function getID();
58 61
 	/**
59 62
 	 * @param string ID of the service
63
+	 * @return void
60 64
 	 */
61 65
 	public function setID($id);
62 66
 	/**
@@ -65,10 +69,12 @@  discard block
 block discarded – undo
65 69
 	public function getEnabled();
66 70
 	/**
67 71
 	 * @param boolean whether the service is enabled
72
+	 * @return void
68 73
 	 */
69 74
 	public function setEnabled($value);
70 75
 	/**
71 76
 	 * Runs the service.
77
+	 * @return void
72 78
 	 */
73 79
 	public function run();
74 80
 }
@@ -87,6 +93,7 @@  discard block
 block discarded – undo
87 93
 	/**
88 94
 	 * Writes a string.
89 95
 	 * @param string string to be written
96
+	 * @return void
90 97
 	 */
91 98
 	public function write($str);
92 99
 	/**
@@ -113,6 +120,7 @@  discard block
 block discarded – undo
113 120
 	public function getName();
114 121
 	/**
115 122
 	 * @param string username
123
+	 * @return void
116 124
 	 */
117 125
 	public function setName($value);
118 126
 	/**
@@ -121,6 +129,8 @@  discard block
 block discarded – undo
121 129
 	public function getIsGuest();
122 130
 	/**
123 131
 	 * @param boolean if the user is a guest
132
+	 * @param boolean $value
133
+	 * @return void
124 134
 	 */
125 135
 	public function setIsGuest($value);
126 136
 	/**
@@ -167,6 +177,7 @@  discard block
 block discarded – undo
167 177
 	/**
168 178
 	 * Saves state into a persistent storage.
169 179
 	 * @param mixed the state to be saved
180
+	 * @return void
170 181
 	 */
171 182
 	public function save($state);
172 183
 }
@@ -208,6 +219,7 @@  discard block
 block discarded – undo
208 219
 	 * @param mixed the value to be cached
209 220
 	 * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
210 221
 	 * @param ICacheDependency dependency of the cached item. If the dependency changes, the item is labelled invalid.
222
+	 * @param string $id
211 223
 	 * @return boolean true if the value is successfully stored into cache, false otherwise
212 224
 	 */
213 225
 	public function add($id,$value,$expire=0,$dependency=null);
@@ -259,6 +271,7 @@  discard block
 block discarded – undo
259 271
 	/**
260 272
 	 * Renders the component to end-users.
261 273
 	 * @param ITextWriter writer for the rendering purpose
274
+	 * @return void
262 275
 	 */
263 276
 	public function render($writer);
264 277
 }
@@ -276,6 +289,7 @@  discard block
 block discarded – undo
276 289
 {
277 290
 	/**
278 291
 	 * Performs databinding.
292
+	 * @return void
279 293
 	 */
280 294
 	public function dataBind();
281 295
 }
@@ -301,6 +315,7 @@  discard block
 block discarded – undo
301 315
 	public function getStyle();
302 316
 	/**
303 317
 	 * Removes all styles associated with the object
318
+	 * @return void
304 319
 	 */
305 320
 	public function clearStyle();
306 321
 }
@@ -339,6 +354,7 @@  discard block
 block discarded – undo
339 354
 	 * appropriate event(s) (e.g. OnClick, OnCommand) indicating the component
340 355
 	 * is responsible for the callback event.
341 356
 	 * @param TCallbackEventParameter the parameter associated with the callback event
357
+	 * @return void
342 358
 	 */
343 359
 	public function raiseCallbackEvent($eventArgument);
344 360
 }
@@ -362,6 +378,8 @@  discard block
 block discarded – undo
362 378
 
363 379
 	/**
364 380
 	 * @param mixed the data to be bound to this object
381
+	 * @param TActiveRecord $value
382
+	 * @return void
365 383
 	 */
366 384
 	public function setData($value);
367 385
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 	 * @param ICacheDependency dependency of the cached item. If the dependency changes, the item is labelled invalid.
201 201
 	 * @return boolean true if the value is successfully stored into cache, false otherwise
202 202
 	 */
203
-	public function set($id,$value,$expire=0,$dependency=null);
203
+	public function set($id, $value, $expire = 0, $dependency = null);
204 204
 	/**
205 205
 	 * Stores a value identified by a key into cache if the cache does not contain this key.
206 206
 	 * Nothing will be done if the cache already contains the key.
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 	 * @param ICacheDependency dependency of the cached item. If the dependency changes, the item is labelled invalid.
211 211
 	 * @return boolean true if the value is successfully stored into cache, false otherwise
212 212
 	 */
213
-	public function add($id,$value,$expire=0,$dependency=null);
213
+	public function add($id, $value, $expire = 0, $dependency = null);
214 214
 	/**
215 215
 	 * Deletes a value with the specified key from cache
216 216
 	 * @param string the key of the value to be deleted
Please login to merge, or discard this patch.
framework/IO/TTarFileExtractor.php 4 patches
Doc Comments   +9 added lines patch added patch discarded remove patch
@@ -224,6 +224,9 @@  discard block
 block discarded – undo
224 224
       return $v_block;
225 225
     }
226 226
 
227
+    /**
228
+     * @param double $p_len
229
+     */
227 230
     private function _jumpBlock($p_len=null)
228 231
     {
229 232
       if (is_resource($this->_file)) {
@@ -317,6 +320,12 @@  discard block
 block discarded – undo
317 320
       return true;
318 321
     }
319 322
 
323
+    /**
324
+     * @param string $p_path
325
+     * @param string $p_mode
326
+     * @param integer $p_file_list
327
+     * @param string $p_remove_path
328
+     */
320 329
     protected function _extractList($p_path, &$p_list_detail, $p_mode,
321 330
 	                      $p_file_list, $p_remove_path)
322 331
     {
Please login to merge, or discard this patch.
Indentation   +510 added lines, -510 removed lines patch added patch discarded remove patch
@@ -35,537 +35,537 @@
 block discarded – undo
35 35
  */
36 36
 class TTarFileExtractor
37 37
 {
38
-    /**
39
-    * @var string Name of the Tar
40
-    */
41
-    private $_tarname='';
42
-
43
-    /**
44
-    * @var file descriptor
45
-    */
46
-    private $_file=0;
47
-
48
-    /**
49
-    * @var string Local Tar name of a remote Tar (http:// or ftp://)
50
-    */
51
-    private $_temp_tarname='';
52
-
53
-    /**
54
-    * Archive_Tar Class constructor. This flavour of the constructor only
55
-    * declare a new Archive_Tar object, identifying it by the name of the
56
-    * tar file.
57
-    *
58
-    * @param    string  $p_tarname  The name of the tar archive to create
59
-    * @access public
60
-    */
61
-    public function __construct($p_tarname)
62
-    {
63
-        $this->_tarname = $p_tarname;
64
-    }
65
-
66
-    public function __destruct()
67
-    {
68
-        $this->_close();
69
-        // ----- Look for a local copy to delete
70
-        if ($this->_temp_tarname != '')
71
-            @unlink($this->_temp_tarname);
72
-    }
73
-
74
-    public function extract($p_path='')
75
-    {
76
-        return $this->extractModify($p_path, '');
77
-    }
78
-
79
-    /**
80
-    * This method extract all the content of the archive in the directory
81
-    * indicated by $p_path. When relevant the memorized path of the
82
-    * files/dir can be modified by removing the $p_remove_path path at the
83
-    * beginning of the file/dir path.
84
-    * While extracting a file, if the directory path does not exists it is
85
-    * created.
86
-    * While extracting a file, if the file already exists it is replaced
87
-    * without looking for last modification date.
88
-    * While extracting a file, if the file already exists and is write
89
-    * protected, the extraction is aborted.
90
-    * While extracting a file, if a directory with the same name already
91
-    * exists, the extraction is aborted.
92
-    * While extracting a directory, if a file with the same name already
93
-    * exists, the extraction is aborted.
94
-    * While extracting a file/directory if the destination directory exist
95
-    * and is write protected, or does not exist but can not be created,
96
-    * the extraction is aborted.
97
-    * If after extraction an extracted file does not show the correct
98
-    * stored file size, the extraction is aborted.
99
-    * When the extraction is aborted, a PEAR error text is set and false
100
-    * is returned. However the result can be a partial extraction that may
101
-    * need to be manually cleaned.
102
-    *
103
-    * @param string $p_path         The path of the directory where the
104
-	*                               files/dir need to by extracted.
105
-    * @param string $p_remove_path  Part of the memorized path that can be
106
-	*                               removed if present at the beginning of
107
-	*                               the file/dir path.
108
-    * @return boolean               true on success, false on error.
109
-    * @access public
110
-    */
111
-    protected function extractModify($p_path, $p_remove_path)
112
-    {
113
-        $v_result = true;
114
-        $v_list_detail = array();
115
-
116
-        if ($v_result = $this->_openRead()) {
117
-            $v_result = $this->_extractList($p_path, $v_list_detail,
118
-			                                "complete", 0, $p_remove_path);
119
-            $this->_close();
120
-        }
121
-
122
-        return $v_result;
123
-    }
124
-
125
-    protected function _error($p_message)
126
-    {
38
+	/**
39
+	 * @var string Name of the Tar
40
+	 */
41
+	private $_tarname='';
42
+
43
+	/**
44
+	 * @var file descriptor
45
+	 */
46
+	private $_file=0;
47
+
48
+	/**
49
+	 * @var string Local Tar name of a remote Tar (http:// or ftp://)
50
+	 */
51
+	private $_temp_tarname='';
52
+
53
+	/**
54
+	 * Archive_Tar Class constructor. This flavour of the constructor only
55
+	 * declare a new Archive_Tar object, identifying it by the name of the
56
+	 * tar file.
57
+	 *
58
+	 * @param    string  $p_tarname  The name of the tar archive to create
59
+	 * @access public
60
+	 */
61
+	public function __construct($p_tarname)
62
+	{
63
+		$this->_tarname = $p_tarname;
64
+	}
65
+
66
+	public function __destruct()
67
+	{
68
+		$this->_close();
69
+		// ----- Look for a local copy to delete
70
+		if ($this->_temp_tarname != '')
71
+			@unlink($this->_temp_tarname);
72
+	}
73
+
74
+	public function extract($p_path='')
75
+	{
76
+		return $this->extractModify($p_path, '');
77
+	}
78
+
79
+	/**
80
+	 * This method extract all the content of the archive in the directory
81
+	 * indicated by $p_path. When relevant the memorized path of the
82
+	 * files/dir can be modified by removing the $p_remove_path path at the
83
+	 * beginning of the file/dir path.
84
+	 * While extracting a file, if the directory path does not exists it is
85
+	 * created.
86
+	 * While extracting a file, if the file already exists it is replaced
87
+	 * without looking for last modification date.
88
+	 * While extracting a file, if the file already exists and is write
89
+	 * protected, the extraction is aborted.
90
+	 * While extracting a file, if a directory with the same name already
91
+	 * exists, the extraction is aborted.
92
+	 * While extracting a directory, if a file with the same name already
93
+	 * exists, the extraction is aborted.
94
+	 * While extracting a file/directory if the destination directory exist
95
+	 * and is write protected, or does not exist but can not be created,
96
+	 * the extraction is aborted.
97
+	 * If after extraction an extracted file does not show the correct
98
+	 * stored file size, the extraction is aborted.
99
+	 * When the extraction is aborted, a PEAR error text is set and false
100
+	 * is returned. However the result can be a partial extraction that may
101
+	 * need to be manually cleaned.
102
+	 *
103
+	 * @param string $p_path         The path of the directory where the
104
+	 *                               files/dir need to by extracted.
105
+	 * @param string $p_remove_path  Part of the memorized path that can be
106
+	 *                               removed if present at the beginning of
107
+	 *                               the file/dir path.
108
+	 * @return boolean               true on success, false on error.
109
+	 * @access public
110
+	 */
111
+	protected function extractModify($p_path, $p_remove_path)
112
+	{
113
+		$v_result = true;
114
+		$v_list_detail = array();
115
+
116
+		if ($v_result = $this->_openRead()) {
117
+			$v_result = $this->_extractList($p_path, $v_list_detail,
118
+											"complete", 0, $p_remove_path);
119
+			$this->_close();
120
+		}
121
+
122
+		return $v_result;
123
+	}
124
+
125
+	protected function _error($p_message)
126
+	{
127 127
 		throw new Exception($p_message);
128
-    }
129
-
130
-    private function _isArchive($p_filename=null)
131
-    {
132
-        if ($p_filename == null) {
133
-            $p_filename = $this->_tarname;
134
-        }
135
-        clearstatcache();
136
-        return @is_file($p_filename);
137
-    }
138
-
139
-    private function _openRead()
140
-    {
141
-        if (strtolower(substr($this->_tarname, 0, 7)) == 'http://') {
142
-
143
-          // ----- Look if a local copy need to be done
144
-          if ($this->_temp_tarname == '') {
145
-              $this->_temp_tarname = uniqid('tar').'.tmp';
146
-              if (!$v_file_from = @fopen($this->_tarname, 'rb')) {
147
-                $this->_error('Unable to open in read mode \''
148
-				              .$this->_tarname.'\'');
149
-                $this->_temp_tarname = '';
150
-                return false;
151
-              }
152
-              if (!$v_file_to = @fopen($this->_temp_tarname, 'wb')) {
153
-                $this->_error('Unable to open in write mode \''
154
-				              .$this->_temp_tarname.'\'');
155
-                $this->_temp_tarname = '';
156
-                return false;
157
-              }
158
-              while ($v_data = @fread($v_file_from, 1024))
159
-                  @fwrite($v_file_to, $v_data);
160
-              @fclose($v_file_from);
161
-              @fclose($v_file_to);
162
-          }
163
-
164
-          // ----- File to open if the local copy
165
-          $v_filename = $this->_temp_tarname;
166
-
167
-        } else
168
-          // ----- File to open if the normal Tar file
169
-          $v_filename = $this->_tarname;
128
+	}
129
+
130
+	private function _isArchive($p_filename=null)
131
+	{
132
+		if ($p_filename == null) {
133
+			$p_filename = $this->_tarname;
134
+		}
135
+		clearstatcache();
136
+		return @is_file($p_filename);
137
+	}
138
+
139
+	private function _openRead()
140
+	{
141
+		if (strtolower(substr($this->_tarname, 0, 7)) == 'http://') {
142
+
143
+		  // ----- Look if a local copy need to be done
144
+		  if ($this->_temp_tarname == '') {
145
+			  $this->_temp_tarname = uniqid('tar').'.tmp';
146
+			  if (!$v_file_from = @fopen($this->_tarname, 'rb')) {
147
+				$this->_error('Unable to open in read mode \''
148
+							  .$this->_tarname.'\'');
149
+				$this->_temp_tarname = '';
150
+				return false;
151
+			  }
152
+			  if (!$v_file_to = @fopen($this->_temp_tarname, 'wb')) {
153
+				$this->_error('Unable to open in write mode \''
154
+							  .$this->_temp_tarname.'\'');
155
+				$this->_temp_tarname = '';
156
+				return false;
157
+			  }
158
+			  while ($v_data = @fread($v_file_from, 1024))
159
+				  @fwrite($v_file_to, $v_data);
160
+			  @fclose($v_file_from);
161
+			  @fclose($v_file_to);
162
+		  }
163
+
164
+		  // ----- File to open if the local copy
165
+		  $v_filename = $this->_temp_tarname;
166
+
167
+		} else
168
+		  // ----- File to open if the normal Tar file
169
+		  $v_filename = $this->_tarname;
170 170
 
171 171
 		$this->_file = @fopen($v_filename, "rb");
172 172
 
173
-        if ($this->_file == 0) {
174
-            $this->_error('Unable to open in read mode \''.$v_filename.'\'');
175
-            return false;
176
-        }
173
+		if ($this->_file == 0) {
174
+			$this->_error('Unable to open in read mode \''.$v_filename.'\'');
175
+			return false;
176
+		}
177 177
 
178
-        return true;
179
-    }
178
+		return true;
179
+	}
180 180
 
181
-    private function _close()
182
-    {
183
-        //if (isset($this->_file)) {
184
-        if (is_resource($this->_file))
181
+	private function _close()
182
+	{
183
+		//if (isset($this->_file)) {
184
+		if (is_resource($this->_file))
185 185
 		{
186
-               @fclose($this->_file);
187
-            $this->_file = 0;
188
-        }
189
-
190
-        // ----- Look if a local copy need to be erase
191
-        // Note that it might be interesting to keep the url for a time : ToDo
192
-        if ($this->_temp_tarname != '') {
193
-            @unlink($this->_temp_tarname);
194
-            $this->_temp_tarname = '';
195
-        }
196
-
197
-        return true;
198
-    }
199
-
200
-    private function _cleanFile()
201
-    {
202
-        $this->_close();
203
-
204
-        // ----- Look for a local copy
205
-        if ($this->_temp_tarname != '') {
206
-            // ----- Remove the local copy but not the remote tarname
207
-            @unlink($this->_temp_tarname);
208
-            $this->_temp_tarname = '';
209
-        } else {
210
-            // ----- Remove the local tarname file
211
-            @unlink($this->_tarname);
212
-        }
213
-        $this->_tarname = '';
214
-
215
-        return true;
216
-    }
217
-
218
-    private function _readBlock()
219
-    {
220
-      $v_block = null;
221
-      if (is_resource($this->_file)) {
222
-              $v_block = @fread($this->_file, 512);
223
-      }
224
-      return $v_block;
225
-    }
226
-
227
-    private function _jumpBlock($p_len=null)
228
-    {
229
-      if (is_resource($this->_file)) {
230
-          if ($p_len === null)
231
-              $p_len = 1;
232
-
233
-              @fseek($this->_file, @ftell($this->_file)+($p_len*512));
234
-      }
235
-      return true;
236
-    }
237
-
238
-    private function _readHeader($v_binary_data, &$v_header)
239
-    {
240
-        if (strlen($v_binary_data)==0) {
241
-            $v_header['filename'] = '';
242
-            return true;
243
-        }
244
-
245
-        if (strlen($v_binary_data) != 512) {
246
-            $v_header['filename'] = '';
247
-            $this->_error('Invalid block size : '.strlen($v_binary_data));
248
-            return false;
249
-        }
250
-
251
-        // ----- Calculate the checksum
252
-        $v_checksum = 0;
253
-        // ..... First part of the header
254
-        for ($i=0; $i<148; $i++)
255
-            $v_checksum+=ord(substr($v_binary_data,$i,1));
256
-        // ..... Ignore the checksum value and replace it by ' ' (space)
257
-        for ($i=148; $i<156; $i++)
258
-            $v_checksum += ord(' ');
259
-        // ..... Last part of the header
260
-        for ($i=156; $i<512; $i++)
261
-           $v_checksum+=ord(substr($v_binary_data,$i,1));
262
-
263
-        $v_data = unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/"
264
-		                 ."a8checksum/a1typeflag/a100link/a6magic/a2version/"
186
+			   @fclose($this->_file);
187
+			$this->_file = 0;
188
+		}
189
+
190
+		// ----- Look if a local copy need to be erase
191
+		// Note that it might be interesting to keep the url for a time : ToDo
192
+		if ($this->_temp_tarname != '') {
193
+			@unlink($this->_temp_tarname);
194
+			$this->_temp_tarname = '';
195
+		}
196
+
197
+		return true;
198
+	}
199
+
200
+	private function _cleanFile()
201
+	{
202
+		$this->_close();
203
+
204
+		// ----- Look for a local copy
205
+		if ($this->_temp_tarname != '') {
206
+			// ----- Remove the local copy but not the remote tarname
207
+			@unlink($this->_temp_tarname);
208
+			$this->_temp_tarname = '';
209
+		} else {
210
+			// ----- Remove the local tarname file
211
+			@unlink($this->_tarname);
212
+		}
213
+		$this->_tarname = '';
214
+
215
+		return true;
216
+	}
217
+
218
+	private function _readBlock()
219
+	{
220
+	  $v_block = null;
221
+	  if (is_resource($this->_file)) {
222
+			  $v_block = @fread($this->_file, 512);
223
+	  }
224
+	  return $v_block;
225
+	}
226
+
227
+	private function _jumpBlock($p_len=null)
228
+	{
229
+	  if (is_resource($this->_file)) {
230
+		  if ($p_len === null)
231
+			  $p_len = 1;
232
+
233
+			  @fseek($this->_file, @ftell($this->_file)+($p_len*512));
234
+	  }
235
+	  return true;
236
+	}
237
+
238
+	private function _readHeader($v_binary_data, &$v_header)
239
+	{
240
+		if (strlen($v_binary_data)==0) {
241
+			$v_header['filename'] = '';
242
+			return true;
243
+		}
244
+
245
+		if (strlen($v_binary_data) != 512) {
246
+			$v_header['filename'] = '';
247
+			$this->_error('Invalid block size : '.strlen($v_binary_data));
248
+			return false;
249
+		}
250
+
251
+		// ----- Calculate the checksum
252
+		$v_checksum = 0;
253
+		// ..... First part of the header
254
+		for ($i=0; $i<148; $i++)
255
+			$v_checksum+=ord(substr($v_binary_data,$i,1));
256
+		// ..... Ignore the checksum value and replace it by ' ' (space)
257
+		for ($i=148; $i<156; $i++)
258
+			$v_checksum += ord(' ');
259
+		// ..... Last part of the header
260
+		for ($i=156; $i<512; $i++)
261
+		   $v_checksum+=ord(substr($v_binary_data,$i,1));
262
+
263
+		$v_data = unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/"
264
+						 ."a8checksum/a1typeflag/a100link/a6magic/a2version/"
265 265
 						 ."a32uname/a32gname/a8devmajor/a8devminor",
266 266
 						 $v_binary_data);
267 267
 
268
-        // ----- Extract the checksum
269
-        $v_header['checksum'] = OctDec(trim($v_data['checksum']));
270
-        if ($v_header['checksum'] != $v_checksum) {
271
-            $v_header['filename'] = '';
268
+		// ----- Extract the checksum
269
+		$v_header['checksum'] = OctDec(trim($v_data['checksum']));
270
+		if ($v_header['checksum'] != $v_checksum) {
271
+			$v_header['filename'] = '';
272 272
 
273
-            // ----- Look for last block (empty block)
274
-            if (($v_checksum == 256) && ($v_header['checksum'] == 0))
275
-                return true;
273
+			// ----- Look for last block (empty block)
274
+			if (($v_checksum == 256) && ($v_header['checksum'] == 0))
275
+				return true;
276 276
 
277
-            $this->_error('Invalid checksum for file "'.$v_data['filename']
278
-			              .'" : '.$v_checksum.' calculated, '
277
+			$this->_error('Invalid checksum for file "'.$v_data['filename']
278
+						  .'" : '.$v_checksum.' calculated, '
279 279
 						  .$v_header['checksum'].' expected');
280
-            return false;
281
-        }
282
-
283
-        // ----- Extract the properties
284
-        $v_header['filename'] = trim($v_data['filename']);
285
-        $v_header['mode'] = OctDec(trim($v_data['mode']));
286
-        $v_header['uid'] = OctDec(trim($v_data['uid']));
287
-        $v_header['gid'] = OctDec(trim($v_data['gid']));
288
-        $v_header['size'] = OctDec(trim($v_data['size']));
289
-        $v_header['mtime'] = OctDec(trim($v_data['mtime']));
290
-        if (($v_header['typeflag'] = $v_data['typeflag']) == "5") {
291
-          $v_header['size'] = 0;
292
-        }
293
-        return true;
294
-    }
295
-
296
-    private function _readLongHeader(&$v_header)
297
-    {
298
-      $v_filename = '';
299
-      $n = floor($v_header['size']/512);
300
-      for ($i=0; $i<$n; $i++) {
301
-        $v_content = $this->_readBlock();
302
-        $v_filename .= $v_content;
303
-      }
304
-      if (($v_header['size'] % 512) != 0) {
305
-        $v_content = $this->_readBlock();
306
-        $v_filename .= $v_content;
307
-      }
308
-
309
-      // ----- Read the next header
310
-      $v_binary_data = $this->_readBlock();
311
-
312
-      if (!$this->_readHeader($v_binary_data, $v_header))
313
-        return false;
314
-
315
-      $v_header['filename'] = $v_filename;
316
-
317
-      return true;
318
-    }
319
-
320
-    protected function _extractList($p_path, &$p_list_detail, $p_mode,
321
-	                      $p_file_list, $p_remove_path)
322
-    {
323
-    $v_result=true;
324
-    $v_nb = 0;
325
-    $v_extract_all = true;
326
-    $v_listing = false;
327
-
328
-    $p_path = $this->_translateWinPath($p_path, false);
329
-    if ($p_path == '' || (substr($p_path, 0, 1) != '/'
330
-	    && substr($p_path, 0, 3) != "../" && !strpos($p_path, ':'))) {
331
-      $p_path = "./".$p_path;
332
-    }
333
-    $p_remove_path = $this->_translateWinPath($p_remove_path);
334
-
335
-    // ----- Look for path to remove format (should end by /)
336
-    if (($p_remove_path != '') && (substr($p_remove_path, -1) != '/'))
337
-      $p_remove_path .= '/';
338
-    $p_remove_path_size = strlen($p_remove_path);
339
-
340
-    switch ($p_mode) {
341
-      case "complete" :
342
-        $v_extract_all = true;
343
-        $v_listing = false;
344
-      break;
345
-      case "partial" :
346
-          $v_extract_all = false;
347
-          $v_listing = false;
348
-      break;
349
-      case "list" :
350
-          $v_extract_all = false;
351
-          $v_listing = true;
352
-      break;
353
-      default :
354
-        $this->_error('Invalid extract mode ('.$p_mode.')');
355
-        return false;
356
-    }
357
-
358
-    clearstatcache();
359
-
360
-    while (strlen($v_binary_data = $this->_readBlock()) != 0)
361
-    {
362
-      $v_extract_file = false;
363
-      $v_extraction_stopped = 0;
364
-
365
-      if (!$this->_readHeader($v_binary_data, $v_header))
366
-        return false;
367
-
368
-      if ($v_header['filename'] == '') {
369
-        continue;
370
-      }
371
-
372
-      // ----- Look for long filename
373
-      if ($v_header['typeflag'] == 'L') {
374
-        if (!$this->_readLongHeader($v_header))
375
-          return false;
376
-      }
377
-
378
-      if ((!$v_extract_all) && (is_array($p_file_list))) {
379
-        // ----- By default no unzip if the file is not found
380
-        $v_extract_file = false;
381
-
382
-        for ($i=0; $i<sizeof($p_file_list); $i++) {
383
-          // ----- Look if it is a directory
384
-          if (substr($p_file_list[$i], -1) == '/') {
385
-            // ----- Look if the directory is in the filename path
386
-            if ((strlen($v_header['filename']) > strlen($p_file_list[$i]))
387
-			    && (substr($v_header['filename'], 0, strlen($p_file_list[$i]))
388
-				    == $p_file_list[$i])) {
389
-              $v_extract_file = true;
390
-              break;
391
-            }
392
-          }
393
-
394
-          // ----- It is a file, so compare the file names
395
-          elseif ($p_file_list[$i] == $v_header['filename']) {
396
-            $v_extract_file = true;
397
-            break;
398
-          }
399
-        }
400
-      } else {
401
-        $v_extract_file = true;
402
-      }
403
-
404
-      // ----- Look if this file need to be extracted
405
-      if (($v_extract_file) && (!$v_listing))
406
-      {
407
-        if (($p_remove_path != '')
408
-            && (substr($v_header['filename'], 0, $p_remove_path_size)
409
-			    == $p_remove_path))
410
-          $v_header['filename'] = substr($v_header['filename'],
411
-		                                 $p_remove_path_size);
412
-        if (($p_path != './') && ($p_path != '/')) {
413
-          while (substr($p_path, -1) == '/')
414
-            $p_path = substr($p_path, 0, strlen($p_path)-1);
415
-
416
-          if (substr($v_header['filename'], 0, 1) == '/')
417
-              $v_header['filename'] = $p_path.$v_header['filename'];
418
-          else
419
-            $v_header['filename'] = $p_path.'/'.$v_header['filename'];
420
-        }
421
-        if (file_exists($v_header['filename'])) {
422
-          if (   (@is_dir($v_header['filename']))
423
-		      && ($v_header['typeflag'] == '')) {
424
-            $this->_error('File '.$v_header['filename']
425
-			              .' already exists as a directory');
426
-            return false;
427
-          }
428
-          if (   ($this->_isArchive($v_header['filename']))
429
-		      && ($v_header['typeflag'] == "5")) {
430
-            $this->_error('Directory '.$v_header['filename']
431
-			              .' already exists as a file');
432
-            return false;
433
-          }
434
-          if (!is_writeable($v_header['filename'])) {
435
-            $this->_error('File '.$v_header['filename']
436
-			              .' already exists and is write protected');
437
-            return false;
438
-          }
439
-          if (filemtime($v_header['filename']) > $v_header['mtime']) {
440
-            // To be completed : An error or silent no replace ?
441
-          }
442
-        }
443
-
444
-        // ----- Check the directory availability and create it if necessary
445
-        elseif (($v_result
446
-		         = $this->_dirCheck(($v_header['typeflag'] == "5"
447
-				                    ?$v_header['filename']
280
+			return false;
281
+		}
282
+
283
+		// ----- Extract the properties
284
+		$v_header['filename'] = trim($v_data['filename']);
285
+		$v_header['mode'] = OctDec(trim($v_data['mode']));
286
+		$v_header['uid'] = OctDec(trim($v_data['uid']));
287
+		$v_header['gid'] = OctDec(trim($v_data['gid']));
288
+		$v_header['size'] = OctDec(trim($v_data['size']));
289
+		$v_header['mtime'] = OctDec(trim($v_data['mtime']));
290
+		if (($v_header['typeflag'] = $v_data['typeflag']) == "5") {
291
+		  $v_header['size'] = 0;
292
+		}
293
+		return true;
294
+	}
295
+
296
+	private function _readLongHeader(&$v_header)
297
+	{
298
+	  $v_filename = '';
299
+	  $n = floor($v_header['size']/512);
300
+	  for ($i=0; $i<$n; $i++) {
301
+		$v_content = $this->_readBlock();
302
+		$v_filename .= $v_content;
303
+	  }
304
+	  if (($v_header['size'] % 512) != 0) {
305
+		$v_content = $this->_readBlock();
306
+		$v_filename .= $v_content;
307
+	  }
308
+
309
+	  // ----- Read the next header
310
+	  $v_binary_data = $this->_readBlock();
311
+
312
+	  if (!$this->_readHeader($v_binary_data, $v_header))
313
+		return false;
314
+
315
+	  $v_header['filename'] = $v_filename;
316
+
317
+	  return true;
318
+	}
319
+
320
+	protected function _extractList($p_path, &$p_list_detail, $p_mode,
321
+						  $p_file_list, $p_remove_path)
322
+	{
323
+	$v_result=true;
324
+	$v_nb = 0;
325
+	$v_extract_all = true;
326
+	$v_listing = false;
327
+
328
+	$p_path = $this->_translateWinPath($p_path, false);
329
+	if ($p_path == '' || (substr($p_path, 0, 1) != '/'
330
+		&& substr($p_path, 0, 3) != "../" && !strpos($p_path, ':'))) {
331
+	  $p_path = "./".$p_path;
332
+	}
333
+	$p_remove_path = $this->_translateWinPath($p_remove_path);
334
+
335
+	// ----- Look for path to remove format (should end by /)
336
+	if (($p_remove_path != '') && (substr($p_remove_path, -1) != '/'))
337
+	  $p_remove_path .= '/';
338
+	$p_remove_path_size = strlen($p_remove_path);
339
+
340
+	switch ($p_mode) {
341
+	  case "complete" :
342
+		$v_extract_all = true;
343
+		$v_listing = false;
344
+	  break;
345
+	  case "partial" :
346
+		  $v_extract_all = false;
347
+		  $v_listing = false;
348
+	  break;
349
+	  case "list" :
350
+		  $v_extract_all = false;
351
+		  $v_listing = true;
352
+	  break;
353
+	  default :
354
+		$this->_error('Invalid extract mode ('.$p_mode.')');
355
+		return false;
356
+	}
357
+
358
+	clearstatcache();
359
+
360
+	while (strlen($v_binary_data = $this->_readBlock()) != 0)
361
+	{
362
+	  $v_extract_file = false;
363
+	  $v_extraction_stopped = 0;
364
+
365
+	  if (!$this->_readHeader($v_binary_data, $v_header))
366
+		return false;
367
+
368
+	  if ($v_header['filename'] == '') {
369
+		continue;
370
+	  }
371
+
372
+	  // ----- Look for long filename
373
+	  if ($v_header['typeflag'] == 'L') {
374
+		if (!$this->_readLongHeader($v_header))
375
+		  return false;
376
+	  }
377
+
378
+	  if ((!$v_extract_all) && (is_array($p_file_list))) {
379
+		// ----- By default no unzip if the file is not found
380
+		$v_extract_file = false;
381
+
382
+		for ($i=0; $i<sizeof($p_file_list); $i++) {
383
+		  // ----- Look if it is a directory
384
+		  if (substr($p_file_list[$i], -1) == '/') {
385
+			// ----- Look if the directory is in the filename path
386
+			if ((strlen($v_header['filename']) > strlen($p_file_list[$i]))
387
+				&& (substr($v_header['filename'], 0, strlen($p_file_list[$i]))
388
+					== $p_file_list[$i])) {
389
+			  $v_extract_file = true;
390
+			  break;
391
+			}
392
+		  }
393
+
394
+		  // ----- It is a file, so compare the file names
395
+		  elseif ($p_file_list[$i] == $v_header['filename']) {
396
+			$v_extract_file = true;
397
+			break;
398
+		  }
399
+		}
400
+	  } else {
401
+		$v_extract_file = true;
402
+	  }
403
+
404
+	  // ----- Look if this file need to be extracted
405
+	  if (($v_extract_file) && (!$v_listing))
406
+	  {
407
+		if (($p_remove_path != '')
408
+			&& (substr($v_header['filename'], 0, $p_remove_path_size)
409
+				== $p_remove_path))
410
+		  $v_header['filename'] = substr($v_header['filename'],
411
+										 $p_remove_path_size);
412
+		if (($p_path != './') && ($p_path != '/')) {
413
+		  while (substr($p_path, -1) == '/')
414
+			$p_path = substr($p_path, 0, strlen($p_path)-1);
415
+
416
+		  if (substr($v_header['filename'], 0, 1) == '/')
417
+			  $v_header['filename'] = $p_path.$v_header['filename'];
418
+		  else
419
+			$v_header['filename'] = $p_path.'/'.$v_header['filename'];
420
+		}
421
+		if (file_exists($v_header['filename'])) {
422
+		  if (   (@is_dir($v_header['filename']))
423
+			  && ($v_header['typeflag'] == '')) {
424
+			$this->_error('File '.$v_header['filename']
425
+						  .' already exists as a directory');
426
+			return false;
427
+		  }
428
+		  if (   ($this->_isArchive($v_header['filename']))
429
+			  && ($v_header['typeflag'] == "5")) {
430
+			$this->_error('Directory '.$v_header['filename']
431
+						  .' already exists as a file');
432
+			return false;
433
+		  }
434
+		  if (!is_writeable($v_header['filename'])) {
435
+			$this->_error('File '.$v_header['filename']
436
+						  .' already exists and is write protected');
437
+			return false;
438
+		  }
439
+		  if (filemtime($v_header['filename']) > $v_header['mtime']) {
440
+			// To be completed : An error or silent no replace ?
441
+		  }
442
+		}
443
+
444
+		// ----- Check the directory availability and create it if necessary
445
+		elseif (($v_result
446
+				 = $this->_dirCheck(($v_header['typeflag'] == "5"
447
+									?$v_header['filename']
448 448
 									:dirname($v_header['filename'])))) != 1) {
449
-            $this->_error('Unable to create path for '.$v_header['filename']);
450
-            return false;
451
-        }
452
-
453
-        if ($v_extract_file) {
454
-          if ($v_header['typeflag'] == "5") {
455
-            if (!@file_exists($v_header['filename'])) {
456
-                if (!@mkdir($v_header['filename'], PRADO_CHMOD)) {
457
-                    $this->_error('Unable to create directory {'
458
-					              .$v_header['filename'].'}');
459
-                    return false;
460
-                }
461
-                chmod($v_header['filename'], PRADO_CHMOD);
462
-            }
463
-          } else {
464
-              if (($v_dest_file = @fopen($v_header['filename'], "wb")) == 0) {
465
-                  $this->_error('Error while opening {'.$v_header['filename']
466
-				                .'} in write binary mode');
467
-                  return false;
468
-              } else {
469
-                  $n = floor($v_header['size']/512);
470
-                  for ($i=0; $i<$n; $i++) {
471
-                      $v_content = $this->_readBlock();
472
-                      fwrite($v_dest_file, $v_content, 512);
473
-                  }
474
-            if (($v_header['size'] % 512) != 0) {
475
-              $v_content = $this->_readBlock();
476
-              fwrite($v_dest_file, $v_content, ($v_header['size'] % 512));
477
-            }
478
-
479
-            @fclose($v_dest_file);
480
-
481
-            // ----- Change the file mode, mtime
482
-            @touch($v_header['filename'], $v_header['mtime']);
483
-            // To be completed
484
-            //chmod($v_header[filename], DecOct($v_header[mode]));
485
-          }
486
-
487
-          // ----- Check the file size
488
-          clearstatcache();
489
-          if (filesize($v_header['filename']) != $v_header['size']) {
490
-              $this->_error('Extracted file '.$v_header['filename']
491
-			                .' does not have the correct file size \''
449
+			$this->_error('Unable to create path for '.$v_header['filename']);
450
+			return false;
451
+		}
452
+
453
+		if ($v_extract_file) {
454
+		  if ($v_header['typeflag'] == "5") {
455
+			if (!@file_exists($v_header['filename'])) {
456
+				if (!@mkdir($v_header['filename'], PRADO_CHMOD)) {
457
+					$this->_error('Unable to create directory {'
458
+								  .$v_header['filename'].'}');
459
+					return false;
460
+				}
461
+				chmod($v_header['filename'], PRADO_CHMOD);
462
+			}
463
+		  } else {
464
+			  if (($v_dest_file = @fopen($v_header['filename'], "wb")) == 0) {
465
+				  $this->_error('Error while opening {'.$v_header['filename']
466
+								.'} in write binary mode');
467
+				  return false;
468
+			  } else {
469
+				  $n = floor($v_header['size']/512);
470
+				  for ($i=0; $i<$n; $i++) {
471
+					  $v_content = $this->_readBlock();
472
+					  fwrite($v_dest_file, $v_content, 512);
473
+				  }
474
+			if (($v_header['size'] % 512) != 0) {
475
+			  $v_content = $this->_readBlock();
476
+			  fwrite($v_dest_file, $v_content, ($v_header['size'] % 512));
477
+			}
478
+
479
+			@fclose($v_dest_file);
480
+
481
+			// ----- Change the file mode, mtime
482
+			@touch($v_header['filename'], $v_header['mtime']);
483
+			// To be completed
484
+			//chmod($v_header[filename], DecOct($v_header[mode]));
485
+		  }
486
+
487
+		  // ----- Check the file size
488
+		  clearstatcache();
489
+		  if (filesize($v_header['filename']) != $v_header['size']) {
490
+			  $this->_error('Extracted file '.$v_header['filename']
491
+							.' does not have the correct file size \''
492 492
 							.filesize($v_header['filename'])
493 493
 							.'\' ('.$v_header['size']
494 494
 							.' expected). Archive may be corrupted.');
495
-              return false;
496
-          }
497
-          }
498
-        } else {
499
-          $this->_jumpBlock(ceil(($v_header['size']/512)));
500
-        }
501
-      } else {
502
-          $this->_jumpBlock(ceil(($v_header['size']/512)));
503
-      }
504
-
505
-      /* TBC : Seems to be unused ...
495
+			  return false;
496
+		  }
497
+		  }
498
+		} else {
499
+		  $this->_jumpBlock(ceil(($v_header['size']/512)));
500
+		}
501
+	  } else {
502
+		  $this->_jumpBlock(ceil(($v_header['size']/512)));
503
+	  }
504
+
505
+	  /* TBC : Seems to be unused ...
506 506
       if ($this->_compress)
507 507
         $v_end_of_file = @gzeof($this->_file);
508 508
       else
509 509
         $v_end_of_file = @feof($this->_file);
510 510
         */
511 511
 
512
-      if ($v_listing || $v_extract_file || $v_extraction_stopped) {
513
-        // ----- Log extracted files
514
-        if (($v_file_dir = dirname($v_header['filename']))
515
-		    == $v_header['filename'])
516
-          $v_file_dir = '';
517
-        if ((substr($v_header['filename'], 0, 1) == '/') && ($v_file_dir == ''))
518
-          $v_file_dir = '/';
519
-
520
-        $p_list_detail[$v_nb++] = $v_header;
521
-      }
522
-    }
523
-
524
-        return true;
525
-    }
526
-
527
-    /**
528
-     * Check if a directory exists and create it (including parent
529
-     * dirs) if not.
530
-     *
531
-     * @param string $p_dir directory to check
532
-     *
533
-     * @return bool true if the directory exists or was created
534
-     */
535
-    protected function _dirCheck($p_dir)
536
-    {
537
-        if ((@is_dir($p_dir)) || ($p_dir == ''))
538
-            return true;
539
-
540
-        $p_parent_dir = dirname($p_dir);
541
-
542
-        if (($p_parent_dir != $p_dir) &&
543
-            ($p_parent_dir != '') &&
544
-            (!$this->_dirCheck($p_parent_dir)))
545
-             return false;
546
-
547
-        if (!@mkdir($p_dir, PRADO_CHMOD)) {
548
-            $this->_error("Unable to create directory '$p_dir'");
549
-            return false;
550
-        }
551
-        chmod($p_dir,PRADO_CHMOD);
552
-
553
-        return true;
554
-    }
555
-
556
-    protected function _translateWinPath($p_path, $p_remove_disk_letter=true)
557
-    {
558
-      if (substr(PHP_OS, 0, 3) == 'WIN') {
559
-          // ----- Look for potential disk letter
560
-          if (   ($p_remove_disk_letter)
561
-		      && (($v_position = strpos($p_path, ':')) != false)) {
562
-              $p_path = substr($p_path, $v_position+1);
563
-          }
564
-          // ----- Change potential windows directory separator
565
-          if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) {
566
-              $p_path = strtr($p_path, '\\', '/');
567
-          }
568
-      }
569
-      return $p_path;
570
-    }
512
+	  if ($v_listing || $v_extract_file || $v_extraction_stopped) {
513
+		// ----- Log extracted files
514
+		if (($v_file_dir = dirname($v_header['filename']))
515
+			== $v_header['filename'])
516
+		  $v_file_dir = '';
517
+		if ((substr($v_header['filename'], 0, 1) == '/') && ($v_file_dir == ''))
518
+		  $v_file_dir = '/';
519
+
520
+		$p_list_detail[$v_nb++] = $v_header;
521
+	  }
522
+	}
523
+
524
+		return true;
525
+	}
526
+
527
+	/**
528
+	 * Check if a directory exists and create it (including parent
529
+	 * dirs) if not.
530
+	 *
531
+	 * @param string $p_dir directory to check
532
+	 *
533
+	 * @return bool true if the directory exists or was created
534
+	 */
535
+	protected function _dirCheck($p_dir)
536
+	{
537
+		if ((@is_dir($p_dir)) || ($p_dir == ''))
538
+			return true;
539
+
540
+		$p_parent_dir = dirname($p_dir);
541
+
542
+		if (($p_parent_dir != $p_dir) &&
543
+			($p_parent_dir != '') &&
544
+			(!$this->_dirCheck($p_parent_dir)))
545
+			 return false;
546
+
547
+		if (!@mkdir($p_dir, PRADO_CHMOD)) {
548
+			$this->_error("Unable to create directory '$p_dir'");
549
+			return false;
550
+		}
551
+		chmod($p_dir,PRADO_CHMOD);
552
+
553
+		return true;
554
+	}
555
+
556
+	protected function _translateWinPath($p_path, $p_remove_disk_letter=true)
557
+	{
558
+	  if (substr(PHP_OS, 0, 3) == 'WIN') {
559
+		  // ----- Look for potential disk letter
560
+		  if (   ($p_remove_disk_letter)
561
+			  && (($v_position = strpos($p_path, ':')) != false)) {
562
+			  $p_path = substr($p_path, $v_position+1);
563
+		  }
564
+		  // ----- Change potential windows directory separator
565
+		  if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) {
566
+			  $p_path = strtr($p_path, '\\', '/');
567
+		  }
568
+	  }
569
+	  return $p_path;
570
+	}
571 571
 }
Please login to merge, or discard this patch.
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -38,17 +38,17 @@  discard block
 block discarded – undo
38 38
     /**
39 39
     * @var string Name of the Tar
40 40
     */
41
-    private $_tarname='';
41
+    private $_tarname = '';
42 42
 
43 43
     /**
44 44
     * @var file descriptor
45 45
     */
46
-    private $_file=0;
46
+    private $_file = 0;
47 47
 
48 48
     /**
49 49
     * @var string Local Tar name of a remote Tar (http:// or ftp://)
50 50
     */
51
-    private $_temp_tarname='';
51
+    private $_temp_tarname = '';
52 52
 
53 53
     /**
54 54
     * Archive_Tar Class constructor. This flavour of the constructor only
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
             @unlink($this->_temp_tarname);
72 72
     }
73 73
 
74
-    public function extract($p_path='')
74
+    public function extract($p_path = '')
75 75
     {
76 76
         return $this->extractModify($p_path, '');
77 77
     }
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 		throw new Exception($p_message);
128 128
     }
129 129
 
130
-    private function _isArchive($p_filename=null)
130
+    private function _isArchive($p_filename = null)
131 131
     {
132 132
         if ($p_filename == null) {
133 133
             $p_filename = $this->_tarname;
@@ -142,16 +142,16 @@  discard block
 block discarded – undo
142 142
 
143 143
           // ----- Look if a local copy need to be done
144 144
           if ($this->_temp_tarname == '') {
145
-              $this->_temp_tarname = uniqid('tar').'.tmp';
145
+              $this->_temp_tarname = uniqid('tar') . '.tmp';
146 146
               if (!$v_file_from = @fopen($this->_tarname, 'rb')) {
147 147
                 $this->_error('Unable to open in read mode \''
148
-				              .$this->_tarname.'\'');
148
+				              .$this->_tarname . '\'');
149 149
                 $this->_temp_tarname = '';
150 150
                 return false;
151 151
               }
152 152
               if (!$v_file_to = @fopen($this->_temp_tarname, 'wb')) {
153 153
                 $this->_error('Unable to open in write mode \''
154
-				              .$this->_temp_tarname.'\'');
154
+				              .$this->_temp_tarname . '\'');
155 155
                 $this->_temp_tarname = '';
156 156
                 return false;
157 157
               }
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 		$this->_file = @fopen($v_filename, "rb");
172 172
 
173 173
         if ($this->_file == 0) {
174
-            $this->_error('Unable to open in read mode \''.$v_filename.'\'');
174
+            $this->_error('Unable to open in read mode \'' . $v_filename . '\'');
175 175
             return false;
176 176
         }
177 177
 
@@ -224,41 +224,41 @@  discard block
 block discarded – undo
224 224
       return $v_block;
225 225
     }
226 226
 
227
-    private function _jumpBlock($p_len=null)
227
+    private function _jumpBlock($p_len = null)
228 228
     {
229 229
       if (is_resource($this->_file)) {
230 230
           if ($p_len === null)
231 231
               $p_len = 1;
232 232
 
233
-              @fseek($this->_file, @ftell($this->_file)+($p_len*512));
233
+              @fseek($this->_file, @ftell($this->_file) + ($p_len * 512));
234 234
       }
235 235
       return true;
236 236
     }
237 237
 
238 238
     private function _readHeader($v_binary_data, &$v_header)
239 239
     {
240
-        if (strlen($v_binary_data)==0) {
240
+        if (strlen($v_binary_data) == 0) {
241 241
             $v_header['filename'] = '';
242 242
             return true;
243 243
         }
244 244
 
245 245
         if (strlen($v_binary_data) != 512) {
246 246
             $v_header['filename'] = '';
247
-            $this->_error('Invalid block size : '.strlen($v_binary_data));
247
+            $this->_error('Invalid block size : ' . strlen($v_binary_data));
248 248
             return false;
249 249
         }
250 250
 
251 251
         // ----- Calculate the checksum
252 252
         $v_checksum = 0;
253 253
         // ..... First part of the header
254
-        for ($i=0; $i<148; $i++)
255
-            $v_checksum+=ord(substr($v_binary_data,$i,1));
254
+        for ($i = 0; $i < 148; $i++)
255
+            $v_checksum += ord(substr($v_binary_data, $i, 1));
256 256
         // ..... Ignore the checksum value and replace it by ' ' (space)
257
-        for ($i=148; $i<156; $i++)
257
+        for ($i = 148; $i < 156; $i++)
258 258
             $v_checksum += ord(' ');
259 259
         // ..... Last part of the header
260
-        for ($i=156; $i<512; $i++)
261
-           $v_checksum+=ord(substr($v_binary_data,$i,1));
260
+        for ($i = 156; $i < 512; $i++)
261
+           $v_checksum += ord(substr($v_binary_data, $i, 1));
262 262
 
263 263
         $v_data = unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/"
264 264
 		                 ."a8checksum/a1typeflag/a100link/a6magic/a2version/"
@@ -274,9 +274,9 @@  discard block
 block discarded – undo
274 274
             if (($v_checksum == 256) && ($v_header['checksum'] == 0))
275 275
                 return true;
276 276
 
277
-            $this->_error('Invalid checksum for file "'.$v_data['filename']
278
-			              .'" : '.$v_checksum.' calculated, '
279
-						  .$v_header['checksum'].' expected');
277
+            $this->_error('Invalid checksum for file "' . $v_data['filename']
278
+			              .'" : ' . $v_checksum . ' calculated, '
279
+						  .$v_header['checksum'] . ' expected');
280 280
             return false;
281 281
         }
282 282
 
@@ -296,8 +296,8 @@  discard block
 block discarded – undo
296 296
     private function _readLongHeader(&$v_header)
297 297
     {
298 298
       $v_filename = '';
299
-      $n = floor($v_header['size']/512);
300
-      for ($i=0; $i<$n; $i++) {
299
+      $n = floor($v_header['size'] / 512);
300
+      for ($i = 0; $i < $n; $i++) {
301 301
         $v_content = $this->_readBlock();
302 302
         $v_filename .= $v_content;
303 303
       }
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
     protected function _extractList($p_path, &$p_list_detail, $p_mode,
321 321
 	                      $p_file_list, $p_remove_path)
322 322
     {
323
-    $v_result=true;
323
+    $v_result = true;
324 324
     $v_nb = 0;
325 325
     $v_extract_all = true;
326 326
     $v_listing = false;
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
     $p_path = $this->_translateWinPath($p_path, false);
329 329
     if ($p_path == '' || (substr($p_path, 0, 1) != '/'
330 330
 	    && substr($p_path, 0, 3) != "../" && !strpos($p_path, ':'))) {
331
-      $p_path = "./".$p_path;
331
+      $p_path = "./" . $p_path;
332 332
     }
333 333
     $p_remove_path = $this->_translateWinPath($p_remove_path);
334 334
 
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
           $v_listing = true;
352 352
       break;
353 353
       default :
354
-        $this->_error('Invalid extract mode ('.$p_mode.')');
354
+        $this->_error('Invalid extract mode (' . $p_mode . ')');
355 355
         return false;
356 356
     }
357 357
 
@@ -379,7 +379,7 @@  discard block
 block discarded – undo
379 379
         // ----- By default no unzip if the file is not found
380 380
         $v_extract_file = false;
381 381
 
382
-        for ($i=0; $i<sizeof($p_file_list); $i++) {
382
+        for ($i = 0; $i < sizeof($p_file_list); $i++) {
383 383
           // ----- Look if it is a directory
384 384
           if (substr($p_file_list[$i], -1) == '/') {
385 385
             // ----- Look if the directory is in the filename path
@@ -411,28 +411,28 @@  discard block
 block discarded – undo
411 411
 		                                 $p_remove_path_size);
412 412
         if (($p_path != './') && ($p_path != '/')) {
413 413
           while (substr($p_path, -1) == '/')
414
-            $p_path = substr($p_path, 0, strlen($p_path)-1);
414
+            $p_path = substr($p_path, 0, strlen($p_path) - 1);
415 415
 
416 416
           if (substr($v_header['filename'], 0, 1) == '/')
417
-              $v_header['filename'] = $p_path.$v_header['filename'];
417
+              $v_header['filename'] = $p_path . $v_header['filename'];
418 418
           else
419
-            $v_header['filename'] = $p_path.'/'.$v_header['filename'];
419
+            $v_header['filename'] = $p_path . '/' . $v_header['filename'];
420 420
         }
421 421
         if (file_exists($v_header['filename'])) {
422
-          if (   (@is_dir($v_header['filename']))
422
+          if ((@is_dir($v_header['filename']))
423 423
 		      && ($v_header['typeflag'] == '')) {
424
-            $this->_error('File '.$v_header['filename']
424
+            $this->_error('File ' . $v_header['filename']
425 425
 			              .' already exists as a directory');
426 426
             return false;
427 427
           }
428
-          if (   ($this->_isArchive($v_header['filename']))
428
+          if (($this->_isArchive($v_header['filename']))
429 429
 		      && ($v_header['typeflag'] == "5")) {
430
-            $this->_error('Directory '.$v_header['filename']
430
+            $this->_error('Directory ' . $v_header['filename']
431 431
 			              .' already exists as a file');
432 432
             return false;
433 433
           }
434 434
           if (!is_writeable($v_header['filename'])) {
435
-            $this->_error('File '.$v_header['filename']
435
+            $this->_error('File ' . $v_header['filename']
436 436
 			              .' already exists and is write protected');
437 437
             return false;
438 438
           }
@@ -444,9 +444,9 @@  discard block
 block discarded – undo
444 444
         // ----- Check the directory availability and create it if necessary
445 445
         elseif (($v_result
446 446
 		         = $this->_dirCheck(($v_header['typeflag'] == "5"
447
-				                    ?$v_header['filename']
447
+				                    ? $v_header['filename']
448 448
 									:dirname($v_header['filename'])))) != 1) {
449
-            $this->_error('Unable to create path for '.$v_header['filename']);
449
+            $this->_error('Unable to create path for ' . $v_header['filename']);
450 450
             return false;
451 451
         }
452 452
 
@@ -455,19 +455,19 @@  discard block
 block discarded – undo
455 455
             if (!@file_exists($v_header['filename'])) {
456 456
                 if (!@mkdir($v_header['filename'], PRADO_CHMOD)) {
457 457
                     $this->_error('Unable to create directory {'
458
-					              .$v_header['filename'].'}');
458
+					              .$v_header['filename'] . '}');
459 459
                     return false;
460 460
                 }
461 461
                 chmod($v_header['filename'], PRADO_CHMOD);
462 462
             }
463 463
           } else {
464 464
               if (($v_dest_file = @fopen($v_header['filename'], "wb")) == 0) {
465
-                  $this->_error('Error while opening {'.$v_header['filename']
465
+                  $this->_error('Error while opening {' . $v_header['filename']
466 466
 				                .'} in write binary mode');
467 467
                   return false;
468 468
               } else {
469
-                  $n = floor($v_header['size']/512);
470
-                  for ($i=0; $i<$n; $i++) {
469
+                  $n = floor($v_header['size'] / 512);
470
+                  for ($i = 0; $i < $n; $i++) {
471 471
                       $v_content = $this->_readBlock();
472 472
                       fwrite($v_dest_file, $v_content, 512);
473 473
                   }
@@ -487,19 +487,19 @@  discard block
 block discarded – undo
487 487
           // ----- Check the file size
488 488
           clearstatcache();
489 489
           if (filesize($v_header['filename']) != $v_header['size']) {
490
-              $this->_error('Extracted file '.$v_header['filename']
490
+              $this->_error('Extracted file ' . $v_header['filename']
491 491
 			                .' does not have the correct file size \''
492 492
 							.filesize($v_header['filename'])
493
-							.'\' ('.$v_header['size']
493
+							.'\' (' . $v_header['size']
494 494
 							.' expected). Archive may be corrupted.');
495 495
               return false;
496 496
           }
497 497
           }
498 498
         } else {
499
-          $this->_jumpBlock(ceil(($v_header['size']/512)));
499
+          $this->_jumpBlock(ceil(($v_header['size'] / 512)));
500 500
         }
501 501
       } else {
502
-          $this->_jumpBlock(ceil(($v_header['size']/512)));
502
+          $this->_jumpBlock(ceil(($v_header['size'] / 512)));
503 503
       }
504 504
 
505 505
       /* TBC : Seems to be unused ...
@@ -548,21 +548,21 @@  discard block
 block discarded – undo
548 548
             $this->_error("Unable to create directory '$p_dir'");
549 549
             return false;
550 550
         }
551
-        chmod($p_dir,PRADO_CHMOD);
551
+        chmod($p_dir, PRADO_CHMOD);
552 552
 
553 553
         return true;
554 554
     }
555 555
 
556
-    protected function _translateWinPath($p_path, $p_remove_disk_letter=true)
556
+    protected function _translateWinPath($p_path, $p_remove_disk_letter = true)
557 557
     {
558 558
       if (substr(PHP_OS, 0, 3) == 'WIN') {
559 559
           // ----- Look for potential disk letter
560
-          if (   ($p_remove_disk_letter)
560
+          if (($p_remove_disk_letter)
561 561
 		      && (($v_position = strpos($p_path, ':')) != false)) {
562
-              $p_path = substr($p_path, $v_position+1);
562
+              $p_path = substr($p_path, $v_position + 1);
563 563
           }
564 564
           // ----- Change potential windows directory separator
565
-          if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) {
565
+          if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0, 1) == '\\')) {
566 566
               $p_path = strtr($p_path, '\\', '/');
567 567
           }
568 568
       }
Please login to merge, or discard this patch.
Braces   +15 added lines, -10 removed lines patch added patch discarded remove patch
@@ -155,8 +155,9 @@  discard block
 block discarded – undo
155 155
                 $this->_temp_tarname = '';
156 156
                 return false;
157 157
               }
158
-              while ($v_data = @fread($v_file_from, 1024))
159
-                  @fwrite($v_file_to, $v_data);
158
+              while ($v_data = @fread($v_file_from, 1024)) {
159
+                                @fwrite($v_file_to, $v_data);
160
+              }
160 161
               @fclose($v_file_from);
161 162
               @fclose($v_file_to);
162 163
           }
@@ -251,14 +252,17 @@  discard block
 block discarded – undo
251 252
         // ----- Calculate the checksum
252 253
         $v_checksum = 0;
253 254
         // ..... First part of the header
254
-        for ($i=0; $i<148; $i++)
255
-            $v_checksum+=ord(substr($v_binary_data,$i,1));
255
+        for ($i=0; $i<148; $i++) {
256
+                    $v_checksum+=ord(substr($v_binary_data,$i,1));
257
+        }
256 258
         // ..... Ignore the checksum value and replace it by ' ' (space)
257
-        for ($i=148; $i<156; $i++)
258
-            $v_checksum += ord(' ');
259
+        for ($i=148; $i<156; $i++) {
260
+                    $v_checksum += ord(' ');
261
+        }
259 262
         // ..... Last part of the header
260
-        for ($i=156; $i<512; $i++)
261
-           $v_checksum+=ord(substr($v_binary_data,$i,1));
263
+        for ($i=156; $i<512; $i++) {
264
+                   $v_checksum+=ord(substr($v_binary_data,$i,1));
265
+        }
262 266
 
263 267
         $v_data = unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/"
264 268
 		                 ."a8checksum/a1typeflag/a100link/a6magic/a2version/"
@@ -410,8 +414,9 @@  discard block
 block discarded – undo
410 414
           $v_header['filename'] = substr($v_header['filename'],
411 415
 		                                 $p_remove_path_size);
412 416
         if (($p_path != './') && ($p_path != '/')) {
413
-          while (substr($p_path, -1) == '/')
414
-            $p_path = substr($p_path, 0, strlen($p_path)-1);
417
+          while (substr($p_path, -1) == '/') {
418
+                      $p_path = substr($p_path, 0, strlen($p_path)-1);
419
+          }
415 420
 
416 421
           if (substr($v_header['filename'], 0, 1) == '/')
417 422
               $v_header['filename'] = $p_path.$v_header['filename'];
Please login to merge, or discard this patch.
framework/IO/TTextWriter.php 2 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -38,6 +38,7 @@
 block discarded – undo
38 38
 	/**
39 39
 	 * Writes a string.
40 40
 	 * @param string string to be written
41
+	 * @param string $str
41 42
 	 */
42 43
 	public function write($str)
43 44
 	{
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
  */
23 23
 class TTextWriter extends TComponent implements ITextWriter
24 24
 {
25
-	private $_str='';
25
+	private $_str = '';
26 26
 
27 27
 	/**
28 28
 	 * Flushes the content that has been written.
@@ -30,8 +30,8 @@  discard block
 block discarded – undo
30 30
 	 */
31 31
 	public function flush()
32 32
 	{
33
-		$str=$this->_str;
34
-		$this->_str='';
33
+		$str = $this->_str;
34
+		$this->_str = '';
35 35
 		return $str;
36 36
 	}
37 37
 
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	 */
42 42
 	public function write($str)
43 43
 	{
44
-		$this->_str.=$str;
44
+		$this->_str .= $str;
45 45
 	}
46 46
 
47 47
 	/**
@@ -49,9 +49,9 @@  discard block
 block discarded – undo
49 49
 	 * @param string content to be written
50 50
 	 * @see write
51 51
 	 */
52
-	public function writeLine($str='')
52
+	public function writeLine($str = '')
53 53
 	{
54
-		$this->write($str."\n");
54
+		$this->write($str . "\n");
55 55
 	}
56 56
 }
57 57
 
Please login to merge, or discard this patch.