Completed
Push — prado-3.3 ( b7af81...086547 )
by Fabio
12:13
created
framework/Web/UI/TTemplateManager.php 1 patch
Spacing   +200 added lines, -200 removed lines patch added patch discarded remove patch
@@ -75,21 +75,21 @@  discard block
 block discarded – undo
75 75
 	{
76 76
 		if(($fileName=$this->getLocalizedTemplate($fileName))!==null)
77 77
 		{
78
-			Prado::trace("Loading template $fileName",'System.Web.UI.TTemplateManager');
78
+			Prado::trace("Loading template $fileName", 'System.Web.UI.TTemplateManager');
79 79
 			if(($cache=$this->getApplication()->getCache())===null)
80
-				return new TTemplate(file_get_contents($fileName),dirname($fileName),$fileName);
80
+				return new TTemplate(file_get_contents($fileName), dirname($fileName), $fileName);
81 81
 			else
82 82
 			{
83 83
 				$array=$cache->get(self::TEMPLATE_CACHE_PREFIX.$fileName);
84 84
 				if(is_array($array))
85 85
 				{
86
-					list($template,$timestamps)=$array;
86
+					list($template, $timestamps)=$array;
87 87
 					if($this->getApplication()->getMode()===TApplicationMode::Performance)
88 88
 						return $template;
89 89
 					$cacheValid=true;
90 90
 					foreach($timestamps as $tplFile=>$timestamp)
91 91
 					{
92
-						if(!is_file($tplFile) || filemtime($tplFile)>$timestamp)
92
+						if(!is_file($tplFile) || filemtime($tplFile) > $timestamp)
93 93
 						{
94 94
 							$cacheValid=false;
95 95
 							break;
@@ -98,13 +98,13 @@  discard block
 block discarded – undo
98 98
 					if($cacheValid)
99 99
 						return $template;
100 100
 				}
101
-				$template=new TTemplate(file_get_contents($fileName),dirname($fileName),$fileName);
101
+				$template=new TTemplate(file_get_contents($fileName), dirname($fileName), $fileName);
102 102
 				$includedFiles=$template->getIncludedFiles();
103 103
 				$timestamps=array();
104 104
 				$timestamps[$fileName]=filemtime($fileName);
105 105
 				foreach($includedFiles as $includedFile)
106 106
 					$timestamps[$includedFile]=filemtime($includedFile);
107
-				$cache->set(self::TEMPLATE_CACHE_PREFIX.$fileName,array($template,$timestamps));
107
+				$cache->set(self::TEMPLATE_CACHE_PREFIX.$fileName, array($template, $timestamps));
108 108
 				return $template;
109 109
 			}
110 110
 		}
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 	protected function getLocalizedTemplate($filename)
121 121
 	{
122 122
 		if(($app=$this->getApplication()->getGlobalization(false))===null)
123
-			return is_file($filename)?$filename:null;
123
+			return is_file($filename) ? $filename : null;
124 124
 		foreach($app->getLocalizedResource($filename) as $file)
125 125
 		{
126 126
 			if(($file=realpath($file))!==false && is_file($file))
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
 	 * @param boolean whether this template is a source template, i.e., this template is loaded from
235 235
 	 * some external storage rather than from within another template.
236 236
 	 */
237
-	public function __construct($template,$contextPath,$tplFile=null,$startingLine=0,$sourceTemplate=true)
237
+	public function __construct($template, $contextPath, $tplFile=null, $startingLine=0, $sourceTemplate=true)
238 238
 	{
239 239
 		$this->_sourceTemplate=$sourceTemplate;
240 240
 		$this->_contextPath=$contextPath;
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
 	 * @param TControl the control who owns the template
303 303
 	 * @param TControl the control who will become the root parent of the controls on the template. If null, it uses the template control.
304 304
 	 */
305
-	public function instantiateIn($tplControl,$parentControl=null)
305
+	public function instantiateIn($tplControl, $parentControl=null)
306 306
 	{
307 307
 		$this->_tplControl=$tplControl;
308 308
 		if($parentControl===null)
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
 					{
333 333
 						if(is_array($properties['id']))
334 334
 							$properties['id']=$component->evaluateExpression($properties['id'][1]);
335
-						$tplControl->registerObject($properties['id'],$component);
335
+						$tplControl->registerObject($properties['id'], $component);
336 336
 					}
337 337
 					if(isset($properties['skinid']))
338 338
 					{
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
 
348 348
 					$component->applyStyleSheetSkin($page);
349 349
 					foreach($properties as $name=>$value)
350
-						$this->configureControl($component,$name,$value);
350
+						$this->configureControl($component, $name, $value);
351 351
 
352 352
 					$component->trackViewState(true);
353 353
 
@@ -365,12 +365,12 @@  discard block
 block discarded – undo
365 365
 					{
366 366
 						if(is_array($properties['id']))
367 367
 							$properties['id']=$component->evaluateExpression($properties['id'][1]);
368
-						$tplControl->registerObject($properties['id'],$component);
368
+						$tplControl->registerObject($properties['id'], $component);
369 369
 						if(!$component->hasProperty('id'))
370 370
 							unset($properties['id']);
371 371
 					}
372 372
 					foreach($properties as $name=>$value)
373
-						$this->configureComponent($component,$name,$value);
373
+						$this->configureComponent($component, $name, $value);
374 374
 					if($parent===$parentControl)
375 375
 						$directChildren[]=$component;
376 376
 					else
@@ -416,14 +416,14 @@  discard block
 block discarded – undo
416 416
 	 * @param string property name
417 417
 	 * @param mixed property initial value
418 418
 	 */
419
-	protected function configureControl($control,$name,$value)
419
+	protected function configureControl($control, $name, $value)
420 420
 	{
421
-		if(strncasecmp($name,'on',2)===0)		// is an event
422
-			$this->configureEvent($control,$name,$value,$control);
423
-		else if(($pos=strrpos($name,'.'))===false)	// is a simple property or custom attribute
424
-			$this->configureProperty($control,$name,$value);
421
+		if(strncasecmp($name, 'on', 2)===0)		// is an event
422
+			$this->configureEvent($control, $name, $value, $control);
423
+		else if(($pos=strrpos($name, '.'))===false)	// is a simple property or custom attribute
424
+			$this->configureProperty($control, $name, $value);
425 425
 		else	// is a subproperty
426
-			$this->configureSubProperty($control,$name,$value);
426
+			$this->configureSubProperty($control, $name, $value);
427 427
 	}
428 428
 
429 429
 	/**
@@ -432,12 +432,12 @@  discard block
 block discarded – undo
432 432
 	 * @param string property name
433 433
 	 * @param mixed property initial value
434 434
 	 */
435
-	protected function configureComponent($component,$name,$value)
435
+	protected function configureComponent($component, $name, $value)
436 436
 	{
437
-		if(strpos($name,'.')===false)	// is a simple property or custom attribute
438
-			$this->configureProperty($component,$name,$value);
437
+		if(strpos($name, '.')===false)	// is a simple property or custom attribute
438
+			$this->configureProperty($component, $name, $value);
439 439
 		else	// is a subproperty
440
-			$this->configureSubProperty($component,$name,$value);
440
+			$this->configureSubProperty($component, $name, $value);
441 441
 	}
442 442
 
443 443
 	/**
@@ -447,12 +447,12 @@  discard block
 block discarded – undo
447 447
 	 * @param string event handler
448 448
 	 * @param TControl context control
449 449
 	 */
450
-	protected function configureEvent($control,$name,$value,$contextControl)
450
+	protected function configureEvent($control, $name, $value, $contextControl)
451 451
 	{
452
-		if(strpos($value,'.')===false)
453
-			$control->attachEventHandler($name,array($contextControl,'TemplateControl.'.$value));
452
+		if(strpos($value, '.')===false)
453
+			$control->attachEventHandler($name, array($contextControl, 'TemplateControl.'.$value));
454 454
 		else
455
-			$control->attachEventHandler($name,array($contextControl,$value));
455
+			$control->attachEventHandler($name, array($contextControl, $value));
456 456
 	}
457 457
 
458 458
 	/**
@@ -461,18 +461,18 @@  discard block
 block discarded – undo
461 461
 	 * @param string property name
462 462
 	 * @param mixed property initial value
463 463
 	 */
464
-	protected function configureProperty($component,$name,$value)
464
+	protected function configureProperty($component, $name, $value)
465 465
 	{
466 466
 		if(is_array($value))
467 467
 		{
468 468
 			switch($value[0])
469 469
 			{
470 470
 				case self::CONFIG_DATABIND:
471
-					$component->bindProperty($name,$value[1]);
471
+					$component->bindProperty($name, $value[1]);
472 472
 					break;
473 473
 				case self::CONFIG_EXPRESSION:
474 474
 					if($component instanceof TControl)
475
-						$component->autoBindProperty($name,$value[1]);
475
+						$component->autoBindProperty($name, $value[1]);
476 476
 					else
477 477
 					{
478 478
 						$setter='set'.$name;
@@ -497,15 +497,15 @@  discard block
 block discarded – undo
497 497
 					$component->$setter(Prado::localize($value[1]));
498 498
 					break;
499 499
 				default:	// an error if reaching here
500
-					throw new TConfigurationException('template_tag_unexpected',$name,$value[1]);
500
+					throw new TConfigurationException('template_tag_unexpected', $name, $value[1]);
501 501
 					break;
502 502
 			}
503 503
 		}
504 504
 		else
505 505
 		{
506
-			if (substr($name,0,2)=='js')
507
-				if ($value and !($value instanceof TJavaScriptLiteral))
508
-					$value = new TJavaScriptLiteral($value);
506
+			if(substr($name, 0, 2)=='js')
507
+				if($value and !($value instanceof TJavaScriptLiteral))
508
+					$value=new TJavaScriptLiteral($value);
509 509
 			$setter='set'.$name;
510 510
 			$component->$setter($value);
511 511
 		}
@@ -517,41 +517,41 @@  discard block
 block discarded – undo
517 517
 	 * @param string subproperty name
518 518
 	 * @param mixed subproperty initial value
519 519
 	 */
520
-	protected function configureSubProperty($component,$name,$value)
520
+	protected function configureSubProperty($component, $name, $value)
521 521
 	{
522 522
 		if(is_array($value))
523 523
 		{
524 524
 			switch($value[0])
525 525
 			{
526 526
 				case self::CONFIG_DATABIND:		// databinding
527
-					$component->bindProperty($name,$value[1]);
527
+					$component->bindProperty($name, $value[1]);
528 528
 					break;
529 529
 				case self::CONFIG_EXPRESSION:		// expression
530 530
 					if($component instanceof TControl)
531
-						$component->autoBindProperty($name,$value[1]);
531
+						$component->autoBindProperty($name, $value[1]);
532 532
 					else
533
-						$component->setSubProperty($name,$this->_tplControl->evaluateExpression($value[1]));
533
+						$component->setSubProperty($name, $this->_tplControl->evaluateExpression($value[1]));
534 534
 					break;
535 535
 				case self::CONFIG_TEMPLATE:
536
-					$component->setSubProperty($name,$value[1]);
536
+					$component->setSubProperty($name, $value[1]);
537 537
 					break;
538 538
 				case self::CONFIG_ASSET:		// asset URL
539 539
 					$url=$this->publishFilePath($this->_contextPath.DIRECTORY_SEPARATOR.$value[1]);
540
-					$component->setSubProperty($name,$url);
540
+					$component->setSubProperty($name, $url);
541 541
 					break;
542 542
 				case self::CONFIG_PARAMETER:		// application parameter
543
-					$component->setSubProperty($name,$this->getApplication()->getParameters()->itemAt($value[1]));
543
+					$component->setSubProperty($name, $this->getApplication()->getParameters()->itemAt($value[1]));
544 544
 					break;
545 545
 				case self::CONFIG_LOCALIZATION:
546
-					$component->setSubProperty($name,Prado::localize($value[1]));
546
+					$component->setSubProperty($name, Prado::localize($value[1]));
547 547
 					break;
548 548
 				default:	// an error if reaching here
549
-					throw new TConfigurationException('template_tag_unexpected',$name,$value[1]);
549
+					throw new TConfigurationException('template_tag_unexpected', $name, $value[1]);
550 550
 					break;
551 551
 			}
552 552
 		}
553 553
 		else
554
-			$component->setSubProperty($name,$value);
554
+			$component->setSubProperty($name, $value);
555 555
 	}
556 556
 
557 557
 	/**
@@ -579,7 +579,7 @@  discard block
 block discarded – undo
579 579
 	{
580 580
 		$input=$this->preprocess($input);
581 581
 		$tpl=&$this->_tpl;
582
-		$n=preg_match_all(self::REGEX_RULES,$input,$matches,PREG_SET_ORDER|PREG_OFFSET_CAPTURE);
582
+		$n=preg_match_all(self::REGEX_RULES, $input, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
583 583
 		$expectPropEnd=false;
584 584
 		$textStart=0;
585 585
 				$stack=array();
@@ -589,186 +589,186 @@  discard block
 block discarded – undo
589 589
 		$this->_directive=null;
590 590
 		try
591 591
 		{
592
-			for($i=0;$i<$n;++$i)
592
+			for($i=0; $i < $n; ++$i)
593 593
 			{
594 594
 				$match=&$matches[$i];
595 595
 				$str=$match[0][0];
596 596
 				$matchStart=$match[0][1];
597
-				$matchEnd=$matchStart+strlen($str)-1;
598
-				if(strpos($str,'<com:')===0)	// opening component tag
597
+				$matchEnd=$matchStart + strlen($str) - 1;
598
+				if(strpos($str, '<com:')===0)	// opening component tag
599 599
 				{
600 600
 					if($expectPropEnd)
601 601
 						continue;
602
-					if($matchStart>$textStart)
603
-						$tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart));
604
-					$textStart=$matchEnd+1;
602
+					if($matchStart > $textStart)
603
+						$tpl[$c++]=array($container, substr($input, $textStart, $matchStart - $textStart));
604
+					$textStart=$matchEnd + 1;
605 605
 					$type=$match[1][0];
606
-					$attributes=$this->parseAttributes($match[2][0],$match[2][1]);
607
-					$this->validateAttributes($type,$attributes);
608
-					$tpl[$c++]=array($container,$type,$attributes);
609
-					if($str[strlen($str)-2]!=='/')  // open tag
606
+					$attributes=$this->parseAttributes($match[2][0], $match[2][1]);
607
+					$this->validateAttributes($type, $attributes);
608
+					$tpl[$c++]=array($container, $type, $attributes);
609
+					if($str[strlen($str) - 2]!=='/')  // open tag
610 610
 					{
611
-						$stack[] = $type;
612
-						$container=$c-1;
611
+						$stack[]=$type;
612
+						$container=$c - 1;
613 613
 					}
614 614
 				}
615
-				else if(strpos($str,'</com:')===0)	// closing component tag
615
+				else if(strpos($str, '</com:')===0)	// closing component tag
616 616
 				{
617 617
 					if($expectPropEnd)
618 618
 						continue;
619
-					if($matchStart>$textStart)
620
-						$tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart));
621
-					$textStart=$matchEnd+1;
619
+					if($matchStart > $textStart)
620
+						$tpl[$c++]=array($container, substr($input, $textStart, $matchStart - $textStart));
621
+					$textStart=$matchEnd + 1;
622 622
 					$type=$match[1][0];
623 623
 
624 624
 					if(empty($stack))
625
-						throw new TConfigurationException('template_closingtag_unexpected',"</com:$type>");
625
+						throw new TConfigurationException('template_closingtag_unexpected', "</com:$type>");
626 626
 
627 627
 					$name=array_pop($stack);
628 628
 					if($name!==$type)
629 629
 					{
630
-						$tag=$name[0]==='@' ? '</prop:'.substr($name,1).'>' : "</com:$name>";
631
-						throw new TConfigurationException('template_closingtag_expected',$tag);
630
+						$tag=$name[0]==='@' ? '</prop:'.substr($name, 1).'>' : "</com:$name>";
631
+						throw new TConfigurationException('template_closingtag_expected', $tag);
632 632
 					}
633 633
 					$container=$tpl[$container][0];
634 634
 				}
635
-				else if(strpos($str,'<%@')===0)	// directive
635
+				else if(strpos($str, '<%@')===0)	// directive
636 636
 				{
637 637
 					if($expectPropEnd)
638 638
 						continue;
639
-					if($matchStart>$textStart)
640
-						$tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart));
641
-					$textStart=$matchEnd+1;
639
+					if($matchStart > $textStart)
640
+						$tpl[$c++]=array($container, substr($input, $textStart, $matchStart - $textStart));
641
+					$textStart=$matchEnd + 1;
642 642
 					if(isset($tpl[0]) || $this->_directive!==null)
643 643
 						throw new TConfigurationException('template_directive_nonunique');
644
-					$this->_directive=$this->parseAttributes($match[4][0],$match[4][1]);
644
+					$this->_directive=$this->parseAttributes($match[4][0], $match[4][1]);
645 645
 				}
646
-				else if(strpos($str,'<%')===0)	// expression
646
+				else if(strpos($str, '<%')===0)	// expression
647 647
 				{
648 648
 					if($expectPropEnd)
649 649
 						continue;
650
-					if($matchStart>$textStart)
651
-						$tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart));
652
-					$textStart=$matchEnd+1;
650
+					if($matchStart > $textStart)
651
+						$tpl[$c++]=array($container, substr($input, $textStart, $matchStart - $textStart));
652
+					$textStart=$matchEnd + 1;
653 653
 					$literal=trim($match[5][0]);
654 654
 					if($str[2]==='=')	// expression
655
-						$tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_EXPRESSION,$literal));
655
+						$tpl[$c++]=array($container, array(TCompositeLiteral::TYPE_EXPRESSION, $literal));
656 656
 					else if($str[2]==='%')  // statements
657
-						$tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_STATEMENTS,$literal));
657
+						$tpl[$c++]=array($container, array(TCompositeLiteral::TYPE_STATEMENTS, $literal));
658 658
 					else if($str[2]==='#')
659
-						$tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_DATABINDING,$literal));
659
+						$tpl[$c++]=array($container, array(TCompositeLiteral::TYPE_DATABINDING, $literal));
660 660
 					else if($str[2]==='$')
661
-						$tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_EXPRESSION,"\$this->getApplication()->getParameters()->itemAt('$literal')"));
661
+						$tpl[$c++]=array($container, array(TCompositeLiteral::TYPE_EXPRESSION, "\$this->getApplication()->getParameters()->itemAt('$literal')"));
662 662
 					else if($str[2]==='~')
663
-						$tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_EXPRESSION,"\$this->publishFilePath('$this->_contextPath/$literal')"));
663
+						$tpl[$c++]=array($container, array(TCompositeLiteral::TYPE_EXPRESSION, "\$this->publishFilePath('$this->_contextPath/$literal')"));
664 664
 					else if($str[2]==='/')
665
-						$tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_EXPRESSION,"rtrim(dirname(\$this->getApplication()->getRequest()->getApplicationUrl()), '\/').'/$literal'"));
665
+						$tpl[$c++]=array($container, array(TCompositeLiteral::TYPE_EXPRESSION, "rtrim(dirname(\$this->getApplication()->getRequest()->getApplicationUrl()), '\/').'/$literal'"));
666 666
 					else if($str[2]==='[')
667 667
 					{
668
-						$literal=strtr(trim(substr($literal,0,strlen($literal)-1)),array("'"=>"\'","\\"=>"\\\\"));
669
-						$tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_EXPRESSION,"Prado::localize('$literal')"));
668
+						$literal=strtr(trim(substr($literal, 0, strlen($literal) - 1)), array("'"=>"\'", "\\"=>"\\\\"));
669
+						$tpl[$c++]=array($container, array(TCompositeLiteral::TYPE_EXPRESSION, "Prado::localize('$literal')"));
670 670
 					}
671 671
 				}
672
-				else if(strpos($str,'<prop:')===0)	// opening property
672
+				else if(strpos($str, '<prop:')===0)	// opening property
673 673
 				{
674
-					if(strrpos($str,'/>')===strlen($str)-2)  //subproperties
674
+					if(strrpos($str, '/>')===strlen($str) - 2)  //subproperties
675 675
 					{
676 676
 						if($expectPropEnd)
677 677
 							continue;
678
-						if($matchStart>$textStart)
679
-							$tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart));
680
-						$textStart=$matchEnd+1;
678
+						if($matchStart > $textStart)
679
+							$tpl[$c++]=array($container, substr($input, $textStart, $matchStart - $textStart));
680
+						$textStart=$matchEnd + 1;
681 681
 						$prop=strtolower($match[6][0]);
682
-						$attrs=$this->parseAttributes($match[7][0],$match[7][1]);
682
+						$attrs=$this->parseAttributes($match[7][0], $match[7][1]);
683 683
 						$attributes=array();
684 684
 						foreach($attrs as $name=>$value)
685 685
 							$attributes[$prop.'.'.$name]=$value;
686 686
 						$type=$tpl[$container][1];
687
-						$this->validateAttributes($type,$attributes);
687
+						$this->validateAttributes($type, $attributes);
688 688
 						foreach($attributes as $name=>$value)
689 689
 						{
690 690
 							if(isset($tpl[$container][2][$name]))
691
-								throw new TConfigurationException('template_property_duplicated',$name);
691
+								throw new TConfigurationException('template_property_duplicated', $name);
692 692
 							$tpl[$container][2][$name]=$value;
693 693
 						}
694 694
 					}
695 695
 					else  // regular property
696 696
 					{
697 697
 						$prop=strtolower($match[3][0]);
698
-						$stack[] = '@'.$prop;
698
+						$stack[]='@'.$prop;
699 699
 						if(!$expectPropEnd)
700 700
 						{
701
-							if($matchStart>$textStart)
702
-								$tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart));
703
-							$textStart=$matchEnd+1;
701
+							if($matchStart > $textStart)
702
+								$tpl[$c++]=array($container, substr($input, $textStart, $matchStart - $textStart));
703
+							$textStart=$matchEnd + 1;
704 704
 							$expectPropEnd=true;
705 705
 						}
706 706
 					}
707 707
 				}
708
-				else if(strpos($str,'</prop:')===0)	// closing property
708
+				else if(strpos($str, '</prop:')===0)	// closing property
709 709
 				{
710 710
 					$prop=strtolower($match[3][0]);
711 711
 					if(empty($stack))
712
-						throw new TConfigurationException('template_closingtag_unexpected',"</prop:$prop>");
712
+						throw new TConfigurationException('template_closingtag_unexpected', "</prop:$prop>");
713 713
 					$name=array_pop($stack);
714 714
 					if($name!=='@'.$prop)
715 715
 					{
716
-						$tag=$name[0]==='@' ? '</prop:'.substr($name,1).'>' : "</com:$name>";
717
-						throw new TConfigurationException('template_closingtag_expected',$tag);
716
+						$tag=$name[0]==='@' ? '</prop:'.substr($name, 1).'>' : "</com:$name>";
717
+						throw new TConfigurationException('template_closingtag_expected', $tag);
718 718
 					}
719
-					if(($last=count($stack))<1 || $stack[$last-1][0]!=='@')
719
+					if(($last=count($stack)) < 1 || $stack[$last - 1][0]!=='@')
720 720
 					{
721
-						if($matchStart>$textStart)
721
+						if($matchStart > $textStart)
722 722
 						{
723
-							$value=substr($input,$textStart,$matchStart-$textStart);
724
-							if(substr($prop,-8,8)==='template')
725
-								$value=$this->parseTemplateProperty($value,$textStart);
723
+							$value=substr($input, $textStart, $matchStart - $textStart);
724
+							if(substr($prop, -8, 8)==='template')
725
+								$value=$this->parseTemplateProperty($value, $textStart);
726 726
 							else
727 727
 								$value=$this->parseAttribute($value);
728
-							if($container>=0)
728
+							if($container >= 0)
729 729
 							{
730 730
 								$type=$tpl[$container][1];
731
-								$this->validateAttributes($type,array($prop=>$value));
731
+								$this->validateAttributes($type, array($prop=>$value));
732 732
 								if(isset($tpl[$container][2][$prop]))
733
-									throw new TConfigurationException('template_property_duplicated',$prop);
733
+									throw new TConfigurationException('template_property_duplicated', $prop);
734 734
 								$tpl[$container][2][$prop]=$value;
735 735
 							}
736 736
 							else	// a property for the template control
737 737
 								$this->_directive[$prop]=$value;
738
-							$textStart=$matchEnd+1;
738
+							$textStart=$matchEnd + 1;
739 739
 						}
740 740
 						$expectPropEnd=false;
741 741
 					}
742 742
 				}
743
-				else if(strpos($str,'<!--')===0)	// comments
743
+				else if(strpos($str, '<!--')===0)	// comments
744 744
 				{
745 745
 					if($expectPropEnd)
746 746
 						throw new TConfigurationException('template_comments_forbidden');
747
-					if($matchStart>$textStart)
748
-						$tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart));
749
-					$textStart=$matchEnd+1;
747
+					if($matchStart > $textStart)
748
+						$tpl[$c++]=array($container, substr($input, $textStart, $matchStart - $textStart));
749
+					$textStart=$matchEnd + 1;
750 750
 				}
751 751
 				else
752
-					throw new TConfigurationException('template_matching_unexpected',$match);
752
+					throw new TConfigurationException('template_matching_unexpected', $match);
753 753
 			}
754 754
 			if(!empty($stack))
755 755
 			{
756 756
 				$name=array_pop($stack);
757
-				$tag=$name[0]==='@' ? '</prop:'.substr($name,1).'>' : "</com:$name>";
758
-				throw new TConfigurationException('template_closingtag_expected',$tag);
757
+				$tag=$name[0]==='@' ? '</prop:'.substr($name, 1).'>' : "</com:$name>";
758
+				throw new TConfigurationException('template_closingtag_expected', $tag);
759 759
 			}
760
-			if($textStart<strlen($input))
761
-				$tpl[$c++]=array($container,substr($input,$textStart));
760
+			if($textStart < strlen($input))
761
+				$tpl[$c++]=array($container, substr($input, $textStart));
762 762
 		}
763 763
 		catch(Exception $e)
764 764
 		{
765 765
 			if(($e instanceof TException) && ($e instanceof TTemplateException))
766 766
 				throw $e;
767 767
 			if($matchEnd===0)
768
-				$line=$this->_startingLine+1;
768
+				$line=$this->_startingLine + 1;
769 769
 			else
770
-				$line=$this->_startingLine+count(explode("\n",substr($input,0,$matchEnd+1)));
771
-			$this->handleException($e,$line,$input);
770
+				$line=$this->_startingLine + count(explode("\n", substr($input, 0, $matchEnd + 1)));
771
+			$this->handleException($e, $line, $input);
772 772
 		}
773 773
 
774 774
 		if($this->_directive===null)
@@ -785,9 +785,9 @@  discard block
 block discarded – undo
785 785
 				if($parent!==null)
786 786
 				{
787 787
 					if(count($merged[1])===1 && is_string($merged[1][0]))
788
-						$objects[$id-1]=array($merged[0],$merged[1][0]);
788
+						$objects[$id - 1]=array($merged[0], $merged[1][0]);
789 789
 					else
790
-						$objects[$id-1]=array($merged[0],new TCompositeLiteral($merged[1]));
790
+						$objects[$id - 1]=array($merged[0], new TCompositeLiteral($merged[1]));
791 791
 				}
792 792
 				if(isset($object[2]))
793 793
 				{
@@ -797,7 +797,7 @@  discard block
 block discarded – undo
797 797
 				else
798 798
 				{
799 799
 					$parent=$object[0];
800
-					$merged=array($parent,array($object[1]));
800
+					$merged=array($parent, array($object[1]));
801 801
 				}
802 802
 			}
803 803
 			else
@@ -806,9 +806,9 @@  discard block
 block discarded – undo
806 806
 		if($parent!==null)
807 807
 		{
808 808
 			if(count($merged[1])===1 && is_string($merged[1][0]))
809
-				$objects[$id]=array($merged[0],$merged[1][0]);
809
+				$objects[$id]=array($merged[0], $merged[1][0]);
810 810
 			else
811
-				$objects[$id]=array($merged[0],new TCompositeLiteral($merged[1]));
811
+				$objects[$id]=array($merged[0], new TCompositeLiteral($merged[1]));
812 812
 		}
813 813
 		$tpl=$objects;
814 814
 		return $objects;
@@ -819,31 +819,31 @@  discard block
 block discarded – undo
819 819
 	 * @param string the string to be parsed.
820 820
 	 * @return array attribute values indexed by names.
821 821
 	 */
822
-	protected function parseAttributes($str,$offset)
822
+	protected function parseAttributes($str, $offset)
823 823
 	{
824 824
 		if($str==='')
825 825
 			return array();
826 826
 		$pattern='/([\w\.\-]+)\s*=\s*(\'.*?\'|".*?"|<%.*?%>)/msS';
827 827
 		$attributes=array();
828
-		$n=preg_match_all($pattern,$str,$matches,PREG_SET_ORDER|PREG_OFFSET_CAPTURE);
829
-		for($i=0;$i<$n;++$i)
828
+		$n=preg_match_all($pattern, $str, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
829
+		for($i=0; $i < $n; ++$i)
830 830
 		{
831 831
 			$match=&$matches[$i];
832 832
 			$name=strtolower($match[1][0]);
833 833
 			if(isset($attributes[$name]))
834
-				throw new TConfigurationException('template_property_duplicated',$name);
834
+				throw new TConfigurationException('template_property_duplicated', $name);
835 835
 			$value=$match[2][0];
836
-			if(substr($name,-8,8)==='template')
836
+			if(substr($name, -8, 8)==='template')
837 837
 			{
838 838
 				if($value[0]==='\'' || $value[0]==='"')
839
-					$attributes[$name]=$this->parseTemplateProperty(substr($value,1,strlen($value)-2),$match[2][1]+1);
839
+					$attributes[$name]=$this->parseTemplateProperty(substr($value, 1, strlen($value) - 2), $match[2][1] + 1);
840 840
 				else
841
-					$attributes[$name]=$this->parseTemplateProperty($value,$match[2][1]);
841
+					$attributes[$name]=$this->parseTemplateProperty($value, $match[2][1]);
842 842
 			}
843 843
 			else
844 844
 			{
845 845
 				if($value[0]==='\'' || $value[0]==='"')
846
-					$attributes[$name]=$this->parseAttribute(substr($value,1,strlen($value)-2));
846
+					$attributes[$name]=$this->parseAttribute(substr($value, 1, strlen($value) - 2));
847 847
 				else
848 848
 					$attributes[$name]=$this->parseAttribute($value);
849 849
 			}
@@ -851,10 +851,10 @@  discard block
 block discarded – undo
851 851
 		return $attributes;
852 852
 	}
853 853
 
854
-	protected function parseTemplateProperty($content,$offset)
854
+	protected function parseTemplateProperty($content, $offset)
855 855
 	{
856
-		$line=$this->_startingLine+count(explode("\n",substr($this->_content,0,$offset)))-1;
857
-		return array(self::CONFIG_TEMPLATE,new TTemplate($content,$this->_contextPath,$this->_tplFile,$line,false));
856
+		$line=$this->_startingLine + count(explode("\n", substr($this->_content, 0, $offset))) - 1;
857
+		return array(self::CONFIG_TEMPLATE, new TTemplate($content, $this->_contextPath, $this->_tplFile, $line, false));
858 858
 	}
859 859
 
860 860
 	/**
@@ -864,12 +864,12 @@  discard block
 block discarded – undo
864 864
 	 */
865 865
 	protected function parseAttribute($value)
866 866
 	{
867
-		if(($n=preg_match_all('/<%[#=].*?%>/msS',$value,$matches,PREG_OFFSET_CAPTURE))>0)
867
+		if(($n=preg_match_all('/<%[#=].*?%>/msS', $value, $matches, PREG_OFFSET_CAPTURE)) > 0)
868 868
 		{
869 869
 			$isDataBind=false;
870 870
 			$textStart=0;
871 871
 			$expr='';
872
-			for($i=0;$i<$n;++$i)
872
+			for($i=0; $i < $n; ++$i)
873 873
 			{
874 874
 				$match=$matches[0][$i];
875 875
 				$token=$match[0];
@@ -877,114 +877,114 @@  discard block
 block discarded – undo
877 877
 				$length=strlen($token);
878 878
 				if($token[2]==='#')
879 879
 					$isDataBind=true;
880
-				if($offset>$textStart)
881
-					$expr.=".'".strtr(substr($value,$textStart,$offset-$textStart),array("'"=>"\\'","\\"=>"\\\\"))."'";
882
-				$expr.='.('.substr($token,3,$length-5).')';
883
-				$textStart=$offset+$length;
880
+				if($offset > $textStart)
881
+					$expr.=".'".strtr(substr($value, $textStart, $offset - $textStart), array("'"=>"\\'", "\\"=>"\\\\"))."'";
882
+				$expr.='.('.substr($token, 3, $length - 5).')';
883
+				$textStart=$offset + $length;
884 884
 			}
885 885
 			$length=strlen($value);
886
-			if($length>$textStart)
887
-				$expr.=".'".strtr(substr($value,$textStart,$length-$textStart),array("'"=>"\\'","\\"=>"\\\\"))."'";
886
+			if($length > $textStart)
887
+				$expr.=".'".strtr(substr($value, $textStart, $length - $textStart), array("'"=>"\\'", "\\"=>"\\\\"))."'";
888 888
 			if($isDataBind)
889
-				return array(self::CONFIG_DATABIND,ltrim($expr,'.'));
889
+				return array(self::CONFIG_DATABIND, ltrim($expr, '.'));
890 890
 			else
891
-				return array(self::CONFIG_EXPRESSION,ltrim($expr,'.'));
891
+				return array(self::CONFIG_EXPRESSION, ltrim($expr, '.'));
892 892
 		}
893
-		else if(preg_match('/\\s*(<%~.*?%>|<%\\$.*?%>|<%\\[.*?\\]%>|<%\/.*?%>)\\s*/msS',$value,$matches) && $matches[0]===$value)
893
+		else if(preg_match('/\\s*(<%~.*?%>|<%\\$.*?%>|<%\\[.*?\\]%>|<%\/.*?%>)\\s*/msS', $value, $matches) && $matches[0]===$value)
894 894
 		{
895 895
 			$value=$matches[1];
896 896
 			if($value[2]==='~')
897
-				return array(self::CONFIG_ASSET,trim(substr($value,3,strlen($value)-5)));
897
+				return array(self::CONFIG_ASSET, trim(substr($value, 3, strlen($value) - 5)));
898 898
 			elseif($value[2]==='[')
899
-				return array(self::CONFIG_LOCALIZATION,trim(substr($value,3,strlen($value)-6)));
899
+				return array(self::CONFIG_LOCALIZATION, trim(substr($value, 3, strlen($value) - 6)));
900 900
 			elseif($value[2]==='$')
901
-				return array(self::CONFIG_PARAMETER,trim(substr($value,3,strlen($value)-5)));
901
+				return array(self::CONFIG_PARAMETER, trim(substr($value, 3, strlen($value) - 5)));
902 902
 			elseif($value[2]==='/') {
903
-				$literal = trim(substr($value,3,strlen($value)-5));
904
-				return array(self::CONFIG_EXPRESSION,"rtrim(dirname(\$this->getApplication()->getRequest()->getApplicationUrl()), '\/').'/$literal'");
903
+				$literal=trim(substr($value, 3, strlen($value) - 5));
904
+				return array(self::CONFIG_EXPRESSION, "rtrim(dirname(\$this->getApplication()->getRequest()->getApplicationUrl()), '\/').'/$literal'");
905 905
 			}
906 906
 		}
907 907
 		else
908 908
 			return $value;
909 909
 	}
910 910
 
911
-	protected function validateAttributes($type,$attributes)
911
+	protected function validateAttributes($type, $attributes)
912 912
 	{
913 913
 		Prado::using($type);
914
-		if(($pos=strrpos($type,'.'))!==false)
915
-			$className=substr($type,$pos+1);
914
+		if(($pos=strrpos($type, '.'))!==false)
915
+			$className=substr($type, $pos + 1);
916 916
 		else
917 917
 			$className=$type;
918 918
 		$class=new ReflectionClass($className);
919
-		if(is_subclass_of($className,'TControl') || $className==='TControl')
919
+		if(is_subclass_of($className, 'TControl') || $className==='TControl')
920 920
 		{
921 921
 			foreach($attributes as $name=>$att)
922 922
 			{
923
-				if(($pos=strpos($name,'.'))!==false)
923
+				if(($pos=strpos($name, '.'))!==false)
924 924
 				{
925 925
 					// a subproperty, so the first segment must be readable
926
-					$subname=substr($name,0,$pos);
926
+					$subname=substr($name, 0, $pos);
927 927
 					if(!$class->hasMethod('get'.$subname))
928
-						throw new TConfigurationException('template_property_unknown',$type,$subname);
928
+						throw new TConfigurationException('template_property_unknown', $type, $subname);
929 929
 				}
930
-				else if(strncasecmp($name,'on',2)===0)
930
+				else if(strncasecmp($name, 'on', 2)===0)
931 931
 				{
932 932
 					// an event
933 933
 					if(!$class->hasMethod($name))
934
-						throw new TConfigurationException('template_event_unknown',$type,$name);
934
+						throw new TConfigurationException('template_event_unknown', $type, $name);
935 935
 					else if(!is_string($att))
936
-						throw new TConfigurationException('template_eventhandler_invalid',$type,$name);
936
+						throw new TConfigurationException('template_eventhandler_invalid', $type, $name);
937 937
 				}
938 938
 				else
939 939
 				{
940 940
 					// a simple property
941
-					if (! ($class->hasMethod('set'.$name) || $class->hasMethod('setjs'.$name) || $this->isClassBehaviorMethod($class,'set'.$name)) )
941
+					if(!($class->hasMethod('set'.$name) || $class->hasMethod('setjs'.$name) || $this->isClassBehaviorMethod($class, 'set'.$name)))
942 942
 					{
943
-						if ($class->hasMethod('get'.$name) || $class->hasMethod('getjs'.$name))
944
-							throw new TConfigurationException('template_property_readonly',$type,$name);
943
+						if($class->hasMethod('get'.$name) || $class->hasMethod('getjs'.$name))
944
+							throw new TConfigurationException('template_property_readonly', $type, $name);
945 945
 						else
946
-							throw new TConfigurationException('template_property_unknown',$type,$name);
946
+							throw new TConfigurationException('template_property_unknown', $type, $name);
947 947
 					}
948 948
 					else if(is_array($att) && $att[0]!==self::CONFIG_EXPRESSION)
949 949
 					{
950
-						if(strcasecmp($name,'id')===0)
951
-							throw new TConfigurationException('template_controlid_invalid',$type);
952
-						else if(strcasecmp($name,'skinid')===0)
953
-							throw new TConfigurationException('template_controlskinid_invalid',$type);
950
+						if(strcasecmp($name, 'id')===0)
951
+							throw new TConfigurationException('template_controlid_invalid', $type);
952
+						else if(strcasecmp($name, 'skinid')===0)
953
+							throw new TConfigurationException('template_controlskinid_invalid', $type);
954 954
 					}
955 955
 				}
956 956
 			}
957 957
 		}
958
-		else if(is_subclass_of($className,'TComponent') || $className==='TComponent')
958
+		else if(is_subclass_of($className, 'TComponent') || $className==='TComponent')
959 959
 		{
960 960
 			foreach($attributes as $name=>$att)
961 961
 			{
962 962
 				if(is_array($att) && ($att[0]===self::CONFIG_DATABIND))
963
-					throw new TConfigurationException('template_databind_forbidden',$type,$name);
964
-				if(($pos=strpos($name,'.'))!==false)
963
+					throw new TConfigurationException('template_databind_forbidden', $type, $name);
964
+				if(($pos=strpos($name, '.'))!==false)
965 965
 				{
966 966
 					// a subproperty, so the first segment must be readable
967
-					$subname=substr($name,0,$pos);
967
+					$subname=substr($name, 0, $pos);
968 968
 					if(!$class->hasMethod('get'.$subname))
969
-						throw new TConfigurationException('template_property_unknown',$type,$subname);
969
+						throw new TConfigurationException('template_property_unknown', $type, $subname);
970 970
 				}
971
-				else if(strncasecmp($name,'on',2)===0)
972
-					throw new TConfigurationException('template_event_forbidden',$type,$name);
971
+				else if(strncasecmp($name, 'on', 2)===0)
972
+					throw new TConfigurationException('template_event_forbidden', $type, $name);
973 973
 				else
974 974
 				{
975 975
 					// id is still alowed for TComponent, even if id property doesn't exist
976
-					if(strcasecmp($name,'id')!==0 && !($class->hasMethod('set'.$name) || $this->isClassBehaviorMethod($class,'set'.$name)))
976
+					if(strcasecmp($name, 'id')!==0 && !($class->hasMethod('set'.$name) || $this->isClassBehaviorMethod($class, 'set'.$name)))
977 977
 					{
978 978
 						if($class->hasMethod('get'.$name))
979
-							throw new TConfigurationException('template_property_readonly',$type,$name);
979
+							throw new TConfigurationException('template_property_readonly', $type, $name);
980 980
 						else
981
-							throw new TConfigurationException('template_property_unknown',$type,$name);
981
+							throw new TConfigurationException('template_property_unknown', $type, $name);
982 982
 					}
983 983
 				}
984 984
 			}
985 985
 		}
986 986
 		else
987
-			throw new TConfigurationException('template_component_required',$type);
987
+			throw new TConfigurationException('template_component_required', $type);
988 988
 	}
989 989
 
990 990
 	/**
@@ -1003,28 +1003,28 @@  discard block
 block discarded – undo
1003 1003
 	 * @param int line number
1004 1004
 	 * @param string template string if no source file is used
1005 1005
 	 */
1006
-	protected function handleException($e,$line,$input=null)
1006
+	protected function handleException($e, $line, $input=null)
1007 1007
 	{
1008 1008
 		$srcFile=$this->_tplFile;
1009 1009
 
1010
-		if(($n=count($this->_includedFiles))>0) // need to adjust error row number and file name
1010
+		if(($n=count($this->_includedFiles)) > 0) // need to adjust error row number and file name
1011 1011
 		{
1012
-			for($i=$n-1;$i>=0;--$i)
1012
+			for($i=$n - 1; $i >= 0; --$i)
1013 1013
 			{
1014
-				if($this->_includeAtLine[$i]<=$line)
1014
+				if($this->_includeAtLine[$i] <= $line)
1015 1015
 				{
1016
-					if($line<$this->_includeAtLine[$i]+$this->_includeLines[$i])
1016
+					if($line < $this->_includeAtLine[$i] + $this->_includeLines[$i])
1017 1017
 					{
1018
-						$line=$line-$this->_includeAtLine[$i]+1;
1018
+						$line=$line - $this->_includeAtLine[$i] + 1;
1019 1019
 						$srcFile=$this->_includedFiles[$i];
1020 1020
 						break;
1021 1021
 					}
1022 1022
 					else
1023
-						$line=$line-$this->_includeLines[$i]+1;
1023
+						$line=$line - $this->_includeLines[$i] + 1;
1024 1024
 				}
1025 1025
 			}
1026 1026
 		}
1027
-		$exception=new TTemplateException('template_format_invalid',$e->getMessage());
1027
+		$exception=new TTemplateException('template_format_invalid', $e->getMessage());
1028 1028
 		$exception->setLineNumber($line);
1029 1029
 		if(!empty($srcFile))
1030 1030
 			$exception->setTemplateFile($srcFile);
@@ -1040,29 +1040,29 @@  discard block
 block discarded – undo
1040 1040
 	 */
1041 1041
 	protected function preprocess($input)
1042 1042
 	{
1043
-		if($n=preg_match_all('/<%include(.*?)%>/',$input,$matches,PREG_SET_ORDER|PREG_OFFSET_CAPTURE))
1043
+		if($n=preg_match_all('/<%include(.*?)%>/', $input, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE))
1044 1044
 		{
1045
-			for($i=0;$i<$n;++$i)
1045
+			for($i=0; $i < $n; ++$i)
1046 1046
 			{
1047
-				$filePath=Prado::getPathOfNamespace(trim($matches[$i][1][0]),TTemplateManager::TEMPLATE_FILE_EXT);
1047
+				$filePath=Prado::getPathOfNamespace(trim($matches[$i][1][0]), TTemplateManager::TEMPLATE_FILE_EXT);
1048 1048
 				if($filePath!==null && is_file($filePath))
1049 1049
 					$this->_includedFiles[]=$filePath;
1050 1050
 				else
1051 1051
 				{
1052
-					$errorLine=count(explode("\n",substr($input,0,$matches[$i][0][1]+1)));
1053
-					$this->handleException(new TConfigurationException('template_include_invalid',trim($matches[$i][1][0])),$errorLine,$input);
1052
+					$errorLine=count(explode("\n", substr($input, 0, $matches[$i][0][1] + 1)));
1053
+					$this->handleException(new TConfigurationException('template_include_invalid', trim($matches[$i][1][0])), $errorLine, $input);
1054 1054
 				}
1055 1055
 			}
1056 1056
 			$base=0;
1057
-			for($i=0;$i<$n;++$i)
1057
+			for($i=0; $i < $n; ++$i)
1058 1058
 			{
1059 1059
 				$ext=file_get_contents($this->_includedFiles[$i]);
1060 1060
 				$length=strlen($matches[$i][0][0]);
1061
-				$offset=$base+$matches[$i][0][1];
1062
-				$this->_includeAtLine[$i]=count(explode("\n",substr($input,0,$offset)));
1063
-				$this->_includeLines[$i]=count(explode("\n",$ext));
1064
-				$input=substr_replace($input,$ext,$offset,$length);
1065
-				$base+=strlen($ext)-$length;
1061
+				$offset=$base + $matches[$i][0][1];
1062
+				$this->_includeAtLine[$i]=count(explode("\n", substr($input, 0, $offset)));
1063
+				$this->_includeLines[$i]=count(explode("\n", $ext));
1064
+				$input=substr_replace($input, $ext, $offset, $length);
1065
+				$base+=strlen($ext) - $length;
1066 1066
 			}
1067 1067
 		}
1068 1068
 
@@ -1075,7 +1075,7 @@  discard block
 block discarded – undo
1075 1075
 	 * @param string $method
1076 1076
 	 * @return boolean
1077 1077
 	 */
1078
-	protected function isClassBehaviorMethod(ReflectionClass $class,$method)
1078
+	protected function isClassBehaviorMethod(ReflectionClass $class, $method)
1079 1079
 	{
1080 1080
 	  $component=new ReflectionClass('TComponent');
1081 1081
 	  $behaviors=$component->getStaticProperties();
@@ -1086,7 +1086,7 @@  discard block
 block discarded – undo
1086 1086
 	    if(strtolower($class->getShortName())!==$name && !$class->isSubclassOf($name)) continue;
1087 1087
 	    foreach($list as $param)
1088 1088
 	    {
1089
-	      if(method_exists($param->getBehavior(),$method))
1089
+	      if(method_exists($param->getBehavior(), $method))
1090 1090
 	        return true;
1091 1091
 	    }
1092 1092
 	  }
Please login to merge, or discard this patch.