Example #1
0
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     Type::check("org\\jecat\\framework\\ui\\xhtml\\Node", $aObject);
     $aAttributes = $aObject->attributes();
     if ($aAttributes->has("file")) {
         $sFileName = '"' . addslashes($aAttributes->string("file")) . '"';
     } else {
         if (!($aFileVal = $aAttributes->anonymous())) {
             throw new Exception("include 节点缺少file属性(line:%d)", $aObject->line());
         }
         $sFileName = '"' . addslashes($aFileVal->source()) . '"';
     }
     // 是否继承父模板中的变量
     $bExtendParentVars = $aAttributes->has("vars") ? $aAttributes->bool('vars') : true;
     // start
     $aDev->write("\r\n");
     // variables
     if (!$bExtendParentVars) {
         $aDev->write("\$__include_aVariables = new \\org\\jecat\\framework\\util\\DataSrc() ; \r\n");
         $aDev->write("\$__include_aVariables->addChild(\$aVariables) ;");
     } else {
         $aDev->write("\$__include_aVariables = \$aVariables ; \r\n");
     }
     // other variables
     foreach ($aAttributes as $sName => $aValue) {
         if (substr($sName, 0, 4) == 'var.' and $sVarName = substr($sName, 4)) {
             $sVarName = '"' . addslashes($sVarName) . '"';
             //$sValue = ExpressionCompiler::compileExpression($aValue->source(),$aObjectContainer->variableDeclares()) ;
             $sValue = $aAttributes->get($sName);
             $aDev->write("\$__include_aVariables->set({$sVarName},{$sValue}) ; \r\n");
         }
     }
     $aDev->write("\$this->display({$sFileName},\$__include_aVariables,\$aDevice) ; ");
 }
Example #2
0
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     Type::check("org\\jecat\\framework\\ui\\xhtml\\Node", $aObject);
     $aDev->write('break ;');
     // 						 . ExpressionCompiler::compileExpression ( $aObject->attributes ()->source (), $aObjectContainer->variableDeclares() )
     // 						 . ';' );
 }
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     Type::check("org\\jecat\\framework\\ui\\xhtml\\Node", $aObject);
     $aAttributes = $aObject->attributes();
     if ($aAttributes->has("name")) {
         $sSubTemplateName = $aAttributes->string("name");
     } else {
         if (!($aNameVal = $aAttributes->anonymous())) {
             throw new Exception("subtemplate:define 节点缺少name属性(line:%d)", $aObject->line());
         }
         $sSubTemplateName = $aNameVal->source();
     }
     if (!is_callable($sSubTemplateName, true)) {
         throw new Exception("subtemplate:define 节点的name属性使用了无效的字符:%d", $sSubTemplateName);
     }
     $aDev->write("\r\n\r\n// -- subtemplate start ----------------------");
     $aDev->write("function __subtemplate_{$sSubTemplateName}(\$aVariables,\$aDevice){ ");
     // 准备 VariableDeclares
     $aOldVars = $aObjectContainer->variableDeclares();
     $aDeclareVariables = new VariableDeclares();
     $aObjectContainer->setVariableDeclares($aDeclareVariables);
     $aBuff = new OutputStreamBuffer();
     $aDev->write($aBuff);
     // 编译子对像
     $this->compileChildren($aObject, $aObjectContainer, $aDev, $aCompilerManager);
     // 声明用到的变量
     $aDeclareVariables->make($aBuff);
     $aObjectContainer->setVariableDeclares($aOldVars);
     $aDev->write("}// -- subtemplate end ----------------------\r\n\r\n");
 }
