Completed
Push — autoload ( 7f2c9b...4808d1 )
by Fabio
42:25 queued 32:40
created
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   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -43,13 +43,13 @@  discard block
 block discarded – undo
43 43
 	 * Message data filename extension.
44 44
 	 * @var string
45 45
 	 */
46
-	protected $dataExt = '.xml';
46
+	protected $dataExt='.xml';
47 47
 
48 48
 	/**
49 49
 	 * Separator between culture name and source.
50 50
 	 * @var string
51 51
 	 */
52
-	protected $dataSeparator = '.';
52
+	protected $dataSeparator='.';
53 53
 
54 54
 	/**
55 55
 	 * Constructor.
@@ -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,20 +69,20 @@  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
 
76
-		$translationUnit = $XML->xpath('//trans-unit');
76
+		$translationUnit=$XML->xpath('//trans-unit');
77 77
 
78
-		$translations = array();
78
+		$translations=array();
79 79
 
80 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;
@@ -127,28 +127,28 @@  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;
132
-		$catalogues = array($source);
133
-		$variant = null;
130
+		$variants=explode('_', $this->culture);
131
+		$source=$catalogue.$this->dataExt;
132
+		$catalogues=array($source);
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 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
-		$byDir = $this->getCatalogueByDir($catalogue);
145
-		$catalogues = array_merge($byDir,array_reverse($catalogues));
146
-		$files = array();
144
+		$byDir=$this->getCatalogueByDir($catalogue);
145
+		$catalogues=array_merge($byDir, array_reverse($catalogues));
146
+		$files=array();
147 147
 
148 148
 		foreach($catalogues as $file)
149 149
 		{
150
-			$files[] = $file;
151
-			$files[] = preg_replace('/\.xml$/', '.xlf', $file);
150
+			$files[]=$file;
151
+			$files[]=preg_replace('/\.xml$/', '.xlf', $file);
152 152
 		}
153 153
 
154 154
 		return $files;
@@ -163,16 +163,16 @@  discard block
 block discarded – undo
163 163
 	 */
164 164
 	private function getCatalogueByDir($catalogue)
