Esempio n. 1
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("}");
 }
Esempio n. 2
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);
     }
 }
Esempio n. 3
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");
     }
 }
Esempio n. 4
0
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     Assert::type("org\\jecat\\framework\\ui\\xhtml\\Macro", $aObject, 'aObject');
     if ($aCompiler = $this->subCompiler($aObject->macroType())) {
         $aCompiler->compile($aObject, $aObjectContainer, $aDev, $aCompilerManager);
     } else {
         $aDev->write($aObject->source());
     }
 }
Esempio n. 5
0
 public function registerEventHandle($sClass, $sEvent, $fnHandler, array $arrCallbackArgvs = null, $sourceObject = '*')
 {
     Assert::isCallback($fnHandler);
     if (is_object($sourceObject)) {
         $sourceObject = spl_object_hash($sourceObject);
     }
     $this->arrEventHandles[$sClass][$sEvent][$sourceObject][] = array($fnHandler, $arrCallbackArgvs);
     return $this;
 }
Esempio n. 6
0
 public function set($sName, $Value)
 {
     if ($this->sClass) {
         Assert::type($this->sClass, $Value, 'Value');
     }
     $oldVal = isset($this->arrDatas[$sName]) ? $this->arrDatas[$sName] : null;
     $this->arrDatas[$sName] = $Value;
     return $oldVal;
 }
Esempio n. 7
0
 public function complete(IObject $aObject, string $aSource, $nPosition)
 {
     Assert::type("org\\jecat\\framework\\ui\\xhtml\\Macro", $aObject, 'aObject');
     $sTextPos = $aObject->position() + strlen($aObject->borderStartMacro()) + 1;
     $sTextLen = $nPosition - strlen($aObject->borderEndMacro()) - $sTextPos + 1;
     $sText = $aSource->substr($sTextPos, $sTextLen);
     $aObject->setEndPosition($nPosition);
     $aObject->setSource($sText);
     return $aObject->parent();
 }
Esempio n. 8
0
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     Assert::type("org\\jecat\\framework\\ui\\xhtml\\Node", $aObject, 'aObject');
     if ($aCompiler = $this->subCompiler(strtolower($aObject->tagName()))) {
         $aCompiler->compile($aObject, $aObjectContainer, $aDev, $aCompilerManager);
     } else {
         $this->compileTag($aObject->headTag(), $aObjectContainer, $aDev, $aCompilerManager);
         if ($aTailTag = $aObject->tailTag()) {
             $this->compileChildren($aObject, $aObjectContainer, $aDev, $aCompilerManager);
             $this->compileTag($aTailTag, $aObjectContainer, $aDev, $aCompilerManager);
         }
     }
 }
Esempio n. 9
0
 protected function generateOriginJointCode(GenerateStat $aStat)
 {
     Assert::type("org\\jecat\\framework\\lang\\compile\\object\\CallFunction", $aStat->aExecutePoint);
     $aStat->sOriginJointCode = '';
     // 类名 或 对象变量
     if ($aObject = $aStat->aExecutePoint->classToken()) {
         $aStat->sOriginJointCode .= $aObject->targetCode();
         if (!$aStat->aExecutePoint->classToken()) {
             throw new Exception("方法调用缺少成员访问符");
         }
         $aStat->sOriginJointCode .= $aStat->aExecutePoint->setAccessToken();
     }
     // 函数名
     $aStat->sOriginJointCode .= $aStat->aExecutePoint->targetCode();
 }
Esempio n. 10
0
 public function &parseStatement(&$arrTokenList)
 {
     $aParseState = new ParseState($arrTokenList, $this);
     for (reset($aParseState->arrTokenList); ($sToken = current($aParseState->arrTokenList)) !== false; next($aParseState->arrTokenList)) {
         // 切换到其它状态
         $this->changeState($sToken, $aParseState);
         Assert::must($aParseState->aCurrentParser);
         $aParseState->aCurrentParser->processToken($sToken, $aParseState);
     }
     // 关闭 parser stack 上所有未结束的 parser
     while ($aParser = $aParseState->popParser()) {
         $aParser->finish($sToken, $aParseState);
     }
     return $aParseState->arrStatement;
 }
Esempio n. 11
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");
     }
 }
Esempio n. 12
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");
 }
Esempio n. 13
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());
     }
 }
Esempio n. 14
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);
         }
     }
 }