Example #4
0
 /**
  * $aObject 这是一个Node对象.它是模板引擎分析模板文件后的产品之一.Node对象包含了标签中的所有内容,包括Node的类型,内容,参数,等等,这些信息都是模板引擎分析模板得来.
  * 			比如这个if标签,你可以通过Node对象拿到它的源码,if的模板源码类似:
  * 			<if '(bool)$nTrue'>
  * 				<span>true</span>
  * 			</if>
  * 			也可以取得if标签的参数,if标签的参数就是上面源码中if后面的部分:
  * 			(bool)$nTrue
  * $aDev 输出设备,一般指网页
  * $aCompilerManager 编译管理器
  */
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     //确保传入的$aObject参数是node对象
     Type::check("org\\jecat\\framework\\ui\\xhtml\\Node", $aObject);
     //以下是编译过程
     //把<if>标签转换成php代码,也就是"if("
     //获得<if>标签中的条件语句,原封不动的放到if后面的括号中充当条件
     //但是这里并没有给代码块结尾,因为结尾在别的编译器中了,对于if标签来说,它的结尾工作放在</if>编译器那里了.是的,if标签是至少需要两个编译器才能完整编译
     $aDev->write('if(' . ExpressionCompiler::compileExpression($aObject->attributes()->anonymous()->source(), $aObjectContainer->variableDeclares()) . '){');
     /* 
      * 处理单行标签.单行格式是为了解决跨模板文件问题
      * if标签的多行格式是:
      * 			<if>
      * 			<else/>
      * 			</if>
      * 单行格式是
      * 			<if/>
      * 			<else/>
      * 			<if:end/>
      */
     if (!$aObject->headTag()->isSingle()) {
         $this->compileChildren($aObject, $aObjectContainer, $aDev, $aCompilerManager);
         $aDev->write("} ");
     }
 }
Example #5
0
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     if ($aObject instanceof \org\jecat\framework\ui\xhtml\ObjectBase and !$aObject->count()) {
         Assert::type("org\\jecat\\framework\\ui\\xhtml\\Text", $aObject, 'aObject');
         $sText = $aObject->source();
         // locale translate
         do {
             if (!trim($sText)) {
                 break;
             }
             // 排除 script/style 等标签中的内容
             if ($aParent = $aObject->parent() and $aParent instanceof Node and in_array(strtolower($aParent->tagName()), array('script', 'style'))) {
                 break;
             }
             // 仅 title alt 等属性
             if ($aObject instanceof AttributeValue and !in_array(strtolower($aObject->name()), array('title', 'alt'))) {
                 break;
             }
             // 过滤 注释 和 doctype 声明
             if (preg_match('/^\\s*<\\!.*>\\s*$/', $sText)) {
                 break;
             }
             $sText = Locale::singleton()->trans($sText, null, 'ui');
         } while (0);
         $aDev->output($sText);
     } else {
         $this->compileChildren($aObject, $aObjectContainer, $aDev, $aCompilerManager);
     }
 }
Example #6
0
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     Type::check("org\\jecat\\framework\\ui\\xhtml\\Node", $aObject);
     $aDev->write(' }elseif(');
     $aDev->write(ExpressionCompiler::compileExpression($aObject->attributes()->anonymous()->source(), $aObjectContainer->variableDeclares()));
     $aDev->write("){ ");
     $this->compileChildren($aObject, $aObjectContainer, $aDev, $aCompilerManager);
 }
Example #7
0
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     if ($aObject instanceof \org\jecat\framework\ui\xhtml\ObjectBase and !$aObject->count()) {
         $aDev->write($aObject->source());
     } else {
         $this->compileChildren($aObject, $aObjectContainer, $aDev, $aCompilerManager);
     }
 }
Example #8
0
 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 compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     Assert::type("org\\jecat\\framework\\ui\\xhtml\\Node", $aObject, 'aObject');
     $aAttrs = $aObject->attributes();
     if (!$aAttrs->has('id')) {
         throw new Exception("widget标签缺少必要属性:%s", 'id');
     }
     $sId = $aAttrs->get('id');
     $aDev->write("\$__ui_widget = \$aVariables->get('theView')->widget( {$sId} ) ;\r\n");
     $aDev->write("if(!\$__ui_widget){");
     $aDev->write("\tthrow new \\org\\jecat\\framework\\lang\\Exception('指定的widget id(%s)不存在,无法显示该widget的消息队列',array({$sId})) ; \r\n");
     $aDev->write("}else{");
     // 使用 <msgqueue> 节点内部的模板内容
     if ($aTemplate = $aObject->getChildNodeByTagName('template')) {
         $sOldMsgQueueVarVarName = '$' . parent::assignVariableName('_aOldMsgQueueVar');
         $aDev->write("\t{$sOldMsgQueueVarVarName}=\$aVariables->get('aMsgQueue') ;");
         $aDev->write("\t\$aVariables->set('aMsgQueue',\$__ui_widget->messageQueue()) ;");
         $this->compileChildren($aTemplate, $aObjectContainer, $aDev, $aCompilerManager);
         $aDev->write("\t\$aVariables->set('aMsgQueue',{$sOldMsgQueueVarVarName}) ;");
     } else {
         $aDev->write("\tif( \$__ui_widget->messageQueue()->count() ){ \r\n");
         $aDev->write("\t\t\$__ui_widget->messageQueue()->display(\$this,\$aDevice) ;\r\n");
         $aDev->write("\t}\r\n");
     }
     $aDev->write("}");
 }
