示例#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) ; ");
 }
 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");
 }
示例#3
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);
 }
示例#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("} ");
     }
 }
示例#5
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");
     }
 }
示例#6
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() )
     // 						 . ';' );
 }
示例#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);
     }
 }
示例#8
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(");");
 }
 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");
 }
示例#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");
     }
 }
示例#11
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('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("}");
 }
示例#12
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");
     }
 }
示例#13
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);
 }
示例#14
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());
     }
 }
示例#15
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);
         }
     }
 }
示例#16
0
 protected function writeEnd(TargetCodeOutputStream $aDev)
 {
     $aDev->write("}");
     $aDev->write("//// ---------------xxx------------------------------------\r\n");
 }
示例#17
0
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     $sContents = trim($aObject->source());
     if ($sContents == '*.uri') {
         $aDev->write("\$aDevice->write(\$aVariables->get('theRequest')->uri()) ;");
     } else {
         if (substr($sContents, 0, 5) == '*.url') {
             $sPart = strlen($sContents) > 5 ? substr($sContents, 5) : '';
             switch ($sPart) {
                 case '':
                     $aDev->write("\$aDevice->write(\$aVariables->get('theRequest')->url()) ;");
                     break;
                 case '.scheme':
                     $aDev->write("\$aDevice->write(\$aVariables->get('theRequest')->urlScheme()) ;");
                     break;
                 case '.host':
                     $aDev->write("\$aDevice->write(\$aVariables->get('theRequest')->urlHost()) ;");
                     break;
                 case '.path':
                     $aDev->write("\$aDevice->write(\$aVariables->get('theRequest')->urlPath()) ;");
                     break;
                 case '.query':
                     $aDev->write("\$aDevice->write(\$aVariables->get('theRequest')->urlQuery()) ;");
                     break;
                 default:
                     break;
             }
         }
     }
 }
示例#18
0
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     Type::check("org\\jecat\\framework\\ui\\xhtml\\Node", $aObject);
     $aDev->write("\$aStackForLoopIsEnableToRun->out();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t");
 }
示例#19
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();");
 }
示例#20
0
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     $aDev->write("\$aDevice->write(\\org\\jecat\\framework\\resrc\\HtmlResourcePool::singleton()) ;\r\n");
 }
示例#21
0
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     $aDev->write(self::compileExpression($aObject->source(), $aObjectContainer->variableDeclares()));
 }
示例#22
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('} ');
     }
 }
示例#23
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());
 }
示例#24
0
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     Assert::type("org\\jecat\\framework\\ui\\xhtml\\Node", $aObject, 'aObject');
     $aDev->write("\r\n// display message queue -------------------------------------");
     // 确定需要display的 MessageQueue 对像
     // ----------------------
     if ($aObject->attributes()->has('for')) {
         $aDev->write("\$__ui_msgqueue = " . $aObject->attributes()->expression('for') . " ;");
     } else {
         $aDev->write("\$__ui_msgqueue = \$aVariables->get('theController')? \$aVariables->get('theController')->messageQueue(): null ;");
     }
     $aDev->write("if( \$__ui_msgqueue instanceof \\org\\jecat\\framework\\message\\IMessageQueueHolder ){");
     $aDev->write("\t\$__ui_msgqueue = \$__ui_msgqueue->messageQueue() ;");
     $aDev->write("}");
     $aDev->write("\\org\\jecat\\framework\\lang\\Assert::type( '\\\\org\\jecat\\framework\\\\message\\\\IMessageQueue',\$__ui_msgqueue);");
     // 确定使用的 template
     // ----------------------
     //  template 属性
     $sTemplate = $aObject->attributes()->has('template') ? $aObject->attributes()->get('template') : 'null';
     // <template> 内部字节点的模板内容
     $sIsSubtemplate = 'false';
     if ($aTemplate = $aObject->getChildNodeByTagName('template')) {
         $nSubtemplateIndex = (int) $aDev->properties()->get('nMessageQueueSubtemplateIndex') + 1;
         $aDev->properties()->set('nMessageQueueSubtemplateIndex', $nSubtemplateIndex);
         $sSubTemplateName = '__subtemplate_for_messagequeue_' . $nSubtemplateIndex;
         $aDev->write("if(!function_exists('{$sSubTemplateName}')){function {$sSubTemplateName}(\$aVariables,\$aDevice){");
         $this->compileChildren($aTemplate, $aObjectContainer, $aDev, $aCompilerManager);
         $aDev->write("}}");
         $sTemplate = "'{$sSubTemplateName}'";
         $sIsSubtemplate = 'true';
     }
     // 显示模式
     // -------------------------------
     switch ($aObject->attributes()->has('mode') ? strtolower($aObject->attributes()->string('mode')) : 'soft') {
         case 'hard':
             $aDev->write("// display message queue by HARD mode");
             $aDev->write("if( !\$__device_for_msgqueue = \$__ui_msgqueue->properties()->get('aDisplayDevice') ){");
             $aDev->write("\t\$__device_for_msgqueue = new \\org\\jecat\\framework\\io\\OutputStreamBuffer() ;");
             $aDev->write("\t\$__ui_msgqueue->properties()->set('aDisplayDevice',\$__device_for_msgqueue) ;");
             $aDev->write("}");
             $aDev->write("\$__device_for_msgqueue->redirect(\$aDevice) ;");
             $sCancelDisplay = ' and $__device_for_msgqueue->isEmpty()';
             break;
         case 'force':
             $aDev->write("// display message queue by FORCE mode");
             $aDev->write("\$__device_for_msgqueue = \$aDevice ;");
             $sCancelDisplay = '';
             break;
         default:
             // soft
             $aDev->write("// display message queue by SOFT mode");
             $aDev->write("if( !\$__device_for_msgqueue = \$__ui_msgqueue->properties()->get('aDisplayDevice') ){");
             $aDev->write("\t\$__device_for_msgqueue = new \\org\\jecat\\framework\\io\\OutputStreamBuffer() ;");
             $aDev->write("\t\$__ui_msgqueue->properties()->set('aDisplayDevice',\$__device_for_msgqueue) ;");
             $aDev->write("}");
             $aDev->write("\$aDevice->write(\$__device_for_msgqueue) ;");
             $sCancelDisplay = ' and $__device_for_msgqueue->isEmpty()';
             break;
     }
     $aDev->write("if( \$__ui_msgqueue->count(){$sCancelDisplay} ){ ");
     $aDev->write("\t\$__ui_msgqueue->display(\$this,\$__device_for_msgqueue,{$sTemplate},{$sIsSubtemplate}) ;");
     $aDev->write("}");
     $aDev->write("// -------------------------------------\r\n");
 }