Esempio n. 15
0
 /**
  * 创建调用原始链接点的代码
  */
 protected function generateOriginJointCode(GenerateStat $aStat)
 {
     Assert::type("org\\jecat\\framework\\lang\\compile\\object\\FunctionDefine", $aStat->aExecutePoint);
     $aStat->sOriginJointMethodName = '__aop_jointpoint_' . $aStat->aExecutePoint->nameToken()->targetCode() . '_' . md5($aStat->aExecutePoint->belongsClass()->name());
     $aStat->sOriginJointCode = '';
     $aStat->sOriginJointCode .= $aStat->aExecutePoint->staticToken() ? 'self::' : '$this->';
     $aStat->sOriginJointCode .= $aStat->sOriginJointMethodName;
 }
Esempio n. 16
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");
 }
Esempio n. 17
0
 public function count()
 {
     $nCount = $this->arrMsgQueue ? count($this->arrMsgQueue) : 0;
     if ($this->arrChildren) {
         foreach ($this->arrChildren as $aChild) {
             if ($aChild instanceof IMessageQueue) {
                 $nCount += $aChild->count();
             } else {
                 if ($aChild instanceof IMessageQueueHolder) {
                     if ($aQueue = $aChild->messageQueue(false)) {
                         $nCount += $aQueue->count();
                     }
                 } else {
                     Assert::wrong("未知的错误");
                 }
             }
         }
     }
     return $nCount;
 }
Esempio n. 18
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('} ');
     }
 }
Esempio n. 19
0
 protected function checkType(IObject $aObject)
 {
     Assert::type("org\\jecat\\framework\\ui\\xhtml\\Node", $aObject, 'aObject');
 }
Esempio n. 20
0
 public function complete(IObject $aObject, string $aSource, $nPosition)
 {
     Assert::type("org\\jecat\\framework\\ui\\xhtml\\Tag", $aObject, 'aObject');
     $aNode = $aObject->parent();
     Assert::type("org\\jecat\\framework\\ui\\xhtml\\Node", $aNode);
     $sTagLen = $nPosition - $aObject->position() + 1;
     $sTagSource = $aSource->substr($aObject->position(), $sTagLen);
     $aObject->setSource($sTagSource);
     $aObject->setEndPosition($nPosition);
     // 单行标签
     if ($sTagSource[strlen($sTagSource) - 2] == '/') {
         if ($aObject->isTail()) {
             throw new Exception("UI引擎在分析模板时无法确定标签类型,不能同时是尾标签和单行标签。位置:%d行", $aObject->line());
         }
         $aObject->setTagType(Tag::TYPE_SINGLE);
     }
     // 头标签/单行标签
     if ($aObject->isHead()) {
         // 处理属性
         $aAttrs = $aObject->attributes();
         $aAttrValIterator = $aAttrs->valueIterator();
         $arrAttrs = array();
         $arrRemoveVal = array();
         $aPrevAttrVal = null;
         for ($aAttrValIterator->rewind(); $aVal = $aAttrValIterator->current(); $aAttrValIterator->next()) {
             if ($aVal->source() == '=') {
                 // 属性名
                 if (!$aPrevAttrVal) {
                     throw new Exception("UI引擎在分析模板时遇到空属性名称。位置:%d行", $aVal->line());
                 }
                 $aAttrName = $aPrevAttrVal;
                 if ($aAttrName->quoteType()) {
                     throw new Exception("UI引擎在分析模板时遇到无效的节点属性名称,属性名称不能使用引号。位置:%d行", $aAttrName->line());
                 }
                 $sAttrName = $aAttrName->source();
                 // 属性值
                 $aAttrValIterator->next();
                 $aAttrVal = $aAttrValIterator->current();
                 if (!$aAttrVal) {
                     continue;
                     throw new Exception("UI引擎在分析模板时遇到错误:属性名:%s没有对应的属性值。位置:%d行", array($sAttrName, $aVal->line()));
                 }
                 $aAttrVal->setName($sAttrName);
                 // 移除 val name
                 array_pop($arrAttrs);
                 $arrAttrs[] = $aAttrVal;
             } else {
                 $arrAttrs[] = $aVal;
             }
             $aPrevAttrVal = $aAttrValIterator->current();
         }
         $aAttrs->clear();
         foreach ($arrAttrs as $aAttrVal) {
             $aAttrs->add($aAttrVal);
         }
         if ($aObject->isSingle()) {
             // 单行标签节点结束
             return ParserStateNode::singleton()->complete($aNode, $aSource, $nPosition);
         } else {
             return $aNode;
         }
     } else {
         if ($aObject->isTail()) {
             if ($aNode->tagName() != $aObject->name()) {
                 throw new Exception("遇到不匹配的XHTML节点,头标签:%s(line:%d), 尾标签:%s(line:%d)", array($aNode->tagName(), $aNode->line(), $aObject->name(), $aObject->line()));
             }
             // 节点结束
             return ParserStateNode::singleton()->complete($aNode, $aSource, $nPosition);
         } else {
             throw new Exception("遇到无效的xhtml标签。源文:%s", $sTagSource);
         }
     }
 }