Example #10
0
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     Assert::type("org\\jecat\\framework\\ui\\xhtml\\Node", $aObject, 'aObject');
     if (!$aObjectContainer->variableDeclares()->hasDeclared('aStackForLoopIsEnableToRun')) {
         $aObjectContainer->variableDeclares()->declareVarible('aStackForLoopIsEnableToRun', 'new \\org\\jecat\\framework\\util\\Stack()');
     }
     $aAttrs = $aObject->attributes();
     $sIdx = $aAttrs->has('idx') ? $aAttrs->string('idx') : '';
     $sItem = $aAttrs->has('item') ? $aAttrs->string('item') : 'theModel';
     $sFor = $aAttrs->has('for') ? $aAttrs->get('for') : "\$aVariables->get('theModel')";
     $aDev->write("if(\$aForModel={$sFor}){\r\n");
     if ($sIdx) {
         $aDev->write("\t\${$sIdx}=0;\r\n");
     }
     $aDev->write("\t\$aStackForLoopIsEnableToRun->put(false);");
     $aDev->write("\t\tforeach(\$aForModel->childIterator() as \$__aChildModel){\r\n");
     $aDev->write("\t\t\t\$aVariables->set('{$sItem}',\$__aChildModel) ;\r\n\t\t\$bLoopIsEnableToRun = & \$aStackForLoopIsEnableToRun->getRef();\r\n\t\t\$bLoopIsEnableToRun = true;\r\n");
     if ($sIdx) {
         $aDev->write("\t\t\t\$aVariables->set('{$sIdx}',\${$sIdx}++) ;\r\n");
     }
     if (!$aObject->headTag()->isSingle()) {
         $this->compileChildren($aObject, $aObjectContainer, $aDev, $aCompilerManager);
         $aDev->write("\t}\r\n}\r\n");
     }
 }
Example #11
0
 /**
  * @return ICompiled
  */
 public function compile(ObjectContainer $aObjectContainer, TargetCodeOutputStream $aTargetCodeStream)
 {
     // 变量声明 buffer
     $aBuffVarsDeclare = new OutputStreamBuffer();
     $aTargetCodeStream->write($aBuffVarsDeclare);
     // 编译正文
     foreach ($aObjectContainer->iterator() as $aObject) {
         $aCompiler = $this->compiler($aObject);
         if ($aCompiler) {
             $aCompiler->compile($aObject, $aObjectContainer, $aTargetCodeStream, $this);
         }
     }
     // 变量声明
     $aObjectContainer->variableDeclares()->make($aBuffVarsDeclare);
 }
Example #12
0
 /**
  * @param sPath string 前后都没有/
  */
 protected function writeSubMenu(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager, $sWidgetVarName)
 {
     $arrTagName = array('menu', 'item');
     foreach ($aObject->childElementsIterator() as $aChild) {
         if ($aChild instanceof Node and in_array($aChild->tagName(), $arrTagName)) {
             $aItemNode = $aChild;
             $aItemAttrs = $aItemNode->attributes();
             if ($aItemAttrs->has('id')) {
                 $sItemId = $aItemAttrs->string('id');
                 if ($aChild->tagName() === 'menu') {
                     $aAttrValue = AttributeValue::createInstance('instance', " \$aStack->get()->getMenuByPath( '{$sItemId}' ) ");
                 } else {
                     $aAttrValue = AttributeValue::createInstance('instance', " \$aStack->get()->getItemByPath( '{$sItemId}' ) ");
                 }
                 $aItemAttrs->add($aAttrValue);
                 $aAttrValue->setParent($aObjectContainer);
                 $aAttrValue = AttributeValue::createInstance('display', false);
                 $aItemAttrs->add($aAttrValue);
                 $aAttrValue->setParent($aObjectContainer);
             } else {
                 // @todo for add
             }
         }
     }
     if (!$aObjectContainer->variableDeclares()->hasDeclared('aStack')) {
         $aObjectContainer->variableDeclares()->declareVarible('aStack', 'new \\org\\jecat\\framework\\util\\Stack()');
     }
     $aDev->write("\t\$aStack->put({$sWidgetVarName});");
     $aDev->write("\t\$aVariables->aStack = \$aStack;");
     $this->compileChildren($aObject, $aObjectContainer, $aDev, $aCompilerManager);
     $aDev->write("\t\$aStack->out();");
 }
