protected function compileTag(Tag $aTag, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager) { $aDev->output('<'); if ($aTag->isTail()) { $aDev->output('/'); } $aDev->output($aTag->name()); // 属性 $aAttrs = $aTag->attributes(); foreach ($aAttrs->valueIterator() as $aAttrVal) { $aDev->output(' '); // 具名属性 if ($sName = $aAttrVal->name()) { $aDev->output($sName); $aDev->output('='); } $aDev->output($aAttrVal->quoteType()); if ($aAttrCompiler = $aCompilerManager->compiler($aAttrVal)) { $aAttrCompiler->compile($aAttrVal, $aObjectContainer, $aDev, $aCompilerManager); get_class($aAttrCompiler); } else { if ($sName) { $aDev->output(addcslashes($aAttrs->get($sName), $aAttrVal->quoteType() . '\\')); } else { $aDev->output(addcslashes($aAttrs->source(), $aAttrVal->quoteType() . '\\')); } } $aDev->output($aAttrVal->quoteType()); } if ($aTag->isSingle()) { $aDev->output(' /'); } $aDev->output('>'); }
public function active(IObject $aParent, string $aSource, &$nPosition) { $nLine = ObjectBase::getLine($aSource, $nPosition); $nStartPos = $nPosition; // 标签名称 if (!($sTagName = $this->parseTagName($aSource, $nPosition))) { throw new Exception("UI引擎在分析模板时遇到无效的xhtml节点:缺少节点名称(位置:%d行)", $nLine); } $aTag = new Tag($sTagName, null, 0, $nStartPos, 0, $nLine, ''); // 尾标签 if ($sTagName[0] == '/') { if (!$aParent instanceof Node) { throw new Exception("错误类型"); } $aTag->setTagType(Tag::TYPE_TAIL); $aTag->setName(substr($sTagName, 1)); $aParent->setTailTag($aTag); } else { $aTag->setTagType(Tag::TYPE_HEAD); $aNode = new Node($aTag); $aParent->add($aNode); } return $aTag; }