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"); }
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; }