Example #13
0
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     Assert::type("org\\jecat\\framework\\ui\\xhtml\\Node", $aObject, 'aObject');
     // 使用 <msgqueue> 节点内部的模板内容
     if ($aTemplate = $aObject->getChildNodeByTagName('template')) {
         $sOldMsgQueueVarVarName = '$' . parent::assignVariableName('_aOldMsgQueueVar');
         $aDev->write("\t{$sOldMsgQueueVarVarName}=\$aVariables->get('aMsgQueue') ;");
         $aDev->write("\t\$aVariables->set('aMsgQueue',\$aVariables->get('theView')->messageQueue()) ;");
         $this->compileChildren($aTemplate, $aObjectContainer, $aDev, $aCompilerManager);
         $aDev->write("\t\$aVariables->set('aMsgQueue',{$sOldMsgQueueVarVarName}) ;");
     } else {
         $aDev->write("if( \$aVariables->get('theView')->messageQueue()->count() ){ \r\n");
         $aDev->write("\t\$aVariables->get('theView')->messageQueue()->display(\$this,\$aDevice) ;\r\n");
         $aDev->write("}\r\n");
     }
 }
Example #14
0
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     Type::check("org\\jecat\\framework\\ui\\xhtml\\Node", $aObject);
     if (!$aObjectContainer->variableDeclares()->hasDeclared('aStackForLoopIsEnableToRun')) {
         $aObjectContainer->variableDeclares()->declareVarible('aStackForLoopIsEnableToRun', 'new \\org\\jecat\\framework\\util\\Stack()');
     }
     $sIdxUserName = $aObject->attributes()->has('idx') ? $aObject->attributes()->get('idx') : '';
     $sIdxAutoName = NodeCompiler::assignVariableName('$__dowhile_idx_');
     if (!empty($sIdxUserName)) {
         $aDev->write(" {$sIdxAutoName} = -1; \$aStackForLoopIsEnableToRun->put(false);");
     }
     $aDev->write(" do{ \$bLoopIsEnableToRun = & \$aStackForLoopIsEnableToRun->getRef();\r\n\t\t\t\$bLoopIsEnableToRun = true;");
     if (!empty($sIdxUserName)) {
         $aDev->write(" {$sIdxAutoName}++; \r\n\t\t\t\t\t\t\t\$aVariables[{$sIdxUserName}]={$sIdxAutoName}; ");
     }
     $this->compileChildren($aObject, $aObjectContainer, $aDev, $aCompilerManager);
     $aDev->write(" }while(");
     $aDev->write(ExpressionCompiler::compileExpression($aObject->attributes()->anonymous()->source(), $aObjectContainer->variableDeclares()));
     $aDev->write(");");
 }