Esempio n. 21
0
 public function examineEnd(string $aSource, &$nPosition, IObject $aObject)
 {
     Assert::type("org\\jecat\\framework\\ui\\xhtml\\AttributeValue", $aObject, 'aObject');
     $sByte = $aSource->byte($nPosition);
     $sQuote = $aObject->quoteType();
     // 有引号的
     if ($sQuote) {
         if ($aObject->quoteType() == $sByte) {
             return true;
         } else {
             if ($sByte == '\\') {
                 $nPosition++;
             }
             return false;
         }
     } else {
         $sNextByte = $aSource->byte($nPosition + 1);
         if (in_array($sNextByte, array('=', '>'))) {
             return true;
         }
         // 空白字符
         if (preg_match('/\\s/', $sNextByte)) {
             return true;
         }
         return false;
     }
 }
Esempio n. 22
0
 public function add($aChild, $sName = null, $bTakeover = true)
 {
     Assert::type(__NAMESPACE__ . '\\IObject', $aChild);
     parent::add($aChild, $sName, $bTakeover);
 }
Esempio n. 23
0
	/**
	
		foreach($arr as $key=>$value){
			code;
		}
	=>
		for( key in arr){
			value = arr[ key ];
			code ;
		}
	 */
	private function transForeach(TokenPool $aTokenPool,Token $aObject)
	{
		// 定位迭代器
		$aTokenIter = $aTokenPool->iterator() ;
		if( !$nPos=$aTokenIter->search($aObject) )
		{
			Assert::wrong('提供的 $aObject 不再 $aTokenPool 中') ;
		}
		$aTokenIter->seek($nPos) ;
		
		// 找条件开始的 ”(“
		do{ $aTokenIter->next() ; }
		while( $aToken=$aTokenIter->current() and $aToken->tokenType()!=Token::T_BRACE_ROUND_OPEN ) ;
		if(!$aToken)
		{
			throw new ClassCompileException($aObject, "foreach 后没有  ( ") ;
		}
		$aBraceRoundOpenToken = $aToken ;
		
		// 找 ( 到 as 之间的表达值
		$arrExpressions = array() ;
		for( $aTokenIter->next(); $aToken=$aTokenIter->current() and $aToken->tokenType()!=T_AS; $aTokenIter->next() )
		{
			$arrExpressions[] = $aToken ;
		}
		// 吐掉最后的空格
		array_pop($arrExpressions);
		
		$aAsToken = $aToken ;
		
		// 吃掉as后的空格
		$aTokenIter->next();
		
		// as 到 闭合 ) 之间是否有 '=>'
		$aDoubleArrowToken = null ;
		$arrTokenListBeforeArrow = array();
		$arrTokenListAfterArrow = array();
		
		for( $aTokenIter->next() ; 
				$aToken = $aTokenIter->current() and $aToken !== $aBraceRoundOpenToken->theOther() ; 
				$aTokenIter->next() ){
			if( $aToken->tokenType() === T_DOUBLE_ARROW ){
				$aDoubleArrowToken = $aToken ;
			}else if( null === $aDoubleArrowToken ){
				$arrTokenListBeforeArrow [] = $aToken ;
			}else{
				$arrTokenListAfterArrow [] = $aToken ;
			}
		}
		// 清理最后的空格
		if( end($arrTokenListBeforeArrow) ->tokenType() === T_WHITESPACE ){
			array_pop( $arrTokenListBeforeArrow );
		}
		if( end($arrTokenListAfterArrow) and end($arrTokenListAfterArrow)->tokenType() === T_WHITESPACE ){
			array_pop( $arrTokenListAfterArrow );
		}
		
		// 寻找开始的 '{'
		// 空体for循环
		for(
			$aTokenIter->next() ; 
			$aToken = $aTokenIter->current() and $aToken->tokenType() !== Token::T_BRACE_OPEN ; 
			$aTokenIter->next() 
		);
		
		$aBraceOpenToken = $aToken ;
		
		// 开始替换
		// foreach 替换成 for
		$aObject->setTargetCode('for') ;
		
		// arrExpressions 替换成 key
		reset($arrExpressions);
		if( null === $aDoubleArrowToken ){
			$aToken = new Token(T_WHITESPACE,T_WHITESPACE);
			$aToken->setTargetCode(__FUNCTION__.'_key');
			$aTokenPool->insertBefore( current($arrExpressions) , $aToken );
		}else{
			// insert key
			foreach($arrTokenListBeforeArrow as $aToken){
				$aTokenPool->insertBefore( current($arrExpressions) , $aToken );
			}
			// insert a space
			$aSpaceToken = new Token(T_WHITESPACE,' ');
			$aTokenPool->insertBefore( current($arrExpressions) , $aSpaceToken );
			
			// remove arr
			do{
				$aTokenPool->remove(current($arrExpressions) );
				next($arrExpressions) ;
			}while( false !== current($arrExpressions) );
		}
		
		// as 替换成 in
		$aAsToken->setTargetCode('in');
		
		// in 后面是arr
		// 直接插入到闭合圆括号之前
		foreach($arrExpressions as $aToken){
			$aCloneToken = clone $aToken ;
			$this->generateTargetCode($aTokenPool , $aCloneToken );
			$aTokenPool->insertBefore( $aBraceRoundOpenToken->theOther() , $aCloneToken );
		}
		
		// '=>' 删掉
		if( null !== $aDoubleArrowToken ){
			$aDoubleArrowToken->setTargetCode('');
		}
		
		
		// '{'之后是value
		// 先换行
		$aToken = new Token(T_WHITESPACE,"\n");
		$arrValueInsert = array($aToken);
		if( null === $aDoubleArrowToken ){
			$arrValueInsert = array_merge( $arrValueInsert , $arrTokenListBeforeArrow );
		}else{
			$arrValueInsert = array_merge( $arrValueInsert , $arrTokenListAfterArrow );
		}
		
		// value 之后是 =arr[key];
		// =
		$aEqualToken = new Token(Token::T_EQUAL,'=');
		$arrValueInsert [] = $aEqualToken ;
		
		// arr
		foreach($arrExpressions as $aToken){
			$aCloneToken = clone $aToken ;
			$arrValueInsert [] = $aToken ;
		}
		
		// [
		$aBraceSquareOpenToken = new Token(Token::T_BRACE_SQUARE_OPEN,'[');
		$arrValueInsert [] = $aBraceSquareOpenToken ;
		
		// key
		if( null === $aDoubleArrowToken ){
			$aToken = new Token(T_WHITESPACE,T_WHITESPACE);
			$aToken->setTargetCode(__FUNCTION__.'_key');
			$arrValueInsert [] = $aToken ;
		}else{
			// insert key
			foreach($arrTokenListBeforeArrow as $aToken){
				$aCloneToken = clone $aToken ;
				$this->generateTargetCode($aTokenPool , $aCloneToken );
				$arrValueInsert [] = $aCloneToken ;
			}
		}
		
		// ]
		$aBraceSquareCloseToken = new Token(Token::T_BRACE_SQUARE_CLOSE,']');
		$arrValueInsert [] = $aBraceSquareCloseToken ;
		
		// ;
		$aSemicolonToken = new Token(Token::T_SEMICOLON,Token::T_SEMICOLON);
		$arrValueInsert [] = $aSemicolonToken ;
		
		// insert
		array_unshift($arrValueInsert , $aBraceOpenToken);
		call_user_func_array(array($aTokenPool,'insertAfter'),$arrValueInsert) ;
	}
Esempio n. 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());
 }
Esempio n. 25
0
 public function registerEventHandle($sEventType, $fnHandler, $sControllerClass = null, $sViewXPath = null, $sWidghtId = null, array $arrCallbackArgvs = null)
 {
     Assert::isCallback($fnHandler);
     $sKey = $sControllerClass . '-' . $sViewXPath . '-' . $sWidghtId . '-' . $sEventType;
     $this->arrEventHandles[$sKey][] = array($fnHandler, $arrCallbackArgvs);
 }
Esempio n. 26
0
 public function display($sSourceFile, $aVariables = null, IOutputStream $aDevice = null)
 {
     Assert::type(array('\\org\\jecat\\framework\\util\\IHashTable', 'array', 'null'), $aVariables);
     if (is_array($aVariables)) {
         $aVariables = new HashTable($aVariables);
     }
     // compile
     $aCompiledFile = $this->compileSourceFile($sSourceFile);
     // render
     $this->render($aCompiledFile, $aVariables, $aDevice);
 }
Esempio n. 27
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;
 }