165 165
 	{
166
-		$variants = explode('_',$this->culture);
167
-		$catalogues = array();
168
-		$variant = null;
166
+		$variants=explode('_', $this->culture);
167
+		$catalogues=array();
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 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,38 +196,38 @@  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;
202
-		$files = scandir($dir);
203
-		$catalogue = array();
201
+		$dir=$dir ? $dir : $this->source;
202
+		$files=scandir($dir);
203
+		$catalogue=array();
204 204
 
205 205
 		foreach($files as $file)
206 206
 		{
207
-			if(is_dir($dir.'/'.$file) && preg_match('/^[a-z]{2}(_[A-Z]{2,3})?$/',$file)) {
208
-				$catalogue = array_merge(
207
+			if(is_dir($dir.'/'.$file) && preg_match('/^[a-z]{2}(_[A-Z]{2,3})?$/', $file)) {
208
+				$catalogue=array_merge(
209 209
 					$catalogue,
210 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);
219
-				$culture = $variant;
220
-				$cat = $name;
217
+				$name=substr($file, 0, $pos);
218
+				$dot=strrpos($name, $this->dataSeparator);
219
+				$culture=$variant;
220
+				$cat=$name;
221 221
 
222 222
 				if(is_int($dot))
223 223
 				{
224
-					$culture = substr($name, $dot+1, strlen($name));
225
-					$cat = substr($name, 0, $dot);
224
+					$culture=substr($name, $dot + 1, strlen($name));
225
+					$cat=substr($name, 0, $dot);
226 226
 				}
227 227
 
228
-				$details[0] = $cat;
229
-				$details[1] = $culture;
230
-				$catalogue[] = $details;
228
+				$details[0]=$cat;
229
+				$details[1]=$culture;
230
+				$catalogue[]=$details;
231 231
 			}
232 232
 		}
233 233
 		sort($catalogue);
@@ -244,13 +244,13 @@  discard block
 block discarded – undo
244 244
 	 */
245 245
 	private function getVariants($catalogue='messages')
246 246
 	{
247
-		if($catalogue === null) {
248
-			$catalogue = 'messages';
247
+		if($catalogue===null) {
248
+			$catalogue='messages';
249 249
 		}
250 250
 
251 251
 		foreach($this->getCatalogueList($catalogue) as $variant)
252 252
 		{
253
-			$file = $this->getSource($variant);
253
+			$file=$this->getSource($variant);
254 254
 			if(is_file($file)) {
255 255
 				return array($variant, $file);
256 256
 			}
@@ -267,48 +267,48 @@  discard block
 block discarded – undo
267 267
 	 */
268 268
 	public function save($catalogue='messages')
269 269
 	{
270
-		$messages = $this->untranslated;
270
+		$messages=$this->untranslated;
271 271
 		if(count($messages) <= 0) {
272 272
 			return false;
273 273
 		}
274 274
 
275
-		$variants = $this->getVariants($catalogue);
275
+		$variants=$this->getVariants($catalogue);
276 276
 
277 277
 		if($variants) {
278
-			list($variant, $filename) = $variants;
278
+			list($variant, $filename)=$variants;
279 279
 		} else {
280
-			list($variant, $filename) = $this->createMessageTemplate($catalogue);
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
 
287 287
 		//create a new dom, import the existing xml
288
-		$dom = new DOMDocument();
288
+		$dom=new DOMDocument();
289 289
 		$dom->load($filename);
290 290
 
291 291
 		//find the body element
292
-		$xpath = new DomXPath($dom);
293
-    	$body = $xpath->query('//body')->item(0);
292
+		$xpath=new DomXPath($dom);
293
+    	$body=$xpath->query('//body')->item(0);
294 294
 
295
-		$lastNodes = $xpath->query('//trans-unit[last()]');
295
+		$lastNodes=$xpath->query('//trans-unit[last()]');
296 296
 		if(($last=$lastNodes->item(0))!==null) {
297
-			$count = (int)$last->getAttribute('id');
297
+			$count=(int) $last->getAttribute('id');
298 298
 		} else {
299
-			$count = 0;
299
+			$count=0;
300 300
 		}
301 301
 
302 302
 		//for each message add it to the XML file using DOM
303 303
 		foreach($messages as $message)
304 304
 		{
305
-			$unit = $dom->createElement('trans-unit');
306
-			$unit->setAttribute('id',++$count);
305
+			$unit=$dom->createElement('trans-unit');
306
+			$unit->setAttribute('id', ++$count);
307 307
 
308
-			$source = $dom->createElement('source');
308
+			$source=$dom->createElement('source');
309 309
 			$source->appendChild($dom->createCDATASection($message));
310 310
 
311
-			$target = $dom->createElement('target');
311
+			$target=$dom->createElement('target');
312 312
 			$target->appendChild($dom->createCDATASection(''));
313 313
 
314 314
 			$unit->appendChild($dom->createTextNode("\n"));
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
 		}
324 324
 
325 325
 
326
-		$fileNode = $xpath->query('//file')->item(0);
326
+		$fileNode=$xpath->query('//file')->item(0);
327 327
 		$fileNode->setAttribute('date', @date('Y-m-d\TH:i:s\Z'));
328 328
 
329 329
 		//save it and clear the cache for this variant
@@ -345,68 +345,68 @@  discard block
 block discarded – undo
345 345
 	 */
346 346
 	public function update($text, $target, $comments, $catalogue='messages')
347 347
 	{
348
-		$variants = $this->getVariants($catalogue);
348
+		$variants=$this->getVariants($catalogue);
349 349
 
350 350
 		if($variants) {
351
-			list($variant, $filename) = $variants;
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
 
360 360
 		//create a new dom, import the existing xml
361
-		$dom = DOMDocument::load($filename);
361
+		$dom=DOMDocument::load($filename);
362 362
 
363 363
 		//find the body element
364
-		$xpath = new DomXPath($dom);
365
-		$units = $xpath->query('//trans-unit');
364
+		$xpath=new DomXPath($dom);
365
+		$units=$xpath->query('//trans-unit');
366 366
 
367 367
 		//for each of the existin units
368 368
 		foreach($units as $unit)
369 369
 		{
370
-			$found = false;
371
-			$targetted = false;
372
-			$commented = false;
370
+			$found=false;
371
+			$targetted=false;
372
+			$commented=false;
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 376
 			foreach($unit->childNodes as $node)
377 377
 			{
378 378
 				//source node
379
-				if($node->nodeName == 'source' && $node->firstChild->wholeText == $text) {
380
-					$found = true;
379
+				if($node->nodeName=='source' && $node->firstChild->wholeText==$text) {
380
+					$found=true;
381 381
 				}
382 382
 
383 383
 				//found source, get the target and notes
384 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
-						$node->nodeValue = $target;
390
-						$targetted = true;
389
+						$node->nodeValue=$target;
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
-						$node->nodeValue = $comments;
397
-						$commented = true;
396
+						$node->nodeValue=$comments;
397
+						$commented=true;
398 398
 					}
399 399
 				}
400 400
 			}
401 401
 
402 402
 			//append a target
403 403
 			if($found && !$targetted) {
404
-				$unit->appendChild($dom->createElement('target',$target));
404
+				$unit->appendChild($dom->createElement('target', $target));
405 405
 			}
406 406
 
407 407
 			//append a note
408 408
 			if($found && !$commented && !empty($comments)) {
409
-				$unit->appendChild($dom->createElement('note',$comments));
409
+				$unit->appendChild($dom->createElement('note', $comments));
410 410
 			}
411 411
 
412 412
 			//finished searching
@@ -415,10 +415,10 @@  discard block
 block discarded – undo
415 415
 			}
416 416
 		}
417 417
 
418
-		$fileNode = $xpath->query('//file')->item(0);
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 423
 			if(!empty($this->cache)) {
424 424
 				$this->cache->clean($variant, $this->culture);
@@ -438,23 +438,23 @@  discard block
 block discarded – undo
438 438
 	 */
439 439
 	public function delete($message, $catalogue='messages')
440 440
 	{
441
-		$variants = $this->getVariants($catalogue);
441
+		$variants=$this->getVariants($catalogue);
442 442
 		if($variants) {
443
-			list($variant, $filename) = $variants;
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
 
452 452
 		//create a new dom, import the existing xml
453
-		$dom = DOMDocument::load($filename);
453
+		$dom=DOMDocument::load($filename);
454 454
 
455 455
 		//find the body element
456
-		$xpath = new DomXPath($dom);
457
-		$units = $xpath->query('//trans-unit');
456
+		$xpath=new DomXPath($dom);
457
+		$units=$xpath->query('//trans-unit');
458 458
 
459 459
 		//for each of the existin units
460 460
 		foreach($units as $unit)
@@ -464,14 +464,14 @@  discard block
 block discarded – undo
464 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
-					$fileNode = $xpath->query('//file')->item(0);
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)) {
474
+					if(false!==$dom->save($filename)) {
475 475
 						if(!empty($this->cache)) {
476 476
 							$this->cache->clean($variant, $this->culture);
477 477
 						}
@@ -488,18 +488,18 @@  discard block
 block discarded – undo
488 488
 
489 489
 	protected function createMessageTemplate($catalogue)
490 490
 	{
491
-		if($catalogue === null) {
492
-			$catalogue = 'messages';
491
+		if($catalogue===null) {
492
+			$catalogue='messages';
493 493
 		}
494 494
 		
495
-		$variants = $this->getCatalogueList($catalogue);
496
-		$variant = array_shift($variants);
497
-		$file = $this->getSource($variant);
498
-		$dir = dirname($file);
495
+		$variants=$this->getCatalogueList($catalogue);
496
+		$variant=array_shift($variants);
497
+		$file=$this->getSource($variant);
498
+		$dir=dirname($file);
499 499
 
500 500
 		if(!is_dir($dir)) {
501 501
 			@mkdir($dir);
502
-			@chmod($dir,PRADO_CHMOD);
502
+			@chmod($dir, PRADO_CHMOD);
503 503
 		}
504 504
 
505 505
 		if(!is_dir($dir)) {
@@ -514,8 +514,8 @@  discard block
 block discarded – undo
514 514
 
515 515
 	protected function getTemplate($catalogue)
516 516
 	{
517
-		$date = @date('c');
518
-		$xml = <<<EOD
517
+		$date=@date('c');
518
+		$xml=<<<EOD
519 519
 <?xml version="1.0" encoding="UTF-8"?>
520 520
 <xliff version="1.0">
521 521
  <file source-language="EN" target-language="{$this->culture}" datatype="plaintext" original="$catalogue" date="$date" product-name="$catalogue">
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.
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.
Spacing   +95 added lines, -95 removed lines patch added patch discarded remove patch
@@ -52,24 +52,24 @@  discard block
 block discarded – undo
52 52
 	 * ICU number formatting data.
53 53
 	 * @var array
54 54
 	 */
55
-	private $data = array();
55
+	private $data=array();
56 56
 
57 57
 	/**
58 58
 	 * A list of properties that are accessable/writable.
59 59
 	 * @var array
60 60
 	 */
61
-	protected $properties = array();
61
+	protected $properties=array();
62 62
 
63 63
 	/**
64 64
 	 * The number pattern.
65 65
 	 * @var array
66 66
 	 */
67
-	protected $pattern = array();
67
+	protected $pattern=array();
68 68
 
69
-	const DECIMAL = 0;
70
-	const CURRENCY = 1;
71
-	const PERCENTAGE = 2;
72
-	const SCIENTIFIC = 3;
69
+	const DECIMAL=0;
70
+	const CURRENCY=1;
71
+	const PERCENTAGE=2;
72
+	const SCIENTIFIC=3;
73 73
 
74 74
 	/**
75 75
 	 * Allow functions that begins with 'set' to be called directly
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 	 */
79 79
 	public function __get($name)
80 80
 	{
81
-		$getProperty = 'get'.$name;
81
+		$getProperty='get'.$name;
82 82
 		if(in_array($getProperty, $this->properties))
83 83
 			return $this->$getProperty();
84 84
 		else
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 	 */
92 92
 	public function __set($name, $value)
93 93
 	{
94
-		$setProperty = 'set'.$name;
94
+		$setProperty='set'.$name;
95 95
 		if(in_array($setProperty, $this->properties))
96 96
 			$this->$setProperty($value);
97 97
 		else
@@ -109,12 +109,12 @@  discard block
 block discarded – undo
109 109
 	 */
110 110
 	public function __construct($data=array(), $type=NumberFormatInfo::DECIMAL)
111 111
 	{
112
-		$this->properties = get_class_methods($this);
112
+		$this->properties=get_class_methods($this);
113 113
 
114 114
 		if(empty($data))
115 115
 			throw new Exception('Please provide the ICU data to initialize.');
116 116
 
117
-		$this->data = $data;
117
+		$this->data=$data;
118 118
 
119 119
 		$this->setPattern($type);
120 120
 	}
@@ -128,16 +128,16 @@  discard block
 block discarded – undo
128 128
 	public function setPattern($type=NumberFormatInfo::DECIMAL)
129 129
 	{
130 130
 		if(is_int($type))
131
-			$this->pattern =
131
+			$this->pattern=
132 132
 				$this->parsePattern($this->data['NumberPatterns'][$type]);
133 133
 		else
134
-			$this->pattern = $this->parsePattern($type);
134
+			$this->pattern=$this->parsePattern($type);
135 135
 
136
-		$this->pattern['negInfty'] =
136
+		$this->pattern['negInfty']=
137 137
 			$this->data['NumberElements'][6].
138 138
 			$this->data['NumberElements'][9];
139 139
 
140
-		$this->pattern['posInfty'] =
140
+		$this->pattern['posInfty']=
141 141
 			$this->data['NumberElements'][11].
142 142
 			$this->data['NumberElements'][9];
143 143
 	}
@@ -155,10 +155,10 @@  discard block
 block discarded – undo
155 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
-            $culture = CultureInfo::getInvariantCulture();
161
-            $invariant = $culture->NumberFormat;
160
+            $culture=CultureInfo::getInvariantCulture();
161
+            $invariant=$culture->NumberFormat;
162 162
             $invariant->setPattern($type);
163 163
         }
164 164
 		return $invariant;
@@ -179,23 +179,23 @@  discard block
 block discarded – undo
179 179
     public static function getInstance($culture=null,
180 180
     								   $type=NumberFormatInfo::DECIMAL)
181 181
     {
182
-   		if ($culture instanceof CultureInfo)
182
+   		if($culture instanceof CultureInfo)
183 183
    		{
184
-            $formatInfo = $culture->NumberFormat;
184
+            $formatInfo=$culture->NumberFormat;
185 185
             $formatInfo->setPattern($type);
186 186
             return $formatInfo;
187 187
    		}
188 188
        	else if(is_string($culture))
189 189
        	{
190
-       		$cultureInfo = new CultureInfo($culture);
191
-       		$formatInfo = $cultureInfo->NumberFormat;
190
+       		$cultureInfo=new CultureInfo($culture);
191
+       		$formatInfo=$cultureInfo->NumberFormat;
192 192
        		$formatInfo->setPattern($type);
193 193
        		return $formatInfo;
194 194
        	}
195 195
        	else
196 196
        	{
197
-            $cultureInfo = new CultureInfo();
198
-       		$formatInfo = $cultureInfo->NumberFormat;
197
+            $cultureInfo=new CultureInfo();
198
+       		$formatInfo=$cultureInfo->NumberFormat;
199 199
        		$formatInfo->setPattern($type);
200 200
        		return $formatInfo;
201 201
        	}
@@ -241,67 +241,67 @@  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
-		$negative = null;
246
+		$negative=null;
247 247
 		if(count($pattern) > 1)
248
-			$negative = $pattern[1];
249
-		$pattern = $pattern[0];
248
+			$negative=$pattern[1];
249
+		$pattern=$pattern[0];
250 250
 
251
-		$comma = ',';
252
-		$dot = '.';
253
-		$digit = '0';
254
-		$hash = '#';
251
+		$comma=',';
252
+		$dot='.';
253
+		$digit='0';
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
-		$groupPos2 = false;
261
-		$groupSize1 = false;
262
-		$groupSize2 = false;
263
-		$decimalPoints = is_int($decimalPos)?-1:false;
260
+		$groupPos2=false;
261
+		$groupSize1=false;
262
+		$groupSize2=false;
263
+		$decimalPoints=is_int($decimalPos) ?-1 : false;
264 264
 
265
-		$info['negPref'] = $this->data['NumberElements'][6];
266
-		$info['negPost'] = '';
265
+		$info['negPref']=$this->data['NumberElements'][6];
266
+		$info['negPost']='';
267 267
 
268
-		$info['negative'] = $negative;
269
-		$info['positive'] = $pattern;
268
+		$info['negative']=$negative;
269
+		$info['positive']=$pattern;
270 270
 
271 271
 		//find the negative prefix and postfix
272 272
 		if($negative)
273 273
 		{
274
-			$prefixPostfix = $this->getPrePostfix($negative);
275
-			$info['negPref'] = $prefixPostfix[0];
276
-			$info['negPost'] = $prefixPostfix[1];
274
+			$prefixPostfix=$this->getPrePostfix($negative);
275
+			$info['negPref']=$prefixPostfix[0];
276
+			$info['negPost']=$prefixPostfix[1];
277 277
 		}
278 278
 
279
-		$posfix = $this->getPrePostfix($pattern);
280
-		$info['posPref'] = $posfix[0];
281
-		$info['posPost'] = $posfix[1];
279
+		$posfix=$this->getPrePostfix($pattern);
280
+		$info['posPref']=$posfix[0];
281
+		$info['posPost']=$posfix[1];
282 282
 
283 283
 		//var_dump($pattern);
284 284
 		//var_dump($decimalPos);
285 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 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
-						$groupSize1 = $i - $groupPos1;
304
+						$groupSize1=$i - $groupPos1;
305 305
 						break;
306 306
 					}
307 307
 				}
@@ -309,36 +309,36 @@  discard block
 block discarded – undo
309 309
 
310 310
 			//get the second group size
311 311
 			if(is_int($groupPos2))
312
-				$groupSize2 = $groupPos1 - $groupPos2-1;
312
+				$groupSize2=$groupPos1 - $groupPos2 - 1;
313 313
 		}
314 314
 
315 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
-					$decimalPoints = $i - $decimalPos;
322
+					$decimalPoints=$i - $decimalPos;
323 323
 					break;
324 324
 				}
325 325
 			}
326 326
 		}
327 327
 
328 328
 		if(is_int($decimalPos))
329
-			$digitPattern = substr($pattern,0,$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
-		$info['groupPos1'] = $groupPos1;
336
-		$info['groupSize1'] = $groupSize1;
337
-		$info['groupPos2'] = $groupPos2;
338
-		$info['groupSize2'] = $groupSize2;
339
-		$info['decimalPos'] = $decimalPos;
340
-		$info['decimalPoints'] = $decimalPoints;
341
-		$info['digitSize'] = strlen($digitPattern);
335
+		$info['groupPos1']=$groupPos1;
336
+		$info['groupSize1']=$groupSize1;
337
+		$info['groupPos2']=$groupPos2;
338
+		$info['groupSize2']=$groupSize2;
339
+		$info['decimalPos']=$decimalPos;
340
+		$info['decimalPoints']=$decimalPoints;
341
+		$info['digitSize']=strlen($digitPattern);
342 342
 		return $info;
343 343
 	}
344 344
 
@@ -349,9 +349,9 @@  discard block
 block discarded – undo
349 349
 	 */
350 350
 	protected function getPrePostfix($pattern)
351 351
 	{
352
-		$regexp = '/[#,\.0]+/';
353
-		$result = preg_split($regexp, $pattern);
354
-		return array($result[0],$result[1]);
352
+		$regexp='/[#,\.0]+/';
353
+		$result=preg_split($regexp, $pattern);
354
+		return array($result[0], $result[1]);
355 355
 	}
356 356
 
357 357
 
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
      */
371 371
     function setDecimalDigits($value)
372 372
     {
373
-    	return $this->pattern['decimalPoints'] = $value;
373
+    	return $this->pattern['decimalPoints']=$value;
374 374
     }
375 375
 
376 376
     function getDigitSize()
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
 
381 381
     function setDigitSize($value)
382 382
     {
383
-    	$this->pattern['digitSize'] = $value;
383
+    	$this->pattern['digitSize']=$value;
384 384
     }
385 385
 
386 386
     /**
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
      */
399 399
     function setDecimalSeparator($value)
400 400
     {
401
-    	return $this->data['NumberElements'][0] = $value;
401
+    	return $this->data['NumberElements'][0]=$value;
402 402
     }
403 403
 
404 404
     /**
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
      */
419 419
     function setGroupSeparator($value)
420 420
     {
421
-    	return $this->data['NumberElements'][1] = $value;
421
+    	return $this->data['NumberElements'][1]=$value;
422 422
     }
423 423
 
424 424
     /**
@@ -430,8 +430,8 @@  discard block
 block discarded – undo
430 430
      */
431 431
     function getGroupSizes()
432 432
     {
433
-    	$group1 = $this->pattern['groupSize1'];
434
-    	$group2 = $this->pattern['groupSize2'];
433
+    	$group1=$this->pattern['groupSize1'];
434
+    	$group2=$this->pattern['groupSize2'];
435 435
 
436 436
     	return array($group1, $group2);
437 437
     }
@@ -445,8 +445,8 @@  discard block
 block discarded – undo
445 445
      */
446 446
     function setGroupSizes($groupSize)
447 447
     {
448
-   		$this->pattern['groupSize1'] = $groupSize[0];
449
-   		$this->pattern['groupSize2'] = $groupSize[1];
448
+   		$this->pattern['groupSize1']=$groupSize[0];
449
+   		$this->pattern['groupSize2']=$groupSize[1];
450 450
     }
451 451
 
452 452
     /**
@@ -457,8 +457,8 @@  discard block
 block discarded – undo
457 457
      */
458 458
     function getNegativePattern()
459 459
     {
460
-    	$prefix = $this->pattern['negPref'];
461
-    	$postfix = $this->pattern['negPost'];
460
+    	$prefix=$this->pattern['negPref'];
461
+    	$postfix=$this->pattern['negPost'];
462 462
     	return array($prefix, $postfix);
463 463
     }
464 464
 
@@ -470,8 +470,8 @@  discard block
 block discarded – undo
470 470
      */
471 471
     function setNegativePattern($pattern)
472 472
     {
473
-    	$this->pattern['negPref'] = $pattern[0];
474
-    	$this->pattern['negPost'] = $pattern[1];
473
+    	$this->pattern['negPref']=$pattern[0];
474
+    	$this->pattern['negPost']=$pattern[1];
475 475
     }
476 476
 
477 477
     /**
@@ -482,8 +482,8 @@  discard block
 block discarded – undo
482 482
      */
483 483
     function getPositivePattern()
484 484
     {
485
-    	$prefix = $this->pattern['posPref'];
486
-    	$postfix = $this->pattern['posPost'];
485
+    	$prefix=$this->pattern['posPref'];
486
+    	$postfix=$this->pattern['posPost'];
487 487
     	return array($prefix, $postfix);
488 488
     }
489 489
 
@@ -495,8 +495,8 @@  discard block
 block discarded – undo
495 495
      */
496 496
     function setPositivePattern($pattern)
497 497
     {
498
-    	$this->pattern['posPref'] = $pattern[0];
499
-    	$this->pattern['posPost'] = $pattern[1];
498
+    	$this->pattern['posPref']=$pattern[0];
499
+    	$this->pattern['posPost']=$pattern[1];
500 500
     }
501 501
 
502 502
     /**
@@ -518,7 +518,7 @@  discard block
 block discarded – undo
518 518
      */
519 519
     function setCurrencySymbol($symbol)
520 520
     {
521
-    	$this->pattern['symbol'] = $symbol;
521
+    	$this->pattern['symbol']=$symbol;
522 522
     }
523 523
 
524 524
     /**
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
      */
537 537
     function setNegativeInfinitySymbol($value)
538 538
     {
539
-		$this->pattern['negInfty'] = $value;
539
+		$this->pattern['negInfty']=$value;
540 540
     }
541 541
 
542 542
     /**
@@ -554,7 +554,7 @@  discard block
 block discarded – undo
554 554
      */
555 555
     function setPositiveInfinitySymbol($value)
556 556
     {
557
-		$this->pattern['posInfty'] = $value;
557
+		$this->pattern['posInfty']=$value;
558 558
     }
559 559
 
560 560
     /**
@@ -572,7 +572,7 @@  discard block
 block discarded – undo
572 572
      */
573 573
     function setNegativeSign($value)
574 574
     {
575
-    	$this->data['NumberElements'][6] = $value;
575
+    	$this->data['NumberElements'][6]=$value;
576 576
     }
577 577
 
578 578
     /**
@@ -590,7 +590,7 @@  discard block
 block discarded – undo
590 590
      */
591 591
     function setPositiveSign($value)
592 592
     {
593
-    	$this->data['NumberElements'][11] = $value;
593
+    	$this->data['NumberElements'][11]=$value;
594 594
     }
595 595
 
596 596
     /**
@@ -608,7 +608,7 @@  discard block
 block discarded – undo
608 608
      */
609 609
     function setNaNSymbol($value)
610 610
     {
611
-    	$this->data['NumberElements'][10] = $value;
611
+    	$this->data['NumberElements'][10]=$value;
612 612
     }
613 613
 
614 614
     /**
@@ -626,7 +626,7 @@  discard block
 block discarded – undo
626 626
      */
627 627
     function setPercentSymbol($value)
628 628
     {
629
-    	$this->data['NumberElements'][3] = $value;
629
+    	$this->data['NumberElements'][3]=$value;
630 630
     }
631 631
 
632 632
     /**
@@ -644,7 +644,7 @@  discard block
 block discarded – undo
644 644
      */
645 645
     function setPerMilleSymbol($value)
646 646
     {
647
-    	$this->data['NumberElements'][8] = $value;
647
+    	$this->data['NumberElements'][8]=$value;
648 648
     }
649 649
 }
650 650
 
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 __construct($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 __construct($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   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
     *
55 55
     * @var string $_cacheDir
56 56
     */
57
-    protected $_cacheDir = '/tmp/';
57
+    protected $_cacheDir='/tmp/';
58 58
 
59 59
     /**
60 60
     * Enable / disable caching
@@ -63,14 +63,14 @@  discard block
 block discarded – undo
63 63
     *
64 64
     * @var boolean $_caching
65 65
     */
66
-    protected $_caching = true;
66
+    protected $_caching=true;
67 67
 
68 68
     /**
69 69
     * Cache lifetime (in seconds)
70 70
     *
71 71
     * @var int $_lifeTime
72 72
     */
73
-    protected $_lifeTime = 3600;
73
+    protected $_lifeTime=3600;
74 74
 
75 75
     /**
76 76
     * Enable / disable fileLocking
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
     *
80 80
     * @var boolean $_fileLocking
81 81
     */
82
-    protected $_fileLocking = true;
82
+    protected $_fileLocking=true;
83 83
 
84 84
     /**
85 85
     * Timestamp of the last valid cache
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
     *
106 106
     * @var boolean $_writeControl
107 107
     */
108
-    protected $_writeControl = true;
108
+    protected $_writeControl=true;
109 109
 
110 110
     /**
111 111
     * Enable / disable read control
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
     *
116 116
     * @var boolean $_writeControl
117 117
     */
118
-    protected $_readControl = true;
118
+    protected $_readControl=true;
119 119
 
120 120
     /**
121 121
     * Type of read control (only if read control is enabled)
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
     *
129 129
     * @var boolean $_readControlType
130 130
     */
131
-    protected $_readControlType = 'crc32';
131
+    protected $_readControlType='crc32';
132 132
 
133 133
     /**
134 134
     * Current cache id
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
     *
152 152
     * @var boolean $_memoryCaching
153 153
     */
154
-    protected $_memoryCaching = false;
154
+    protected $_memoryCaching=false;
155 155
 
156 156
     /**
157 157
     * Enable / Disable "Only Memory Caching"
@@ -159,28 +159,28 @@  discard block
 block discarded – undo
159 159
     *
160 160
     * @var boolean $_onlyMemoryCaching
161 161
     */
162
-    protected $_onlyMemoryCaching = false;
162
+    protected $_onlyMemoryCaching=false;
163 163
 
164 164
     /**
165 165
     * Memory caching array
166 166
     *
167 167
     * @var array $_memoryCachingArray
168 168
     */
169
-    protected $_memoryCachingArray = array();
169
+    protected $_memoryCachingArray=array();
170 170
 
171 171
     /**
172 172
     * Memory caching counter
173 173
     *
174 174
     * @var int $memoryCachingCounter
175 175
     */
176
-    protected $_memoryCachingCounter = 0;
176
+    protected $_memoryCachingCounter=0;
177 177
 
178 178
     /**
179 179
     * Memory caching limit
180 180
     *
181 181
     * @var int $memoryCachingLimit
182 182
     */
183
-    protected $_memoryCachingLimit = 1000;
183
+    protected $_memoryCachingLimit=1000;
184 184
 
185 185
     /**
186 186
     * File Name protection
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
     *
193 193
     * @var boolean $fileNameProtection
194 194
     */
195
-    protected $_fileNameProtection = true;
195
+    protected $_fileNameProtection=true;
196 196
 
197 197
     /**
198 198
     * Enable / disable automatic serialization
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
     *
203 203
     * @var boolean $_serialize
204 204
     */
205
-    protected $_automaticSerialization = false;
205
+    protected $_automaticSerialization=false;
206 206
 
207 207
     // --- Public methods ---
208 208
 
@@ -228,9 +228,9 @@  discard block
 block discarded – undo
228 228
     * @param array $options options
229 229
     * @access public
230 230
     */
231
-    function __construct($options = array(null))
231
+    function __construct($options=array(null))
232 232
     {
233
-        $availableOptions = array(	'automaticSerialization',
233
+        $availableOptions=array('automaticSerialization',
234 234
         							'fileNameProtection',
235 235
         							'memoryCaching',
236 236
         							'onlyMemoryCaching',
@@ -244,11 +244,11 @@  discard block
 block discarded – undo
244 244
         							'readControlType');
245 245
         foreach($options as $key => $value) {
246 246
             if(in_array($key, $availableOptions)) {
247
-                $property = '_'.$key;
248
-                $this->$property = $value;
247
+                $property='_'.$key;
248
+                $this->$property=$value;
249 249
             }
250 250
         }
251
-        $this->_refreshTime = time() - $this->_lifeTime;
251
+        $this->_refreshTime=time() - $this->_lifeTime;
252 252
 	}
253 253
 
254 254
     /**
@@ -261,41 +261,41 @@  discard block
 block discarded – undo
261 261
     * @return string data of the cache (or false if no cache available)
262 262
     * @access public
263 263
     */
264
-    function get($id, $group = 'default', $doNotTestCacheValidity = false)
264
+    function get($id, $group='default', $doNotTestCacheValidity=false)
265 265
     {
266
-        $this->_id = $id;
267
-        $this->_group = $group;
268
-        $data = false;
269
-        if ($this->_caching) {
266
+        $this->_id=$id;
267
+        $this->_group=$group;
268
+        $data=false;
269
+        if($this->_caching) {
270 270
             $this->_setFileName($id, $group);
271
-            if ($this->_memoryCaching) {
272
-                if (isset($this->_memoryCachingArray[$this->_file])) {
273
-                    if ($this->_automaticSerialization) {
271
+            if($this->_memoryCaching) {
272
+                if(isset($this->_memoryCachingArray[$this->_file])) {
273
+                    if($this->_automaticSerialization) {
274 274
                         return unserialize(
275 275
                         			$this->_memoryCachingArray[$this->_file]);
276 276
                     } else {
277 277
                         return $this->_memoryCachingArray[$this->_file];
278 278
                     }
279 279
                 } else {
280
-                    if ($this->_onlyMemoryCaching) {
280
+                    if($this->_onlyMemoryCaching) {
281 281
                         return false;
282 282
                     }
283 283
                 }
284 284
             }
285
-            if ($doNotTestCacheValidity) {
286
-                if (file_exists($this->_file)) {
287
-                    $data = $this->_read();
285
+            if($doNotTestCacheValidity) {
286
+                if(file_exists($this->_file)) {
287
+                    $data=$this->_read();
288 288
                 }
289 289
             } else {
290
-                if (@filemtime($this->_file) > $this->_refreshTime) {
291
-                    $data = $this->_read();
290
+                if(@filemtime($this->_file) > $this->_refreshTime) {
291
+                    $data=$this->_read();
292 292
                 }
293 293
             }
294
-            if (($data) and ($this->_memoryCaching)) {
294
+            if(($data) and ($this->_memoryCaching)) {
295 295
                 $this->_memoryCacheAdd($this->_file, $data);
296 296
             }
297
-            if ($this->_automaticSerialization && is_string($data)) {
298
-                $data = unserialize($data);
297
+            if($this->_automaticSerialization && is_string($data)) {
298
+                $data=unserialize($data);
299 299
             }
300 300
             return $data;
301 301
         }
@@ -312,24 +312,24 @@  discard block
 block discarded – undo
312 312
     * @return boolean true if no problem
313 313
     * @access public
314 314
     */
315
-    function save($data, $id = null, $group = 'default')
315
+    function save($data, $id=null, $group='default')
316 316
     {
317
-        if ($this->_caching) {
318
-            if ($this->_automaticSerialization) {
319
-                $data = serialize($data);
317
+        if($this->_caching) {
318
+            if($this->_automaticSerialization) {
319
+                $data=serialize($data);
320 320
             }
321
-            if (isset($id)) {
321
+            if(isset($id)) {
322 322
                 $this->_setFileName($id, $group);
323 323
             }
324
-            if ($this->_memoryCaching) {
324
+            if($this->_memoryCaching) {
325 325
                 $this->_memoryCacheAdd($this->_file, $data);
326
-                if ($this->_onlyMemoryCaching) {
326
+                if($this->_onlyMemoryCaching) {
327 327
                     return true;
328 328
                 }
329 329
             }
330
-            if ($this->_writeControl) {
331
-                if (!$this->_writeAndControl($data)) {
332
-                    @touch($this->_file, time() - 2*abs($this->_lifeTime));
330
+            if($this->_writeControl) {
331
+                if(!$this->_writeAndControl($data)) {
332
+                    @touch($this->_file, time() - 2 * abs($this->_lifeTime));
333 333
                     return false;
334 334
                 } else {
335 335
                     return true;
@@ -349,10 +349,10 @@  discard block
 block discarded – undo
349 349
     * @return boolean true if no problem
350 350
     * @access public
351 351
     */
352
-    function remove($id, $group = 'default')
352
+    function remove($id, $group='default')
353 353
     {
354 354
         $this->_setFileName($id, $group);
355
-        if (!@unlink($this->_file)) {
355
+        if(!@unlink($this->_file)) {
356 356
             $this->raiseError('TCache_Lite : Unable to remove cache !', -3);
357 357
             return false;
358 358
         }
@@ -369,35 +369,35 @@  discard block
 block discarded – undo
369 369
     * @return boolean true if no problem
370 370
     * @access public
371 371
     */
372
-    function clean($group = false)
372
+    function clean($group=false)
373 373
     {
374
-        if ($this->_fileNameProtection) {
375
-            $motif = ($group) ? 'cache_'.md5($group).'_' : 'cache_';
374
+        if($this->_fileNameProtection) {
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
-        if ($this->_memoryCaching) {
380
-            while (list($key, $value) = each($this->_memoryCaching)) {
381
-                if (strpos($key, $motif, 0)) {
379
+        if($this->_memoryCaching) {
380
+            while(list($key, $value)=each($this->_memoryCaching)) {
381
+                if(strpos($key, $motif, 0)) {
382 382
                     unset($this->_memoryCaching[$key]);
383
-                    $this->_memoryCachingCounter =
383
+                    $this->_memoryCachingCounter=
384 384
                     		$this->_memoryCachingCounter - 1;
385 385
                 }
386 386
             }
387
-            if ($this->_onlyMemoryCaching) {
387
+            if($this->_onlyMemoryCaching) {
388 388
                 return true;
389 389
             }
390 390
         }
391
-        if (!($dh = opendir($this->_cacheDir))) {
391
+        if(!($dh=opendir($this->_cacheDir))) {
392 392
             $this->raiseError('TCache_Lite : Unable to open cache directory !');
393 393
             return false;
394 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)) {
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 401
              $this->raiseError('Cache_Lite : Unable to remove cache !', -3);
402 402
                             return false;
403 403
                         }
@@ -416,22 +416,22 @@  discard block
 block discarded – undo
416 416
     */
417 417
     function setLifeTime($newLifeTime)
418 418
     {
419
-        $this->_lifeTime = $newLifeTime;
420
-        $this->_refreshTime = time() - $newLifeTime;
419
+        $this->_lifeTime=$newLifeTime;
420
+        $this->_refreshTime=time() - $newLifeTime;
421 421
     }
422 422
 
423 423
     /**
424 424
     *
425 425
     * @access public
426 426
     */
427
-    function saveMemoryCachingState($id, $group = 'default')
427
+    function saveMemoryCachingState($id, $group='default')
428 428
     {
429
-        if ($this->_caching) {
430
-            $array = array(
429
+        if($this->_caching) {
430
+            $array=array(
431 431
                 'counter' => $this->_memoryCachingCounter,
432 432
                 'array' => $this->_memoryCachingState
433 433
             );
434
-            $data = serialize($array);
434
+            $data=serialize($array);
435 435
             $this->save($data, $id, $group);
436 436
         }
437 437
     }
@@ -440,15 +440,15 @@  discard block
 block discarded – undo
440 440
     *
441 441
     * @access public
442 442
     */
443
-    function getMemoryCachingState($id, $group = 'default',
444
-    								$doNotTestCacheValidity = false)
443
+    function getMemoryCachingState($id, $group='default',
444
+    								$doNotTestCacheValidity=false)
445 445
     {
446
-        if ($this->_caching) {
447
-            if ($data = $this->get($id, $group, $doNotTestCacheValidity))
446
+        if($this->_caching) {
447
+            if($data=$this->get($id, $group, $doNotTestCacheValidity))
448 448
             {
449
-                $array = unserialize($data);
450
-                $this->_memoryCachingCounter = $array['counter'];
451
-                $this->_memoryCachingArray = $array['array'];
449
+                $array=unserialize($data);
450
+                $this->_memoryCachingCounter=$array['counter'];
451
+                $this->_memoryCachingArray=$array['array'];
452 452
             }
453 453
         }
454 454
     }
@@ -488,12 +488,12 @@  discard block
 block discarded – undo
488 488
     */
489 489
     function _memoryCacheAdd($id, $data)
490 490
     {
491
-        $this->_memoryCachingArray[$this->_file] = $data;
492
-        if ($this->_memoryCachingCounter >= $this->_memoryCachingLimit) {
493
-            list($key, $value) = each($this->_memoryCachingArray);
491
+        $this->_memoryCachingArray[$this->_file]=$data;
492
+        if($this->_memoryCachingCounter >= $this->_memoryCachingLimit) {
493
+            list($key, $value)=each($this->_memoryCachingArray);
494 494
             unset($this->_memoryCachingArray[$key]);
495 495
         } else {
496
-            $this->_memoryCachingCounter = $this->_memoryCachingCounter + 1;
496
+            $this->_memoryCachingCounter=$this->_memoryCachingCounter + 1;
497 497
         }
498 498
     }
499 499
 
@@ -506,11 +506,11 @@  discard block
 block discarded – undo
506 506
     */
507 507
     function _setFileName($id, $group)
508 508
     {
509
-        if ($this->_fileNameProtection) {
510
-            $this->_file = ($this->_cacheDir.'cache_'.md5($group).'_'
509
+        if($this->_fileNameProtection) {
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
 
@@ -527,23 +527,23 @@  discard block
 block discarded – undo
527 527
     */
528 528
     function _read()
529 529
     {
530
-        $fp = @fopen($this->_file, "rb");
531
-        if ($this->_fileLocking) @flock($fp, LOCK_SH);
532
-        if ($fp) {
530
+        $fp=@fopen($this->_file, "rb");
531
+        if($this->_fileLocking) @flock($fp, LOCK_SH);
532
+        if($fp) {
533 533
         	// because the filesize can be cached by PHP itself...
534 534
             clearstatcache();
535
-            $length = @filesize($this->_file);
536
-            if ($this->_readControl) {
537
-                $hashControl = @fread($fp, 32);
538
-                $length = $length - 32;
535
+            $length=@filesize($this->_file);
536
+            if($this->_readControl) {
537
+                $hashControl=@fread($fp, 32);
538
+                $length=$length - 32;
539 539
             }
540
-            $data = @fread($fp, $length);
541
-            if ($this->_fileLocking) @flock($fp, LOCK_UN);
540
+            $data=@fread($fp, $length);
541
+            if($this->_fileLocking) @flock($fp, LOCK_UN);
542 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));
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 547
                     return false;
548 548
                 }
549 549
             }
@@ -562,15 +562,15 @@  discard block
 block discarded – undo
562 562
     */
563 563
     function _write($data)
564 564
     {
565
-        $fp = @fopen($this->_file, "wb");
566
-        if ($fp) {
567
-            if ($this->_fileLocking) @flock($fp, LOCK_EX);
568
-            if ($this->_readControl) {
565
+        $fp=@fopen($this->_file, "wb");
566
+        if($fp) {
567
+            if($this->_fileLocking) @flock($fp, LOCK_EX);
568
+            if($this->_readControl) {
569 569
                 @fwrite($fp, $this->_hash($data, $this->_readControlType), 32);
570 570
             }
571
-            $len = strlen($data);
571
+            $len=strlen($data);
572 572
             @fwrite($fp, $data, $len);
573
-            if ($this->_fileLocking) @flock($fp, LOCK_UN);
573
+            if($this->_fileLocking) @flock($fp, LOCK_UN);
574 574
             @fclose($fp);
575 575
             return true;
576 576
         }
@@ -589,7 +589,7 @@  discard block
 block discarded – undo
589 589
     function _writeAndControl($data)
590 590
     {
591 591
         $this->_write($data);
592
-        $dataRead = $this->_read($data);
592
+        $dataRead=$this->_read($data);
593 593
         return ($dataRead==$data);
594 594
     }
595 595
 
@@ -603,7 +603,7 @@  discard block
 block discarded – undo
603 603
     */
604 604
     function _hash($data, $controlType)
605 605
     {
606
-        switch ($controlType) {
606
+        switch($controlType) {
607 607
         case 'md5':
608 608
             return md5($data);
609 609
         case 'crc32':
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   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -39,11 +39,11 @@  discard block
 block discarded – undo
39 39
 	 */
40 40
     function parseDSN($dsn)
41 41
     {
42
-        if (is_array($dsn)) {
42
+        if(is_array($dsn)) {
43 43
             return $dsn;
44 44
         }
45 45
 
46
-        $parsed = array(
46
+        $parsed=array(
47 47
             'phptype'  => false,
48 48
             'dbsyntax' => false,
49 49
             'username' => false,
@@ -56,94 +56,94 @@  discard block
 block discarded – undo
56 56
         );
57 57
 
58 58
         // Find phptype and dbsyntax
59
-        if (($pos = strpos($dsn, '://')) !== false) {
60
-            $str = substr($dsn, 0, $pos);
61
-            $dsn = substr($dsn, $pos + 3);
59
+        if(($pos=strpos($dsn, '://'))!==false) {
60
+            $str=substr($dsn, 0, $pos);
61
+            $dsn=substr($dsn, $pos + 3);
62 62
         } else {
63
-            $str = $dsn;
64
-            $dsn = null;
63
+            $str=$dsn;
64
+            $dsn=null;
65 65
         }
66 66
 
67 67
         // Get phptype and dbsyntax
68 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];
69
+        if(preg_match('|^(.+?)\((.*?)\)$|', $str, $arr)) {
70
+            $parsed['phptype']=$arr[1];
71
+            $parsed['dbsyntax']=(empty($arr[2])) ? $arr[1] : $arr[2];
72 72
         } else {
73
-            $parsed['phptype']  = $str;
74
-            $parsed['dbsyntax'] = $str;
73
+            $parsed['phptype']=$str;
74
+            $parsed['dbsyntax']=$str;
75 75
         }
76 76
 
77
-        if (empty($dsn)) {
77
+        if(empty($dsn)) {
78 78
             return $parsed;
79 79
         }
80 80
 
81 81
         // Get (if found): username and password
82 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));
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 89
             } else {
90
-                $parsed['username'] = rawurldecode($str);
90
+                $parsed['username']=rawurldecode($str);
91 91
             }
92 92
         }
93 93
 
94 94
         // Find protocol and hostspec
95 95
 
96 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];
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 102
         // $dsn => protocol+hostspec/database (old format)
103 103
         } else {
104
-            if (strpos($dsn, '+') !== false) {
105
-                list($proto, $dsn) = explode('+', $dsn, 2);
104
+            if(strpos($dsn, '+')!==false) {
105
+                list($proto, $dsn)=explode('+', $dsn, 2);
106 106
             }
107
-            if (strpos($dsn, '/') !== false) {
108
-                list($proto_opts, $dsn) = explode('/', $dsn, 2);
107
+            if(strpos($dsn, '/')!==false) {
108
+                list($proto_opts, $dsn)=explode('/', $dsn, 2);
109 109
             } else {
110
-                $proto_opts = $dsn;
111
-                $dsn = null;
110
+                $proto_opts=$dsn;
111
+                $dsn=null;
112 112
             }
113 113
         }
114 114
 
115 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);
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 121
             } else {
122
-                $parsed['hostspec'] = $proto_opts;
122
+                $parsed['hostspec']=$proto_opts;
123 123
             }
124
-        } elseif ($parsed['protocol'] == 'unix') {
125
-            $parsed['socket'] = $proto_opts;
124
+        } elseif($parsed['protocol']=='unix') {
125
+            $parsed['socket']=$proto_opts;
126 126
         }
127 127
 
128 128
         // Get dabase if any
129 129
         // $dsn => database
130
-        if (!empty($dsn)) {
130
+        if(!empty($dsn)) {
131 131
             // /database
132
-            if (($pos = strpos($dsn, '?')) === false) {
133
-                $parsed['database'] = $dsn;
132
+            if(($pos=strpos($dsn, '?'))===false) {
133
+                $parsed['database']=$dsn;
134 134
             // /database?param1=value1&param2=value2
135 135
             } else {
136
-                $parsed['database'] = substr($dsn, 0, $pos);
137
-                $dsn = substr($dsn, $pos + 1);
138
-                if (strpos($dsn, '&') !== false) {
139
-                    $opts = explode('&', $dsn);
136
+                $parsed['database']=substr($dsn, 0, $pos);
137
+                $dsn=substr($dsn, $pos + 1);
138
+                if(strpos($dsn, '&')!==false) {
139
+                    $opts=explode('&', $dsn);
140 140
                 } else { // database?param1=value1
141
-                    $opts = array($dsn);
141
+                    $opts=array($dsn);
142 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);
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 147
                     }
148 148
                 }
149 149
             }
@@ -161,10 +161,10 @@  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
167
-			return $s !== false ? $s : $string; //it could return false
166
+			$s=iconv($from, 'UTF-8', $string); //to UTF-8
167
+			return $s!==false ? $s : $string; //it could return false
168 168
 		}
169 169
 		return $string;
170 170
 	}
@@ -177,10 +177,10 @@  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
-			$s = iconv('UTF-8', $to, $string);
183
-			return $s !== false ? $s : $string;
182
+			$s=iconv('UTF-8', $to, $string);
183
+			return $s!==false ? $s : $string;
184 184
 		}
185 185
 		return $string;
186 186
 	} 
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.
Spacing   +155 added lines, -155 removed lines patch added patch discarded remove patch
@@ -60,14 +60,14 @@  discard block
 block discarded – undo
60 60
     */
61 61
     public function __construct($p_tarname)
62 62
     {
63
-        $this->_tarname = $p_tarname;
63
+        $this->_tarname=$p_tarname;
64 64
     }
65 65
 
66 66
     public function __destruct()
67 67
     {
68 68
         $this->_close();
69 69
         // ----- Look for a local copy to delete
70
-        if ($this->_temp_tarname != '')
70
+        if($this->_temp_tarname!='')
71 71
             @unlink($this->_temp_tarname);
72 72
     }
73 73
 
@@ -110,11 +110,11 @@  discard block
 block discarded – undo
110 110
     */
111 111
     protected function extractModify($p_path, $p_remove_path)
112 112
     {
113
-        $v_result = true;
114
-        $v_list_detail = array();
113
+        $v_result=true;
114
+        $v_list_detail=array();
115 115
 
116
-        if ($v_result = $this->_openRead()) {
117
-            $v_result = $this->_extractList($p_path, $v_list_detail,
116
+        if($v_result=$this->_openRead()) {
117
+            $v_result=$this->_extractList($p_path, $v_list_detail,
118 118
 			                                "complete", 0, $p_remove_path);
119 119
             $this->_close();
120 120
         }
@@ -129,8 +129,8 @@  discard block
 block discarded – undo
129 129
 
130 130
     private function _isArchive($p_filename=null)
131 131
     {
132
-        if ($p_filename == null) {
133
-            $p_filename = $this->_tarname;
132
+        if($p_filename==null) {
133
+            $p_filename=$this->_tarname;
134 134
         }
135 135
         clearstatcache();
136 136
         return @is_file($p_filename);
@@ -138,39 +138,39 @@  discard block
 block discarded – undo
138 138
 
139 139
     private function _openRead()
140 140
     {
141
-        if (strtolower(substr($this->_tarname, 0, 7)) == 'http://') {
141
+        if(strtolower(substr($this->_tarname, 0, 7))=='http://') {
142 142
 
143 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')) {
144
+          if($this->_temp_tarname=='') {
145
+              $this->_temp_tarname=uniqid('tar').'.tmp';
146
+              if(!$v_file_from=@fopen($this->_tarname, 'rb')) {
147 147
                 $this->_error('Unable to open in read mode \''
148 148
 				              .$this->_tarname.'\'');
149
-                $this->_temp_tarname = '';
149
+                $this->_temp_tarname='';
150 150
                 return false;
151 151
               }
152
-              if (!$v_file_to = @fopen($this->_temp_tarname, 'wb')) {
152
+              if(!$v_file_to=@fopen($this->_temp_tarname, 'wb')) {
153 153
                 $this->_error('Unable to open in write mode \''
154 154
 				              .$this->_temp_tarname.'\'');
155
-                $this->_temp_tarname = '';
155
+                $this->_temp_tarname='';
156 156
                 return false;
157 157
               }
158
-              while ($v_data = @fread($v_file_from, 1024))
158
+              while($v_data=@fread($v_file_from, 1024))
159 159
                   @fwrite($v_file_to, $v_data);
160 160
               @fclose($v_file_from);
161 161
               @fclose($v_file_to);
162 162
           }
163 163
 
164 164
           // ----- File to open if the local copy
165
-          $v_filename = $this->_temp_tarname;
165
+          $v_filename=$this->_temp_tarname;
166 166
 
167 167
         } else
168 168
           // ----- File to open if the normal Tar file
169
-          $v_filename = $this->_tarname;
169
+          $v_filename=$this->_tarname;
170 170
 
171
-		$this->_file = @fopen($v_filename, "rb");
171
+		$this->_file=@fopen($v_filename, "rb");
172 172
 
173
-        if ($this->_file == 0) {
173
+        if($this->_file==0) {
174 174
             $this->_error('Unable to open in read mode \''.$v_filename.'\'');
175 175
             return false;
176 176
         }
@@ -181,17 +181,17 @@  discard block
 block discarded – undo
181 181
     private function _close()
182 182
     {
183 183
         //if (isset($this->_file)) {
184
-        if (is_resource($this->_file))
184
+        if(is_resource($this->_file))
185 185
 		{
186 186
                @fclose($this->_file);
187
-            $this->_file = 0;
187
+            $this->_file=0;
188 188
         }
189 189
 
190 190
         // ----- Look if a local copy need to be erase
191 191
         // Note that it might be interesting to keep the url for a time : ToDo
192
-        if ($this->_temp_tarname != '') {
192
+        if($this->_temp_tarname!='') {
193 193
             @unlink($this->_temp_tarname);
194
-            $this->_temp_tarname = '';
194
+            $this->_temp_tarname='';
195 195
         }
196 196
 
197 197
         return true;
@@ -202,76 +202,76 @@  discard block
 block discarded – undo
202 202
         $this->_close();
203 203
 
204 204
         // ----- Look for a local copy
205
-        if ($this->_temp_tarname != '') {
205
+        if($this->_temp_tarname!='') {
206 206
             // ----- Remove the local copy but not the remote tarname
207 207
             @unlink($this->_temp_tarname);
208
-            $this->_temp_tarname = '';
208
+            $this->_temp_tarname='';
209 209
         } else {
210 210
             // ----- Remove the local tarname file
211 211
             @unlink($this->_tarname);
212 212
         }
213
-        $this->_tarname = '';
213
+        $this->_tarname='';
214 214
 
215 215
         return true;
216 216
     }
217 217
 
218 218
     private function _readBlock()
219 219
     {
220
-      $v_block = null;
221
-      if (is_resource($this->_file)) {
222
-              $v_block = @fread($this->_file, 512);
220
+      $v_block=null;
221
+      if(is_resource($this->_file)) {
222
+              $v_block=@fread($this->_file, 512);
223 223
       }
224 224
       return $v_block;
225 225
     }
226 226
 
227 227
     private function _jumpBlock($p_len=null)
228 228
     {
229
-      if (is_resource($this->_file)) {
230
-          if ($p_len === null)
231
-              $p_len = 1;
229
+      if(is_resource($this->_file)) {
230
+          if($p_len===null)
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) {
241
-            $v_header['filename'] = '';
240
+        if(strlen($v_binary_data)==0) {
241
+            $v_header['filename']='';
242 242
             return true;
243 243
         }
244 244
 
245
-        if (strlen($v_binary_data) != 512) {
246
-            $v_header['filename'] = '';
245
+        if(strlen($v_binary_data)!=512) {
246
+            $v_header['filename']='';
247 247
             $this->_error('Invalid block size : '.strlen($v_binary_data));
248 248
             return false;
249 249
         }
250 250
 
251 251
         // ----- Calculate the checksum
252
-        $v_checksum = 0;
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++)
258
-            $v_checksum += ord(' ');
257
+        for($i=148; $i < 156; $i++)
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
-        $v_data = unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/"
263
+        $v_data=unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/"
264 264
 		                 ."a8checksum/a1typeflag/a100link/a6magic/a2version/"
265 265
 						 ."a32uname/a32gname/a8devmajor/a8devminor",
266 266
 						 $v_binary_data);
267 267
 
268 268
         // ----- Extract the checksum
269
-        $v_header['checksum'] = OctDec(trim($v_data['checksum']));
270
-        if ($v_header['checksum'] != $v_checksum) {
271
-            $v_header['filename'] = '';
269
+        $v_header['checksum']=OctDec(trim($v_data['checksum']));
270
+        if($v_header['checksum']!=$v_checksum) {
271
+            $v_header['filename']='';
272 272
 
273 273
             // ----- Look for last block (empty block)
274
-            if (($v_checksum == 256) && ($v_header['checksum'] == 0))
274
+            if(($v_checksum==256) && ($v_header['checksum']==0))
275 275
                 return true;
276 276
 
277 277
             $this->_error('Invalid checksum for file "'.$v_data['filename']
@@ -281,38 +281,38 @@  discard block
 block discarded – undo
281 281
         }
282 282
 
283 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;
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 292
         }
293 293
         return true;
294 294
     }
295 295
 
296 296
     private function _readLongHeader(&$v_header)
297 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;
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 303
       }
304
-      if (($v_header['size'] % 512) != 0) {
305
-        $v_content = $this->_readBlock();
306
-        $v_filename .= $v_content;
304
+      if(($v_header['size'] % 512)!=0) {
305
+        $v_content=$this->_readBlock();
306
+        $v_filename.=$v_content;
307 307
       }
308 308
 
309 309
       // ----- Read the next header
310
-      $v_binary_data = $this->_readBlock();
310
+      $v_binary_data=$this->_readBlock();
311 311
 
312
-      if (!$this->_readHeader($v_binary_data, $v_header))
312
+      if(!$this->_readHeader($v_binary_data, $v_header))
313 313
         return false;
314 314
 
315
-      $v_header['filename'] = $v_filename;
315
+      $v_header['filename']=$v_filename;
316 316
 
317 317
       return true;
318 318
     }
@@ -321,34 +321,34 @@  discard block
 block discarded – undo
321 321
 	                      $p_file_list, $p_remove_path)
322 322
     {
323 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;
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 332
     }
333
-    $p_remove_path = $this->_translateWinPath($p_remove_path);
333
+    $p_remove_path=$this->_translateWinPath($p_remove_path);
334 334
 
335 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);
336
+    if(($p_remove_path!='') && (substr($p_remove_path, -1)!='/'))
337
+      $p_remove_path.='/';
338
+    $p_remove_path_size=strlen($p_remove_path);
339 339
 
340
-    switch ($p_mode) {
340
+    switch($p_mode) {
341 341
       case "complete" :
342
-        $v_extract_all = true;
343
-        $v_listing = false;
342
+        $v_extract_all=true;
343
+        $v_listing=false;
344 344
       break;
345 345
       case "partial" :
346
-          $v_extract_all = false;
347
-          $v_listing = false;
346
+          $v_extract_all=false;
347
+          $v_listing=false;
348 348
       break;
349 349
       case "list" :
350
-          $v_extract_all = false;
351
-          $v_listing = true;
350
+          $v_extract_all=false;
351
+          $v_listing=true;
352 352
       break;
353 353
       default :
354 354
         $this->_error('Invalid extract mode ('.$p_mode.')');
@@ -357,103 +357,103 @@  discard block
 block discarded – undo
357 357
 
358 358
     clearstatcache();
359 359
 
360
-    while (strlen($v_binary_data = $this->_readBlock()) != 0)
360
+    while(strlen($v_binary_data=$this->_readBlock())!=0)
361 361
     {
362
-      $v_extract_file = false;
363
-      $v_extraction_stopped = 0;
362
+      $v_extract_file=false;
363
+      $v_extraction_stopped=0;
364 364
 
365
-      if (!$this->_readHeader($v_binary_data, $v_header))
365
+      if(!$this->_readHeader($v_binary_data, $v_header))
366 366
         return false;
367 367
 
368
-      if ($v_header['filename'] == '') {
368
+      if($v_header['filename']=='') {
369 369
         continue;
370 370
       }
371 371
 
372 372
       // ----- Look for long filename
373
-      if ($v_header['typeflag'] == 'L') {
374
-        if (!$this->_readLongHeader($v_header))
373
+      if($v_header['typeflag']=='L') {
374
+        if(!$this->_readLongHeader($v_header))
375 375
           return false;
376 376
       }
377 377
 
378
-      if ((!$v_extract_all) && (is_array($p_file_list))) {
378
+      if((!$v_extract_all) && (is_array($p_file_list))) {
379 379
         // ----- By default no unzip if the file is not found
380
-        $v_extract_file = false;
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
-          if (substr($p_file_list[$i], -1) == '/') {
384
+          if(substr($p_file_list[$i], -1)=='/') {
385 385
             // ----- Look if the directory is in the filename path
386
-            if ((strlen($v_header['filename']) > strlen($p_file_list[$i]))
386
+            if((strlen($v_header['filename']) > strlen($p_file_list[$i]))
387 387
 			    && (substr($v_header['filename'], 0, strlen($p_file_list[$i]))
388 388
 				    == $p_file_list[$i])) {
389
-              $v_extract_file = true;
389
+              $v_extract_file=true;
390 390
               break;
391 391
             }
392 392
           }
393 393
 
394 394
           // ----- It is a file, so compare the file names
395
-          elseif ($p_file_list[$i] == $v_header['filename']) {
396
-            $v_extract_file = true;
395
+          elseif($p_file_list[$i]==$v_header['filename']) {
396
+            $v_extract_file=true;
397 397
             break;
398 398
           }
399 399
         }
400 400
       } else {
401
-        $v_extract_file = true;
401
+        $v_extract_file=true;
402 402
       }
403 403
 
404 404
       // ----- Look if this file need to be extracted
405
-      if (($v_extract_file) && (!$v_listing))
405
+      if(($v_extract_file) && (!$v_listing))
406 406
       {
407
-        if (($p_remove_path != '')
407
+        if(($p_remove_path!='')
408 408
             && (substr($v_header['filename'], 0, $p_remove_path_size)
409 409
 			    == $p_remove_path))
410
-          $v_header['filename'] = substr($v_header['filename'],
410
+          $v_header['filename']=substr($v_header['filename'],
411 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);
412
+        if(($p_path!='./') && ($p_path!='/')) {
413
+          while(substr($p_path, -1)=='/')
414
+            $p_path=substr($p_path, 0, strlen($p_path) - 1);
415 415
 
416
-          if (substr($v_header['filename'], 0, 1) == '/')
417
-              $v_header['filename'] = $p_path.$v_header['filename'];
416
+          if(substr($v_header['filename'], 0, 1)=='/')
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
-        if (file_exists($v_header['filename'])) {
422
-          if (   (@is_dir($v_header['filename']))
423
-		      && ($v_header['typeflag'] == '')) {
421
+        if(file_exists($v_header['filename'])) {
422
+          if((@is_dir($v_header['filename']))
423
+		      && ($v_header['typeflag']=='')) {
424 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']))
429
-		      && ($v_header['typeflag'] == "5")) {
428
+          if(($this->_isArchive($v_header['filename']))
429
+		      && ($v_header['typeflag']=="5")) {
430 430
             $this->_error('Directory '.$v_header['filename']
431 431
 			              .' already exists as a file');
432 432
             return false;
433 433
           }
434
-          if (!is_writeable($v_header['filename'])) {
434
+          if(!is_writeable($v_header['filename'])) {
435 435
             $this->_error('File '.$v_header['filename']
436 436
 			              .' already exists and is write protected');
437 437
             return false;
438 438
           }
439
-          if (filemtime($v_header['filename']) > $v_header['mtime']) {
439
+          if(filemtime($v_header['filename']) > $v_header['mtime']) {
440 440
             // To be completed : An error or silent no replace ?
441 441
           }
442 442
         }
443 443
 
444 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
-									:dirname($v_header['filename'])))) != 1) {
445
+        elseif(($v_result
446
+		         = $this->_dirCheck(($v_header['typeflag']=="5"
447
+				                    ? $v_header['filename']
448
+									:dirname($v_header['filename']))))!=1) {
449 449
             $this->_error('Unable to create path for '.$v_header['filename']);
450 450
             return false;
451 451
         }
452 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)) {
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 457
                     $this->_error('Unable to create directory {'
458 458
 					              .$v_header['filename'].'}');
459 459
                     return false;
@@ -461,18 +461,18 @@  discard block
 block discarded – undo
461 461
                 chmod($v_header['filename'], PRADO_CHMOD);
462 462
             }
463 463
           } else {
464
-              if (($v_dest_file = @fopen($v_header['filename'], "wb")) == 0) {
464
+              if(($v_dest_file=@fopen($v_header['filename'], "wb"))==0) {
465 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++) {
471
-                      $v_content = $this->_readBlock();
469
+                  $n=floor($v_header['size'] / 512);
470
+                  for($i=0; $i < $n; $i++) {
471
+                      $v_content=$this->_readBlock();
472 472
                       fwrite($v_dest_file, $v_content, 512);
473 473
                   }
474
-            if (($v_header['size'] % 512) != 0) {
475
-              $v_content = $this->_readBlock();
474
+            if(($v_header['size'] % 512)!=0) {
475
+              $v_content=$this->_readBlock();
476 476
               fwrite($v_dest_file, $v_content, ($v_header['size'] % 512));
477 477
             }
478 478
 
@@ -486,7 +486,7 @@  discard block
 block discarded – undo
486 486
 
487 487
           // ----- Check the file size
488 488
           clearstatcache();
489
-          if (filesize($v_header['filename']) != $v_header['size']) {
489
+          if(filesize($v_header['filename'])!=$v_header['size']) {
490 490
               $this->_error('Extracted file '.$v_header['filename']
491 491
 			                .' does not have the correct file size \''
492 492
 							.filesize($v_header['filename'])
@@ -496,10 +496,10 @@  discard block
 block discarded – undo
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 ...
@@ -509,15 +509,15 @@  discard block
 block discarded – undo
509 509
         $v_end_of_file = @feof($this->_file);
510 510
         */
511 511
 
512
-      if ($v_listing || $v_extract_file || $v_extraction_stopped) {
512
+      if($v_listing || $v_extract_file || $v_extraction_stopped) {
513 513
         // ----- Log extracted files
514
-        if (($v_file_dir = dirname($v_header['filename']))
514
+        if(($v_file_dir=dirname($v_header['filename']))
515 515
 		    == $v_header['filename'])
516
-          $v_file_dir = '';
517
-        if ((substr($v_header['filename'], 0, 1) == '/') && ($v_file_dir == ''))
518
-          $v_file_dir = '/';
516
+          $v_file_dir='';
517
+        if((substr($v_header['filename'], 0, 1)=='/') && ($v_file_dir==''))
518
+          $v_file_dir='/';
519 519
 
520
-        $p_list_detail[$v_nb++] = $v_header;
520
+        $p_list_detail[$v_nb++]=$v_header;
521 521
       }
522 522
     }
523 523
 
@@ -534,36 +534,36 @@  discard block
 block discarded – undo
534 534
      */
535 535
     protected function _dirCheck($p_dir)
536 536
     {
537
-        if ((@is_dir($p_dir)) || ($p_dir == ''))
537
+        if((@is_dir($p_dir)) || ($p_dir==''))
538 538
             return true;
539 539
 
540
-        $p_parent_dir = dirname($p_dir);
540
+        $p_parent_dir=dirname($p_dir);
541 541
 
542
-        if (($p_parent_dir != $p_dir) &&
543
-            ($p_parent_dir != '') &&
542
+        if(($p_parent_dir!=$p_dir) &&
543
+            ($p_parent_dir!='') &&
544 544
             (!$this->_dirCheck($p_parent_dir)))
545 545
              return false;
546 546
 
547
-        if (!@mkdir($p_dir, PRADO_CHMOD)) {
547
+        if(!@mkdir($p_dir, PRADO_CHMOD)) {
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 556
     protected function _translateWinPath($p_path, $p_remove_disk_letter=true)
557 557
     {
558
-      if (substr(PHP_OS, 0, 3) == 'WIN') {
558
+      if(substr(PHP_OS, 0, 3)=='WIN') {
559 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);
560
+          if(($p_remove_disk_letter)
561
+		      && (($v_position=strpos($p_path, ':'))!=false)) {
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) == '\\')) {
566
-              $p_path = strtr($p_path, '\\', '/');
565
+          if((strpos($p_path, '\\') > 0) || (substr($p_path, 0, 1)=='\\')) {
566
+              $p_path=strtr($p_path, '\\', '/');
567 567
           }
568 568
       }
569 569
       return $p_path;
Please login to merge, or discard this patch.
Braces   +6 added lines, -4 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
           }
@@ -410,8 +411,9 @@  discard block
 block discarded – undo
410 411
           $v_header['filename'] = substr($v_header['filename'],
411 412
 		                                 $p_remove_path_size);
412 413
         if (($p_path != './') && ($p_path != '/')) {
413
-          while (substr($p_path, -1) == '/')
414
-            $p_path = substr($p_path, 0, strlen($p_path)-1);
414
+          while (substr($p_path, -1) == '/') {
415
+                      $p_path = substr($p_path, 0, strlen($p_path)-1);
416
+          }
415 417
 
416 418
           if (substr($v_header['filename'], 0, 1) == '/')
417 419
               $v_header['filename'] = $p_path.$v_header['filename'];
Please login to merge, or discard this patch.
Indentation   +516 added lines, -516 removed lines patch added patch discarded remove patch
@@ -1,11 +1,11 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * TTarFileExtractor class file
4
- *
5
- * @author Vincent Blavet <[email protected]>
6
- * @copyright Copyright &copy; 1997-2003 The PHP Group
7
- * @package System.IO
8
- */
3
+	 * TTarFileExtractor class file
4
+	 *
5
+	 * @author Vincent Blavet <[email protected]>
6
+	 * @copyright Copyright &copy; 1997-2003 The PHP Group
7
+	 * @package System.IO
8
+	 */
9 9
 
10 10
 /* vim: set ts=4 sw=4: */
11 11
 // +----------------------------------------------------------------------+
@@ -35,537 +35,537 @@  discard block
 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.
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.
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * TTextWriter class file
4
- *
5
- * @author Qiang Xue <[email protected]>
6
- * @link https://github.com/pradosoft/prado
7
- * @copyright Copyright &copy; 2005-2016 The PRADO Group
8
- * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
9
- * @package System.IO
10
- */
3
+	 * TTextWriter class file
4
+	 *
5
+	 * @author Qiang Xue <[email protected]>
6
+	 * @link https://github.com/pradosoft/prado
7
+	 * @copyright Copyright &copy; 2005-2016 The PRADO Group
8
+	 * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
9
+	 * @package System.IO
10
+	 */
11 11
 
12 12
 /**
13 13
  * TTextWriter class.
Please login to merge, or discard this patch.
framework/PradoBase.php 4 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -184,6 +184,7 @@
 block discarded – undo
184 184
 	 * will cause the throw of an exception.
185 185
 	 * This method should only be used by framework developers.
186 186
 	 * @param TApplication the application instance
187
+	 * @param TApplication $application
187 188
 	 * @throws TInvalidOperationException if this method is invoked twice or more.
188 189
 	 */
189 190
 	public static function setApplication($application)
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -18,8 +18,8 @@
 block discarded – undo
18 18
 if(!defined('PRADO_DIR'))
19 19
 	define('PRADO_DIR',dirname(__FILE__));
20 20
 /**
21
- * Defines the default permission for writable directories and files
22
- */
21
+	 * Defines the default permission for writable directories and files
22
+	 */
23 23
 if(!defined('PRADO_CHMOD'))
24 24
 	define('PRADO_CHMOD',0777);
25 25
 
Please login to merge, or discard this patch.
Braces   +11 added lines, -22 removed lines patch added patch discarded remove patch
@@ -116,8 +116,7 @@  discard block
 block discarded – undo
116 116
 		{
117 117
 			$am=self::$_application->getAssetManager();
118 118
 			$url=$am->publishFilePath(self::getPathOfNamespace('System.'.$logoName,'.gif'));
119
-		}
120
-		else
119
+		} else
121 120
 			$url='http://pradosoft.github.io/docs/'.$logoName.'.gif';
122 121
 		return '<a title="Powered by PRADO" href="https://github.com/pradosoft/prado" target="_blank"><img src="'.$url.'" style="border-width:0px;" alt="Powered by PRADO" /></a>';
123 122
 	}
@@ -169,8 +168,7 @@  discard block
 block discarded – undo
169 168
 		if(self::$_application!==null && ($errorHandler=self::$_application->getErrorHandler())!==null)
170 169
 		{
171 170
 			$errorHandler->handleError(null,$exception);
172
-		}
173
-		else
171
+		} else
174 172
 		{
175 173
 			echo $exception;
176 174
 		}
@@ -259,8 +257,7 @@  discard block
 block discarded – undo
259 257
 					return $component;
260 258
 				break;
261 259
 			}
262
-		}
263
-		else
260
+		} else
264 261
 			return new $type;
265 262
 	}
266 263
 
@@ -282,24 +279,21 @@  discard block
 block discarded – undo
282 279
 			try
283 280
 			{
284 281
 				include_once($namespace.self::CLASS_FILE_EXT);
285
-			}
286
-			catch(Exception $e)
282
+			} catch(Exception $e)
287 283
 			{
288 284
 				if($checkClassExistence && !class_exists($namespace,false))
289 285
 					throw new TInvalidOperationException('prado_component_unknown',$namespace,$e->getMessage());
290 286
 				else
291 287
 					throw $e;
292 288
 			}
293
-		}
294
-		else if(($path=self::getPathOfNamespace($namespace,self::CLASS_FILE_EXT))!==null)
289
+		} else if(($path=self::getPathOfNamespace($namespace,self::CLASS_FILE_EXT))!==null)
295 290
 		{
296 291
 			$className=substr($namespace,$pos+1);
297 292
 			if($className==='*')  // a directory
298 293
 			{
299 294
 				self::$_usings[$namespace]=$path;
300 295
 				set_include_path(get_include_path().PATH_SEPARATOR.$path);
301
-			}
302
-			else  // a file
296
+			} else  // a file
303 297
 			{
304 298
 				self::$_usings[$namespace]=$path;
305 299
 				if(!$checkClassExistence || !class_exists($className,false))
@@ -307,8 +301,7 @@  discard block
 block discarded – undo
307 301
 					try
308 302
 					{
309 303
 						include_once($path);
310
-					}
311
-					catch(Exception $e)
304
+					} catch(Exception $e)
312 305
 					{
313 306
 						if($checkClassExistence && !class_exists($className,false))
314 307
 							throw new TInvalidOperationException('prado_component_unknown',$className,$e->getMessage());
@@ -317,8 +310,7 @@  discard block
 block discarded – undo
317 310
 					}
318 311
 				}
319 312
 			}
320
-		}
321
-		else
313
+		} else
322 314
 			throw new TInvalidDataValueException('prado_using_invalid',$namespace);
323 315
 	}
324 316
 
@@ -384,8 +376,7 @@  discard block
 block discarded – undo
384 376
 				self::$_aliases[$alias]=$rp;
385 377
 			else
386 378
 				throw new TInvalidDataValueException('prado_aliasname_invalid',$alias);
387
-		}
388
-		else
379
+		} else
389 380
 			throw new TInvalidDataValueException('prado_alias_invalid',$alias,$path);
390 381
 	}
391 382
 
@@ -430,8 +421,7 @@  discard block
 block discarded – undo
430 421
 							echo "'". substr($str, 0, 70) . "...'";
431 422
 						else
432 423
 							echo "'" . $str . "'";
433
-					}
434
-					else if (is_int($item) || is_float($item))
424
+					} else if (is_int($item) || is_float($item))
435 425
 						echo $item;
436 426
 					else if (is_object($item))
437 427
 						echo get_class($item);
@@ -526,8 +516,7 @@  discard block
 block discarded – undo
526 516
 			if(isset($trace[0]['file']) && isset($trace[0]['line']))
527 517
 				$msg.=" (line {$trace[0]['line']}, {$trace[0]['file']})";
528 518
 			$level=TLogger::DEBUG;
529
-		}
530
-		else
519
+		} else
531 520
 			$level=TLogger::INFO;
532 521
 		self::log($msg,$level,$category,$ctl);
533 522
 	}
Please login to merge, or discard this patch.
Spacing   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -16,12 +16,12 @@  discard block
 block discarded – undo
16 16
  * Defines the PRADO framework installation path.
17 17
  */
18 18
 if(!defined('PRADO_DIR'))
19
-	define('PRADO_DIR',dirname(__FILE__));
19
+	define('PRADO_DIR', dirname(__FILE__));
20 20
 /**
21 21
  * Defines the default permission for writable directories and files
22 22
  */
23 23
 if(!defined('PRADO_CHMOD'))
24
-	define('PRADO_CHMOD',0777);
24
+	define('PRADO_CHMOD', 0777);
25 25
 
26 26
 /**
27 27
  * PradoBase class.
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	/**
63 63
 	 * @var array list of class exists checks
64 64
 	 */
65
-	protected static $classExists = array();
65
+	protected static $classExists=array();
66 66
 
67 67
 	/**
68 68
 	 * @return string the version of Prado framework
@@ -82,15 +82,15 @@  discard block
 block discarded – undo
82 82
 		/**
83 83
 		 * Sets error handler to be Prado::phpErrorHandler
84 84
 		 */
85
-		set_error_handler(array('PradoBase','phpErrorHandler'));
85
+		set_error_handler(array('PradoBase', 'phpErrorHandler'));
86 86
 		/**
87 87
 		 * Sets shutdown function to be Prado::phpFatalErrorHandler
88 88
 		 */
89
-		register_shutdown_function(array('PradoBase','phpFatalErrorHandler'));
89
+		register_shutdown_function(array('PradoBase', 'phpFatalErrorHandler'));
90 90
 		/**
91 91
 		 * Sets exception handler to be Prado::exceptionHandler
92 92
 		 */
93
-		set_exception_handler(array('PradoBase','exceptionHandler'));
93
+		set_exception_handler(array('PradoBase', 'exceptionHandler'));
94 94
 		/**
95 95
 		 * Disable php's builtin error reporting to avoid duplicated reports
96 96
 		 */
@@ -113,11 +113,11 @@  discard block
 block discarded – undo
113 113
 	 */
114 114
 	public static function poweredByPrado($logoType=0)
115 115
 	{
116
-		$logoName=$logoType==1?'powered2':'powered';
116
+		$logoName=$logoType==1 ? 'powered2' : 'powered';
117 117
 		if(self::$_application!==null)
118 118
 		{
119 119
 			$am=self::$_application->getAssetManager();
120
-			$url=$am->publishFilePath(self::getPathOfNamespace('System.'.$logoName,'.gif'));
120
+			$url=$am->publishFilePath(self::getPathOfNamespace('System.'.$logoName, '.gif'));
121 121
 		}
122 122
 		else
123 123
 			$url='http://pradosoft.github.io/docs/'.$logoName.'.gif';
@@ -134,10 +134,10 @@  discard block
 block discarded – undo
134 134
 	 * @param string the filename that the error was raised in
135 135
 	 * @param integer the line number the error was raised at
136 136
 	 */
137
-	public static function phpErrorHandler($errno,$errstr,$errfile,$errline)
137
+	public static function phpErrorHandler($errno, $errstr, $errfile, $errline)
138 138
 	{
139 139
 		if(error_reporting() & $errno)
140
-			throw new TPhpErrorException($errno,$errstr,$errfile,$errline);
140
+			throw new TPhpErrorException($errno, $errstr, $errfile, $errline);
141 141
 	}
142 142
 
143 143
 	/**
@@ -148,12 +148,12 @@  discard block
 block discarded – undo
148 148
 	 */
149 149
 	public static function phpFatalErrorHandler()
150 150
 	{
151
-		$error = error_get_last();
151
+		$error=error_get_last();
152 152
 		if($error && 
153 153
 			TPhpErrorException::isFatalError($error) &&
154 154
 			error_reporting() & $error['type'])
155 155
 		{
156
-			self::exceptionHandler(new TPhpErrorException($error['type'],$error['message'],$error['file'],$error['line']));
156
+			self::exceptionHandler(new TPhpErrorException($error['type'], $error['message'], $error['file'], $error['line']));
157 157
 		}
158 158
 	}
159 159
 
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 	{
171 171
 		if(self::$_application!==null && ($errorHandler=self::$_application->getErrorHandler())!==null)
172 172
 		{
173
-			$errorHandler->handleError(null,$exception);
173
+			$errorHandler->handleError(null, $exception);
174 174
 		}
175 175
 		else
176 176
 		{
@@ -227,19 +227,19 @@  discard block
 block discarded – undo
227 227
 	public static function createComponent($type)
228 228
 	{
229 229
 		if(!isset(self::$classExists[$type]))
230
-			self::$classExists[$type] = class_exists($type, false);
230
+			self::$classExists[$type]=class_exists($type, false);
231 231
 
232
-		if( !isset(self::$_usings[$type]) && !self::$classExists[$type]) {
232
+		if(!isset(self::$_usings[$type]) && !self::$classExists[$type]) {
233 233
 			self::using($type);
234
-			self::$classExists[$type] = class_exists($type, false);
234
+			self::$classExists[$type]=class_exists($type, false);
235 235
 		}
236 236
 
237
-		if( ($pos = strrpos($type, '.')) !== false)
238
-			$type = substr($type,$pos+1);
237
+		if(($pos=strrpos($type, '.'))!==false)
238
+			$type=substr($type, $pos + 1);
239 239
 
240
-		if(($n=func_num_args())>1)
240
+		if(($n=func_num_args()) > 1)
241 241
 		{
242
-			$args = func_get_args();
242
+			$args=func_get_args();
243 243
 			switch($n) {
244 244
 				case 2:
245 245
 					return new $type($args[1]);
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
 				break;
256 256
 				default:
257 257
 					$s='$args[1]';
258
-					for($i=2;$i<$n;++$i)
258
+					for($i=2; $i < $n; ++$i)
259 259
 						$s.=",\$args[$i]";
260 260
 					eval("\$component=new $type($s);");
261 261
 					return $component;
@@ -275,11 +275,11 @@  discard block
 block discarded – undo
275 275
 	 * @param boolean whether to check the existence of the class after the class file is included
276 276
 	 * @throws TInvalidDataValueException if the namespace is invalid
277 277
 	 */
278
-	public static function using($namespace,$checkClassExistence=true)
278
+	public static function using($namespace, $checkClassExistence=true)
279 279
 	{
280
-		if(isset(self::$_usings[$namespace]) || class_exists($namespace,false))
280
+		if(isset(self::$_usings[$namespace]) || class_exists($namespace, false))
281 281
 			return;
282
-		if(($pos=strrpos($namespace,'.'))===false)  // a class name
282
+		if(($pos=strrpos($namespace, '.'))===false)  // a class name
283 283
 		{
284 284
 			try
285 285
 			{
@@ -287,15 +287,15 @@  discard block
 block discarded – undo
287 287
 			}
288 288
 			catch(Exception $e)
289 289
 			{
290
-				if($checkClassExistence && !class_exists($namespace,false))
291
-					throw new TInvalidOperationException('prado_component_unknown',$namespace,$e->getMessage());
290
+				if($checkClassExistence && !class_exists($namespace, false))
291
+					throw new TInvalidOperationException('prado_component_unknown', $namespace, $e->getMessage());
292 292
 				else
293 293
 					throw $e;
294 294
 			}
295 295
 		}
296
-		else if(($path=self::getPathOfNamespace($namespace,self::CLASS_FILE_EXT))!==null)
296
+		else if(($path=self::getPathOfNamespace($namespace, self::CLASS_FILE_EXT))!==null)
297 297
 		{
298
-			$className=substr($namespace,$pos+1);
298
+			$className=substr($namespace, $pos + 1);
299 299
 			if($className==='*')  // a directory
300 300
 			{
301 301
 				self::$_usings[$namespace]=$path;
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
 			else  // a file
305 305
 			{
306 306
 				self::$_usings[$namespace]=$path;
307
-				if(!$checkClassExistence || !class_exists($className,false))
307
+				if(!$checkClassExistence || !class_exists($className, false))
308 308
 				{
309 309
 					try
310 310
 					{
@@ -312,8 +312,8 @@  discard block
 block discarded – undo
312 312
 					}
313 313
 					catch(Exception $e)
314 314
 					{
315
-						if($checkClassExistence && !class_exists($className,false))
316
-							throw new TInvalidOperationException('prado_component_unknown',$className,$e->getMessage());
315
+						if($checkClassExistence && !class_exists($className, false))
316
+							throw new TInvalidOperationException('prado_component_unknown', $className, $e->getMessage());
317 317
 						else
318 318
 							throw $e;
319 319
 					}
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
 			}
322 322
 		}
323 323
 		else
324
-			throw new TInvalidDataValueException('prado_using_invalid',$namespace);
324
+			throw new TInvalidDataValueException('prado_using_invalid', $namespace);
325 325
 	}
326 326
 
327 327
 	/**
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
 	 */
339 339
 	public static function getPathOfNamespace($namespace, $ext='')
340 340
 	{
341
-		if(self::CLASS_FILE_EXT === $ext || empty($ext))
341
+		if(self::CLASS_FILE_EXT===$ext || empty($ext))
342 342
 		{
343 343
 			if(isset(self::$_usings[$namespace]))
344 344
 				return self::$_usings[$namespace];
@@ -347,11 +347,11 @@  discard block
 block discarded – undo
347 347
 				return self::$_aliases[$namespace];
348 348
 		}
349 349
 
350
-		$segs = explode('.',$namespace);
351
-		$alias = array_shift($segs);
350
+		$segs=explode('.', $namespace);
351
+		$alias=array_shift($segs);
352 352
 
353
-		if(null !== ($file = array_pop($segs)) && null !== ($root = self::getPathOfAlias($alias)))
354
-			return rtrim($root.DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR ,$segs),'/\\').(($file === '*') ? '' : DIRECTORY_SEPARATOR.$file.$ext);
353
+		if(null!==($file=array_pop($segs)) && null!==($root=self::getPathOfAlias($alias)))
354
+			return rtrim($root.DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR, $segs), '/\\').(($file==='*') ? '' : DIRECTORY_SEPARATOR.$file.$ext);
355 355
 
356 356
 		return null;
357 357
 	}
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
 	 */
363 363
 	public static function getPathOfAlias($alias)
364 364
 	{
365
-		return isset(self::$_aliases[$alias])?self::$_aliases[$alias]:null;
365
+		return isset(self::$_aliases[$alias]) ? self::$_aliases[$alias] : null;
366 366
 	}
367 367
 
368 368
 	protected static function getPathAliases()
@@ -376,19 +376,19 @@  discard block
 block discarded – undo
376 376
 	 * @throws TInvalidOperationException if the alias is already defined
377 377
 	 * @throws TInvalidDataValueException if the path is not a valid file path
378 378
 	 */
379
-	public static function setPathOfAlias($alias,$path)
379
+	public static function setPathOfAlias($alias, $path)
380 380
 	{
381 381
 		if(isset(self::$_aliases[$alias]) && !defined('PRADO_TEST_RUN'))
382
-			throw new TInvalidOperationException('prado_alias_redefined',$alias);
382
+			throw new TInvalidOperationException('prado_alias_redefined', $alias);
383 383
 		else if(($rp=realpath($path))!==false && is_dir($rp))
384 384
 		{
385
-			if(strpos($alias,'.')===false)
385
+			if(strpos($alias, '.')===false)
386 386
 				self::$_aliases[$alias]=$rp;
387 387
 			else
388
-				throw new TInvalidDataValueException('prado_aliasname_invalid',$alias);
388
+				throw new TInvalidDataValueException('prado_aliasname_invalid', $alias);
389 389
 		}
390 390
 		else
391
-			throw new TInvalidDataValueException('prado_alias_invalid',$alias,$path);
391
+			throw new TInvalidDataValueException('prado_alias_invalid', $alias, $path);
392 392
 	}
393 393
 
394 394
 	/**
@@ -413,13 +413,13 @@  discard block
 block discarded – undo
413 413
 				continue;
414 414
 			echo '#'.$index.' ';
415 415
 			if(isset($t['file']))
416
-				echo basename($t['file']) . ':' . $t['line'];
416
+				echo basename($t['file']).':'.$t['line'];
417 417
 			else
418 418
 				 echo '<PHP inner-code>';
419 419
 			echo ' -- ';
420 420
 			if(isset($t['class']))
421
-				echo $t['class'] . $t['type'];
422
-			echo $t['function'] . '(';
421
+				echo $t['class'].$t['type'];
422
+			echo $t['function'].'(';
423 423
 			if(isset($t['args']) && sizeof($t['args']) > 0)
424 424
 			{
425 425
 				$count=0;
@@ -428,25 +428,25 @@  discard block
 block discarded – undo
428 428
 					if(is_string($item))
429 429
 					{
430 430
 						$str=htmlentities(str_replace("\r\n", "", $item), ENT_QUOTES);
431
-						if (strlen($item) > 70)
432
-							echo "'". substr($str, 0, 70) . "...'";
431
+						if(strlen($item) > 70)
432
+							echo "'".substr($str, 0, 70)."...'";
433 433
 						else
434
-							echo "'" . $str . "'";
434
+							echo "'".$str."'";
435 435
 					}
436
-					else if (is_int($item) || is_float($item))
436
+					else if(is_int($item) || is_float($item))
437 437
 						echo $item;
438
-					else if (is_object($item))
438
+					else if(is_object($item))
439 439
 						echo get_class($item);
440
-					else if (is_array($item))
441
-						echo 'array(' . count($item) . ')';
442
-					else if (is_bool($item))
440
+					else if(is_array($item))
441
+						echo 'array('.count($item).')';
442
+					else if(is_bool($item))
443 443
 						echo $item ? 'true' : 'false';
444
-					else if ($item === null)
444
+					else if($item===null)
445 445
 						echo 'NULL';
446
-					else if (is_resource($item))
446
+					else if(is_resource($item))
447 447
 						echo get_resource_type($item);
448 448
 					$count++;
449
-					if (count($t['args']) > $count)
449
+					if(count($t['args']) > $count)
450 450
 						echo ', ';
451 451
 				}
452 452
 			}
@@ -473,10 +473,10 @@  discard block
 block discarded – undo
473 473
 			else
474 474
 			{
475 475
 				$languages=array();
476
-				foreach(explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']) as $language)
476
+				foreach(explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $language)
477 477
 				{
478
-					$array=explode(';q=',trim($language));
479
-					$languages[trim($array[0])]=isset($array[1])?(float)$array[1]:1.0;
478
+					$array=explode(';q=', trim($language));
479
+					$languages[trim($array[0])]=isset($array[1]) ? (float) $array[1] : 1.0;
480 480
 				}
481 481
 				arsort($languages);
482 482
 				$languages=array_keys($languages);
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
 		if($language===null)
498 498
 		{
499 499
 			$langs=Prado::getUserLanguages();
500
-			$lang=explode('-',$langs[0]);
500
+			$lang=explode('-', $langs[0]);
501 501
 			if(empty($lang[0]) || !ctype_alpha($lang[0]))
502 502
 				$language='en';
503 503
 			else
@@ -518,7 +518,7 @@  discard block
 block discarded – undo
518 518
 	 * @param (string|TControl) control of the message
519 519
 	 * @see log, getLogger
520 520
 	 */
521
-	public static function trace($msg,$category='Uncategorized',$ctl=null)
521
+	public static function trace($msg, $category='Uncategorized', $ctl=null)
522 522
 	{
523 523
 		if(self::$_application && self::$_application->getMode()===TApplicationMode::Performance)
524 524
 			return;
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
 		}
532 532
 		else
533 533
 			$level=TLogger::INFO;
534
-		self::log($msg,$level,$category,$ctl);
534
+		self::log($msg, $level, $category, $ctl);
535 535
 	}
536 536
 
537 537
 	/**
@@ -546,11 +546,11 @@  discard block
 block discarded – undo
546 546
 	 * @param string category of the message
547 547
 	 * @param (string|TControl) control of the message
548 548
 	 */
549
-	public static function log($msg,$level=TLogger::INFO,$category='Uncategorized',$ctl=null)
549
+	public static function log($msg, $level=TLogger::INFO, $category='Uncategorized', $ctl=null)
550 550
 	{
551 551
 		if(self::$_logger===null)
552 552
 			self::$_logger=new TLogger;
553
-		self::$_logger->log($msg,$level,$category,$ctl);
553
+		self::$_logger->log($msg, $level, $category, $ctl);
554 554
 	}
555 555
 
556 556
 	/**
@@ -572,10 +572,10 @@  discard block
 block discarded – undo
572 572
 	 * @param boolean whether to syntax highlight the output. Defaults to false.
573 573
 	 * @return string the string representation of the variable
574 574
 	 */
575
-	public static function varDump($var,$depth=10,$highlight=false)
575
+	public static function varDump($var, $depth=10, $highlight=false)
576 576
 	{
577 577
 		Prado::using('System.Util.TVarDumper');
578
-		return TVarDumper::dump($var,$depth,$highlight);
578
+		return TVarDumper::dump($var, $depth, $highlight);
579 579
 	}
580 580
 
581 581
 	/**
@@ -591,32 +591,32 @@  discard block
 block discarded – undo
591 591
 	public static function localize($text, $parameters=array(), $catalogue=null, $charset=null)
592 592
 	{
593 593
 		Prado::using('System.I18N.Translation');
594
-		$app = Prado::getApplication()->getGlobalization(false);
594
+		$app=Prado::getApplication()->getGlobalization(false);
595 595
 
596
-		$params = array();
596
+		$params=array();
597 597
 		foreach($parameters as $key => $value)
598
-			$params['{'.$key.'}'] = $value;
598
+			$params['{'.$key.'}']=$value;
599 599
 
600 600
 		//no translation handler provided
601
-		if($app===null || ($config = $app->getTranslationConfiguration())===null)
601
+		if($app===null || ($config=$app->getTranslationConfiguration())===null)
602 602
 			return strtr($text, $params);
603 603
 
604
-		if ($catalogue===null)
605
-			$catalogue=isset($config['catalogue'])?$config['catalogue']:'messages';
604
+		if($catalogue===null)
605
+			$catalogue=isset($config['catalogue']) ? $config['catalogue'] : 'messages';
606 606
 
607 607
 		Translation::init($catalogue);
608 608
 
609 609
 		//globalization charset
610
-		$appCharset = $app===null ? '' : $app->getCharset();
610
+		$appCharset=$app===null ? '' : $app->getCharset();
611 611
 
612 612
 		//default charset
613
-		$defaultCharset = ($app===null) ? 'UTF-8' : $app->getDefaultCharset();
613
+		$defaultCharset=($app===null) ? 'UTF-8' : $app->getDefaultCharset();
614 614
 
615 615
 		//fall back
616
-		if(empty($charset)) $charset = $appCharset;
617
-		if(empty($charset)) $charset = $defaultCharset;
616
+		if(empty($charset)) $charset=$appCharset;
617
+		if(empty($charset)) $charset=$defaultCharset;
618 618
 
619
-		return Translation::formatter($catalogue)->format($text,$params,$catalogue,$charset);
619
+		return Translation::formatter($catalogue)->format($text, $params, $catalogue, $charset);
620 620
 	}
621 621
 }
622 622
 
Please login to merge, or discard this patch.
framework/Security/IUserManager.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -35,6 +35,7 @@  discard block
 block discarded – undo
35 35
 	/**
36 36
 	 * Returns a user instance according to auth data stored in a cookie.
37 37
 	 * @param THttpCookie the cookie storing user authentication information
38
+	 * @param THttpCookie $cookie
38 39
 	 * @return TUser the user instance generated based on the cookie auth data, null if the cookie does not have valid auth data.
39 40
 	 * @since 3.1.1
40 41
 	 */
@@ -42,7 +43,9 @@  discard block
 block discarded – undo
42 43
 	/**
43 44
 	 * Saves user auth data into a cookie.
44 45
 	 * @param THttpCookie the cookie to receive the user auth data.
46
+	 * @param THttpCookie $cookie
45 47
 	 * @since 3.1.1
48
+	 * @return void
46 49
 	 */
47 50
 	public function saveUserToCookie($cookie);
48 51
 	/**
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -51,6 +51,6 @@
 block discarded – undo
51 51
 	 * @param string password
52 52
 	 * @return boolean true if validation is successful, false otherwise.
53 53
 	 */
54
-	public function validateUser($username,$password);
54
+	public function validateUser($username, $password);
55 55
 }
56 56
 
Please login to merge, or discard this patch.