Example #15
0
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     Assert::type("org\\jecat\\framework\\ui\\xhtml\\Node", $aObject, 'aObject');
     if ($aTailTag = $aObject->tailTag()) {
         $aDev->write("if( !(\$aVariables->get('theView') instanceof \\org\\jecat\\framework\\mvc\\view\\IFormView) or \$aVariables->get('theView')->isShowForm() )\r\n{\r\n");
         $this->compileTag($aObject->headTag(), $aObjectContainer, $aDev, $aCompilerManager);
         $aDev->write("\tif(\$aVariables->get('theView') instanceof \\org\\jecat\\framework\\mvc\\view\\IFormView){\r\n");
         $aDev->write("\t\t");
         $aDev->output('<input type="hidden" name="');
         $aDev->write("\t\t\$aDevice->write( \$aVariables->get('theView')->htmlFormSignature() ) ;\r\n");
         $aDev->output('" value="1" />');
         $aDev->output('<input type="hidden" name="act" value="submit" />');
         $aDev->write("\t}\r\n");
         $this->compileChildren($aObject, $aObjectContainer, $aDev, $aCompilerManager);
         $this->compileTag($aTailTag, $aObjectContainer, $aDev, $aCompilerManager);
         $aDev->write("}\r\n");
     } else {
         throw new Exception("form 节点必须是成对标签形式(位置:%d行)。", $aObject->line());
     }
 }
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     Type::check("org\\jecat\\framework\\ui\\xhtml\\Node", $aObject);
     $aAttributes = $aObject->attributes();
     if ($aAttributes->has("name")) {
         $sSubTemplateName = $aAttributes->string("name");
     } else {
         if (!($aSubTemplateNameVal = $aAttributes->anonymous())) {
             throw new Exception("subtemplate:define 节点缺少name属性(line:%d)", $aObject->line());
         }
         $sSubTemplateName = $aSubTemplateNameVal->source();
     }
     if (!is_callable($sSubTemplateName, true)) {
         throw new Exception("subtemplate:define 节点的name属性使用了无效的字符:%d", $sSubTemplateName);
     }
     $sSubTemplateFuncName = '__subtemplate_' . $sSubTemplateName;
     $aDev->write("\r\n// -- call subtemplate:{$sSubTemplateName} start---------------------");
     // 是否继承父模板中的变量
     $bExtendParentVars = $aAttributes->has("vars") ? $aAttributes->bool('vars') : false;
     // variables
     if (!$bExtendParentVars) {
         $aDev->write("\$__subtemplate_aVariables = new \\org\\jecat\\framework\\util\\DataSrc() ;");
         $aDev->write("\$__subtemplate_aVariables->addChild(\$aVariables) ;");
     } else {
         $aDev->write("\$__subtemplate_aVariables = \$aVariables ;");
     }
     // other variables
     foreach ($aAttributes as $sName => $aValue) {
         if (substr($sName, 0, 4) == 'var.' and $sVarName = substr($sName, 4)) {
             $sVarName = '"' . addslashes($sVarName) . '"';
             $sValue = ExpressionCompiler::compileExpression($aValue->source(), $aObjectContainer->variableDeclares());
             $aDev->write("\$__subtemplate_aVariables->set({$sVarName},{$sValue}) ;");
         }
     }
     $aDev->write("if( !function_exists('{$sSubTemplateFuncName}') ){");
     $aDev->write("\t\$aDevice->write(\"正在调用无效的子模板:{$sSubTemplateName}\") ;");
     $aDev->write("} else {");
     $aDev->write("\tcall_user_func_array('{$sSubTemplateFuncName}',array(\$__subtemplate_aVariables,\$aDevice)) ;");
     $aDev->write("}");
     $aDev->write("// -- call subtemplate:{$sSubTemplateName} end ---------------------\r\n\r\n");
 }
Example #17
0
    public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
    {
        $aObject instanceof \org\jecat\framework\ui\xhtml\Node;
        if (!($sFuncName = $aObject->attributes()->string('function'))) {
            throw new Exception("render:js 节点缺少function属性(line:%d)", $aObject->line());
        }
        $aDev->output(<<<JSCODE
<script>
// 模板渲染函数
function {$sFuncName}(aVariables)
{
\t// 输出缓存对像
\tvar aDevice = {
\t\t_buffer: ''
\t\t, write: function(data){
\t\t\tthis._buffer+= data ;
\t\t}
\t}
JSCODE
);
        // 指定的模板文件
        if ($aObject->attributes()->string('template')) {
        } else {
            if ($aObject->tailTag()) {
                $aChildCompiledBuff = new TargetCodeOutputStream();
                $aChildCompiledBuff->useHereDoc(false);
                $this->compileChildren($aObject, $aObjectContainer, $aChildCompiledBuff, $aCompilerManager);
                $aJsBuff = new OutputStreamBuffer();
                JavascriptTranslaterFactory::singleton()->create()->compile(new InputStreamCache('<?php ' . $aChildCompiledBuff->bufferBytes(false)), $aJsBuff);
                $aDev->output($aJsBuff);
            } else {
            }
        }
        $aDev->output(<<<JSCODE

\treturn aDevice._buffer ;
}
</script>\t\t\t
JSCODE
);
    }