示例#25
0
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     Type::check("org\\jecat\\framework\\ui\\xhtml\\Node", $aObject);
     $aDev->write("}");
 }
示例#26
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");
 }
示例#27
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)
     }
 }
示例#28
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();
     // 指定view名称
     if ($aAttrs->has('xpath')) {
         $sXpath = $aAttrs->get('xpath');
     } else {
         if ($aAttrs->has('name')) {
             $sXpath = $aAttrs->get('name');
         } else {
             $sXpath = null;
         }
     }
     if ($sXpath) {
         $arrViewXPaths = "array({$sXpath})";
         $bUseXpath = true;
     } else {
         $arrViewXPaths = 'null';
         $bUseXpath = false;
     }
     $sLayout = $aAttrs->string('layout') ?: ViewAssembler::layout_vertical;
     // model
     if ($aAttrs->has('mode')) {
         $nMode = ViewAssembler::filterModeToPriority($aAttrs->string('mode'));
     } else {
         $nMode = $bUseXpath ? ViewAssembler::hard : ViewAssembler::soft;
     }
     $nNodeViewId =& $aDev->properties(true)->getRef('node.view.id');
     if ($nNodeViewId === null) {
         $nNodeViewId = 0;
     } else {
         $nNodeViewId++;
     }
     $sViewAssemblyListId = "\$this->id().'-pos{$nNodeViewId}'";
     // 视图的预处理
     $aDev->preprocessStream()->write("\r\n// define view assembly list -------------------");
     $aDev->preprocessStream()->write("if( empty(\$this) or !(\$this instanceof jc\\mvc\\view\\IView) )");
     $aDev->preprocessStream()->write("{");
     $aDev->preprocessStream()->write("\tthrow new jc\\lang\\Exception('UI标签 <view> 必须用于视图类。') ;");
     $aDev->preprocessStream()->write("}");
     $aDev->preprocessStream()->write("jc\\mvc\\view\\ViewAssembler::singleton()->defineAssemblyList(\r\n\t\t{$sViewAssemblyListId}\r\n\t\t, '{$sLayout}'\r\n\t\t, array(\r\n\t\t\t'priority' => {$nMode},\r\n\t\t\t'xpaths' => {$arrViewXPaths},\r\n\t\t\t'view' => \$this ,\r\n\t\t)\r\n) ;");
     $aDev->write("\r\n// display views ");
     $sViewAssemblyListId = "\$aVariables->theView->id().'-pos{$nNodeViewId}'";
     $aDev->write("jc\\mvc\\view\\ViewAssembler::singleton()->displayAssemblyList({$sViewAssemblyListId},\$aDevice) ;");
     return;
 }