From 70944795827cffd1bd5a27a9c4a99eb1434f905f Mon Sep 17 00:00:00 2001 From: xue <> Date: Sat, 15 Apr 2006 14:35:46 +0000 Subject: Merge from branch 3.0 till 913. --- framework/Web/UI/TTemplateManager.php | 105 ++++------------------------------ 1 file changed, 10 insertions(+), 95 deletions(-) (limited to 'framework/Web/UI/TTemplateManager.php') diff --git a/framework/Web/UI/TTemplateManager.php b/framework/Web/UI/TTemplateManager.php index 7961a121..488a3a3b 100644 --- a/framework/Web/UI/TTemplateManager.php +++ b/framework/Web/UI/TTemplateManager.php @@ -397,7 +397,6 @@ class TTemplate extends TApplicationComponent implements ITemplate */ protected function configureProperty($component,$name,$value) { - $setter='set'.$name; if(is_array($value)) { switch($value[0]) @@ -406,19 +405,23 @@ class TTemplate extends TApplicationComponent implements ITemplate $component->bindProperty($name,$value[1]); break; case self::CONFIG_EXPRESSION: - $component->$setter($component->evaluateExpression($value[1])); + $component->autoBindProperty($name,$value[1]); break; case self::CONFIG_TEMPLATE: + $setter='set'.$name; $component->$setter($value[1]); break; case self::CONFIG_ASSET: // asset URL + $setter='set'.$name; $url=$this->publishFilePath($this->_contextPath.'/'.$value[1]); $component->$setter($url); break; case self::CONFIG_PARAMETER: // application parameter + $setter='set'.$name; $component->$setter($this->getApplication()->getParameters()->itemAt($value[1])); break; case self::CONFIG_LOCALIZATION: + $setter='set'.$name; $component->$setter(Prado::localize($value[1])); break; default: // an error if reaching here @@ -426,7 +429,10 @@ class TTemplate extends TApplicationComponent implements ITemplate } } else + { + $setter='set'.$name; $component->$setter($value); + } } /** @@ -817,7 +823,7 @@ class TTemplate extends TApplicationComponent implements ITemplate { foreach($attributes as $name=>$att) { - if(is_array($att) && $att[0]===self::CONFIG_DATABIND) + if(is_array($att) && ($att[0]===self::CONFIG_DATABIND || $att[0]===self::CONFIG_EXPRESSION)) throw new TConfigurationException('template_databind_forbidden',$type,$name); if(($pos=strpos($name,'.'))!==false) { @@ -846,95 +852,4 @@ class TTemplate extends TApplicationComponent implements ITemplate } } -/** - * TCompositeLiteral class - * - * TCompositeLiteral is used internally by {@link TTemplate} for representing - * consecutive static strings, expressions and statements. - * - * @author Qiang Xue - * @version $Revision: $ $Date: $ - * @package System.Web.UI - * @since 3.0 - */ -class TCompositeLiteral extends TComponent implements IRenderable, IBindable -{ - const TYPE_EXPRESSION=0; - const TYPE_STATEMENTS=1; - const TYPE_DATABINDING=2; - private $_container=null; - private $_items=array(); - private $_expressions=array(); - private $_statements=array(); - private $_bindings=array(); - - /** - * Constructor. - * @param array list of items to be represented by TCompositeLiteral - */ - public function __construct($items) - { - $this->_items=array(); - $this->_expressions=array(); - $this->_statements=array(); - foreach($items as $id=>$item) - { - if(is_array($item)) - { - if($item[0]===self::TYPE_EXPRESSION) - $this->_expressions[$id]=$item[1]; - else if($item[0]===self::TYPE_STATEMENTS) - $this->_statements[$id]=$item[1]; - else if($item[0]===self::TYPE_DATABINDING) - $this->_bindings[$id]=$item[1]; - $this->_items[$id]=''; - } - else - $this->_items[$id]=$item; - } - } - - /** - * @return TComponent container of this component. It serves as the evaluation context of expressions and statements. - */ - public function getContainer() - { - return $this->_container; - } - - /** - * @param TComponent container of this component. It serves as the evaluation context of expressions and statements. - */ - public function setContainer(TComponent $value) - { - $this->_container=$value; - } - - /** - * Renders the content stored in this component. - * This method is required by {@link IRenderable} - * @param ITextWriter - */ - public function render($writer) - { - $context=$this->_container===null?$this:$this->_container; - foreach($this->_expressions as $id=>$expression) - $this->_items[$id]=$context->evaluateExpression($expression); - foreach($this->_statements as $id=>$statement) - $this->_items[$id]=$context->evaluateStatements($statement); - $writer->write(implode('',$this->_items)); - } - - /** - * Performs databindings. - * This method is required by {@link IBindable} - */ - public function dataBind() - { - $context=$this->_container===null?$this:$this->_container; - foreach($this->_bindings as $id=>$binding) - $this->_items[$id]=$context->evaluateExpression($binding); - } -} - -?> \ No newline at end of file +?> -- cgit v1.2.3