Example #18
0
 public function compile(IObject $aObject, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     $sSource = $aObject->source();
     //如果开头是变量
     if (substr($sSource, 0, 1) === '$') {
         //分辨是定义还是调用
         if ($nEqual = stripos($sSource, '=') and strlen(substr($sSource, $nEqual)) > 0) {
             //这是定义
             $sObjName = '$' . substr($sSource, 1, $nEqual - 1);
             $arrStrings = $this->getElementsBySource(substr($sSource, $nEqual + 1));
             $sArrName = '$' . NodeCompiler::assignVariableName('arrChangByLoopIndex');
             $aDev->write("{$sArrName} = " . var_export($arrStrings, true) . ";\n\t\t\t\t\t\t\t\tif(!isset({$sObjName}))\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t{$sObjName} = new org\\jecat\\framework\\ui\\xhtml\\compiler\\macro\\Cycle({$sArrName});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\$aVariables->set( '" . substr($sObjName, 1) . "' , {$sObjName} ) ;\n\t\t\t\t\t\t\t\t");
         } else {
             //这是调用
             $sObjName = '$' . substr($sSource, 1);
             $aDev->write("\n\t\t\t\t\t\t\t\tif(isset({$sObjName}))\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t{$sObjName}->printArr(\$aDevice);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t");
         }
     } else {
         $sArrName = '$' . NodeCompiler::assignVariableName('arrChangByLoopIndex');
         $sObjName = '$' . NodeCompiler::assignVariableName('aStrChangByLoopIndex');
         $aDev->write("{$sArrName} = " . var_export($this->getElementsBySource($sSource), true) . ";\n\t\t\t\tif(!isset({$sObjName}))\n\t\t\t\t{\n\t\t\t\t\t{$sObjName} = new org\\jecat\\framework\\ui\\xhtml\\compiler\\macro\\Cycle({$sArrName});\n\t\t\t\t}\n\t\t\t\t{$sObjName}->printArr(\$aDevice);\n\t\t\t\t\$aVariables->set( '" . substr($sObjName, 1) . "' ,{$sObjName} ) ;\n\t\t\t");
     }
 }
Example #19
0
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     Type::check("org\\jecat\\framework\\ui\\xhtml\\Node", $aObject);
     $aAttrs = $aObject->attributes();
     $sType = strtolower($aAttrs->string('type'));
     if (in_array($sType, array('text/php', 'php'))) {
         foreach ($aObject->iterator() as $aChild) {
             if ($aChild instanceof AttributeValue) {
                 continue;
             }
             $aDev->write(ExpressionCompiler::compileExpression($aChild->source(), $aObjectContainer->variableDeclares(), false, true));
         }
     } else {
         if ($aAttrs->has('src') and !$aAttrs->bool('ignore')) {
             $sSrc = $aAttrs->get('src');
             $aDev->preprocessStream()->write("\\org\\jecat\\framework\\resrc\\HtmlResourcePool::singleton()->addRequire({$sSrc},\\org\\jecat\\framework\\resrc\\HtmlResourcePool::RESRC_JS) ;");
             // 清除后文中的空白字符
             ClearCompiler::clearAfterWhitespace($aObject);
         } else {
             parent::compile($aObject, $aObjectContainer, $aDev, $aCompilerManager);
         }
     }
 }
Example #20
0
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     Assert::type("org\\jecat\\framework\\ui\\xhtml\\Node", $aObject, 'aObject');
     $aAttrs = $aObject->attributes();
     if ($aAttrs->has('name')) {
         $sName = $aAttrs->get('name');
     } else {
         $aIterator = $aObject->iterator();
         if (!($aFirst = $aIterator->current())) {
             throw new Exception("%s 对象却少数据名称", $aObject->tagName());
         }
         $sName = '"' . addslashes($aFirst->source()) . '"';
     }
     $aDev->write("if(\$theModel=\$aVariables->get('theModel')){\r\n");
     $aDev->write("\t\$aDevice->write(\$theModel->data({$sName})) ;\r\n");
     $aDev->write("}\r\n");
 }
