From 27478826035da62e1cba07833101b162558f895a Mon Sep 17 00:00:00 2001 From: xue <> Date: Thu, 4 May 2006 03:02:44 +0000 Subject: Merge from 3.0 branch till 1016. --- framework/Web/UI/TTemplateManager.php | 64 +++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 21 deletions(-) (limited to 'framework/Web/UI/TTemplateManager.php') diff --git a/framework/Web/UI/TTemplateManager.php b/framework/Web/UI/TTemplateManager.php index eac7c157..b29466ad 100644 --- a/framework/Web/UI/TTemplateManager.php +++ b/framework/Web/UI/TTemplateManager.php @@ -132,9 +132,7 @@ class TTemplateManager extends TModule * - directive: directive specifies the property values for the template owner. * It is in the format of <% property name-value pairs %> * - expressions: They are in the formate of <= PHP expression > and <% PHP statements > - * - comments: There are two kinds of comments, regular HTML comments and special template comments. - * The former is in the format of <!-- comments -->, which will be treated as text strings. - * The latter is in the format of <%* comments %>, which will be stripped out. + * - comments: Special template comments enclosed within <!-- comments --!> will be stripped out. * * Tags other than the above are not required to be well-formed. * @@ -152,13 +150,12 @@ class TTemplate extends TApplicationComponent implements ITemplate { /** * '' - template comments - * '' - HTML comments * '<\/?com:([\w\.]+)((?:\s*[\w\.]+=\'.*?\'|\s*[\w\.]+=".*?"|\s*[\w\.]+=<%.*?%>)*)\s*\/?>' - component tags * '<\/?prop:([\w\.]+)\s*>' - property tags * '<%@\s*((?:\s*[\w\.]+=\'.*?\'|\s*[\w\.]+=".*?")*)\s*%>' - directives * '<%[%#~\\$=\\[](.*?)%>' - expressions */ - const REGEX_RULES='/||<\/?com:([\w\.]+)((?:\s*[\w\.]+=\'.*?\'|\s*[\w\.]+=".*?"|\s*[\w\.]+=<%.*?%>)*)\s*\/?>|<\/?prop:([\w\.]+)\s*>|<%@\s*((?:\s*[\w\.]+=\'.*?\'|\s*[\w\.]+=".*?")*)\s*%>|<%[%#~\\$=\\[](.*?)%>/msS'; + const REGEX_RULES='/|<\/?com:([\w\.]+)((?:\s*[\w\.]+=\'.*?\'|\s*[\w\.]+=".*?"|\s*[\w\.]+=<%.*?%>)*)\s*\/?>|<\/?prop:([\w\.]+)\s*>|<%@\s*((?:\s*[\w\.]+=\'.*?\'|\s*[\w\.]+=".*?")*)\s*%>|<%[%#~\\$=\\[](.*?)%>/msS'; /** * Different configurations of component property/event/attribute @@ -280,6 +277,7 @@ class TTemplate extends TApplicationComponent implements ITemplate if(($page=$tplControl->getPage())===null) $page=$this->getService()->getRequestedPage(); $controls=array(); + $directChildren=array(); foreach($this->_tpl as $key=>$object) { if($object[0]===-1) @@ -315,7 +313,10 @@ class TTemplate extends TApplicationComponent implements ITemplate // apply attributes foreach($properties as $name=>$value) $this->configureControl($component,$name,$value); - $component->createdOnTemplate($parent); + if($parent===$tplControl) + $directChildren[]=$component; + else + $component->createdOnTemplate($parent); if($component->getAllowChildControls()) $controls[$key]=$component; } @@ -331,20 +332,45 @@ class TTemplate extends TApplicationComponent implements ITemplate } foreach($properties as $name=>$value) $this->configureComponent($component,$name,$value); - $parent->addParsedObject($component); + if($parent===$tplControl) + $directChildren[]=$component; + else + $parent->addParsedObject($component); } } - else if(is_string($object[1])) - $parent->addParsedObject($object[1]); else if($object[1] instanceof TCompositeLiteral) { - $o=clone $object[1]; - $o->setContainer($tplControl); - $parent->addParsedObject($o); + if($object[1] instanceof TCompositeLiteral) + { + // need to clone a new object because the one in template is reused + $o=clone $object[1]; + $o->setContainer($tplControl); + if($parent===$tplControl) + $directChildren[]=$o; + else + $parent->addParsedObject($o); + } + else + { + if($parent===$tplControl) + $directChildren[]=$object[1]; + else + $parent->addParsedObject($object[1]); + } } else throw new TConfigurationException('template_content_unexpected',(string)$object[1]); } + // delay setting parent till now because the parent may cause + // the child to do lifecycle catchup which may cause problem + // if the child needs its own child controls. + foreach($directChildren as $control) + { + if($control instanceof TControl) + $control->createdOnTemplate($tplControl); + else + $tplControl->addParsedObject($control); + } } /** @@ -640,15 +666,11 @@ class TTemplate extends TApplicationComponent implements ITemplate } else if(strpos($str,'')===strlen($str)-4) // template comments - { - if($expectPropEnd) - throw new TConfigurationException('template_comments_forbidden'); - if($matchStart>$textStart) - $tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart)); - $textStart=$matchEnd+1; - } - // else, HTML comments and we do nothing + if($expectPropEnd) + throw new TConfigurationException('template_comments_forbidden'); + if($matchStart>$textStart) + $tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart)); + $textStart=$matchEnd+1; } else throw new TConfigurationException('template_matching_unexpected',$match); -- cgit v1.2.3