Example #21
0
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     Assert::type("org\\jecat\\framework\\ui\\xhtml\\Node", $aObject, 'aObject');
     $aAttrs = $aObject->attributes();
     if (!$aAttrs->has('rel')) {
         $aAttrs->set('rel', 'stylesheet');
     }
     if ($aAttrs->has('src') and !$aAttrs->has('href')) {
         $aAttrs->set('href', $aAttrs->string('src'));
     }
     if (strtolower($aAttrs->string('rel')) == 'stylesheet' and !$aAttrs->bool('ignore')) {
         $sHref = $aAttrs->get('href');
         $aDev->preprocessStream()->write("jc\\resrc\\HtmlResourcePool::singleton()->addRequire({$sHref},jc\\resrc\\HtmlResourcePool::RESRC_CSS) ;");
         // 清除后文中的空白字符
         ClearCompiler::clearAfterWhitespace($aObject);
     } else {
         $this->compileTag($aObject->headTag(), $aObjectContainer, $aDev, $aCompilerManager);
         $this->compileChildren($aObject, $aObjectContainer, $aDev, $aCompilerManager);
         if ($aTailTag = $aObject->tailTag()) {
             $this->compileChildren($aObject, $aObjectContainer, $aDev, $aCompilerManager);
             $this->compileTag($aTailTag, $aObjectContainer, $aDev, $aCompilerManager);
         }
     }
 }
Example #22
0
 public function compile(IInputStream $aSourceInput, IOutputStream $aCompiledOutput, ObjectContainer $aObjectContainer = null, $bIntact = true)
 {
     if (!$aObjectContainer) {
         $aObjectContainer = new ObjectContainer();
     }
     // 解析
     $this->interpreters()->parse($aSourceInput, $aObjectContainer, $this);
     // 编译
     $aTargetCodeStream = new TargetCodeOutputStream();
     if ($bIntact) {
         $aTargetCodeStream->start();
     }
     $this->compilers()->compile($aObjectContainer, $aTargetCodeStream);
     if ($bIntact) {
         $aTargetCodeStream->finish();
     }
     $aCompiledOutput->write($aTargetCodeStream->bufferBytes(true));
 }
Example #23
0
 protected function writeEnd(TargetCodeOutputStream $aDev)
 {
     $aDev->write("}");
     $aDev->write("//// ---------------xxx------------------------------------\r\n");
 }
Example #24
0
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     Assert::type("org\\jecat\\framework\\ui\\xhtml\\weave\\WeaveinObject", $aObject, 'aObject');
     $aDev->write($aObject->compiled());
 }
Example #25
0
 public function output(TargetCodeOutputStream $aDev)
 {
     $aDev->output(highlight_string($this->sCode, true));
 }
Example #26
0
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     Type::check("org\\jecat\\framework\\ui\\xhtml\\Node", $aObject);
     $aDev->write("}");
 }
Example #27
0
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     $aDev->write(self::compileExpression($aObject->source(), $aObjectContainer->variableDeclares()));
 }
Example #28
0
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     if (!$aObjectContainer->variableDeclares()->hasDeclared('aStackForLoopIsEnableToRun')) {
         $aObjectContainer->variableDeclares()->declareVarible('aStackForLoopIsEnableToRun', 'new \\org\\jecat\\framework\\util\\Stack()');
     }
     Type::check("org\\jecat\\framework\\ui\\xhtml\\Node", $aObject);
     $aAttrs = $aObject->attributes();
     if ($aAttrs->has('for')) {
         $sForUserExp = $aAttrs->expression('for');
     } else {
         throw new Exception("foreach tag can not run without 'for' attribute");
     }
     $sKeyUserName = $aAttrs->has('key') ? $aAttrs->get('key') : '';
     $sItemUserName = $aAttrs->has('item') ? $aAttrs->get('item') : '';
     $bItemRef = $aAttrs->has('item.ref') ? $aAttrs->bool('item.ref') : false;
     $sIdxUserName = $aAttrs->has('idx') ? $aAttrs->get('idx') : '';
     $sForAutoName = NodeCompiler::assignVariableName('$__foreach_Arr_');
     $sItemAutoName = NodeCompiler::assignVariableName('$__foreach_item_');
     $sKeyAutoName = NodeCompiler::assignVariableName('$__foreach_key_');
     $sIdxAutoName = NodeCompiler::assignVariableName('$__foreach_idx_');
     $sItemRef = $bItemRef ? '&' : '';
     $aDev->write("\r\n// foreach start ");
     $aDev->write("{$sForAutoName} = {$sForUserExp};\r\n\$aStackForLoopIsEnableToRun->put(false);\r\n{$sIdxAutoName} = -1;\r\nforeach({$sForAutoName} as {$sKeyAutoName}=>{$sItemRef}{$sItemAutoName}){");
     $aDev->write("\$bLoopIsEnableToRun = & \$aStackForLoopIsEnableToRun->getRef();\r\n\t\$bLoopIsEnableToRun = true;\r\n\t{$sIdxAutoName}++;");
     if (!empty($sKeyUserName)) {
         $aDev->write("\t\t\$aVariables[{$sKeyUserName}]={$sKeyAutoName}; ");
     }
     if (!empty($sItemUserName)) {
         $aDev->write("\t\t\$aVariables[{$sItemUserName}]={$sItemAutoName}; ");
     }
     if (!empty($sIdxUserName)) {
         $aDev->write("\t\t\$aVariables[{$sIdxUserName}]={$sIdxAutoName}; ");
     }
     //是否是单行标签?
     if (!$aObject->headTag()->isSingle()) {
         //循环体,可能会包含foreach:else标签
         $this->compileChildren($aObject, $aObjectContainer, $aDev, $aCompilerManager);
         $aDev->write("}\r\n");
         // end if   (如果foreach的内容包含foreach:else标签,则此处为foreach:else的end)
     }
 }
Example #29
0
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     Assert::type("org\\jecat\\framework\\ui\\xhtml\\Node", $aObject, 'aObject');
     if (!$aObjectContainer->variableDeclares()->hasDeclared('aStackForLoopIsEnableToRun')) {
         $aObjectContainer->variableDeclares()->declareVarible('aStackForLoopIsEnableToRun', 'new \\org\\jecat\\framework\\util\\Stack()');
     }
     $aAttrs = $aObject->attributes();
     $sStartValue = $aAttrs->has("start") ? $aAttrs->expression("start") : '0';
     $sEndValue = $aAttrs->expression("end");
     $sStepValue = $aAttrs->has("step") ? $aAttrs->expression("step") : '1';
     $sVarAutoName = NodeCompiler::assignVariableName('$__loop_var_');
     $sIdxAutoName = NodeCompiler::assignVariableName('$__loop_idx_');
     $sEndName = NodeCompiler::assignVariableName('$__loop_end_');
     $sStepName = NodeCompiler::assignVariableName('$__loop_step_');
     $aDev->write("\t\t{$sEndName}  = {$sEndValue} ; \n\t\t\t\t\t\t\t\t{$sStepName}  = {$sStepValue}  ;\n\t\t\t\t\t\t\t\t{$sIdxAutoName} = 0;\n\t\t\t\t\t\t\t\t\$aStackForLoopIsEnableToRun->put(false);\n\t\t\t\t\t\t\t\tfor( {$sVarAutoName} = {$sStartValue} ; {$sVarAutoName} <= {$sEndName} ; {$sVarAutoName} += {$sStepName} ){\n\t\t\t\t\t\t\t\t\$bLoopIsEnableToRun = & \$aStackForLoopIsEnableToRun->getRef();\n\t\t\t\t\t\t\t\t\$bLoopIsEnableToRun = true;  \n\t\t\t\t\t\t");
     if ($aAttrs->has("var")) {
         $sVarUserName = $aAttrs->string("var");
         $aDev->write("\t\t\t\$aVariables->{$sVarUserName} = {$sVarAutoName} ;");
     }
     if ($aAttrs->has("idx")) {
         $sIdxUserName = $aAttrs->string("idx");
         $aDev->write("\t\t\t\$aVariables->{$sIdxUserName} = {$sIdxAutoName} ;\n\t\t\t\t\t\t\t\t\t\t{$sIdxAutoName}++;");
     }
     // 		$aDev->write ( "\$bLoopIsEnableToRun = & \$aStackForLoopIsEnableToRun->getRef();
     // 			\$bLoopIsEnableToRun = true;" );
     if (!$aObject->headTag()->isSingle()) {
         $this->compileChildren($aObject, $aObjectContainer, $aDev, $aCompilerManager);
         $aDev->write('} ');
     }
 }
Example #30
0
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     $aDev->write("\$aDevice->write(\\org\\jecat\\framework\\resrc\\HtmlResourcePool::singleton()) ;\r\n");
 }