public function compile(array &$arrRawSql, array &$arrInFactors = null, array &$arrTokenTree = null, $sTreeType = 'subtree') { $sSql = ''; if (!$arrTokenTree) { $arrTokenTree =& $arrRawSql; } if (!empty($arrRawSql[$sTreeType])) { // data factors if (!empty($arrRawSql['factors'])) { $arrFactors =& $arrRawSql['factors']; } else { $arrFactors =& $arrInFactors; } foreach ($arrRawSql[$sTreeType] as &$token) { if (is_string($token) or is_numeric($token)) { if ($arrFactors and array_key_exists($token, $arrFactors)) { $sSql .= " '" . addslashes($arrFactors[$token]) . "'"; } else { $sSql .= ' ' . $token; } } else { if (is_array($token)) { if ($this->arrTokenCompilers and !empty($this->arrTokenCompilers[$token['expr_type']])) { $sSql .= ' ' . $this->arrTokenCompilers[$token['expr_type']]->compile($this, $arrTokenTree, $token, $arrFactors); } else { if (!empty($token['subtree'])) { $sSqlSubtree = $this->compile($token, $arrFactors, $arrTokenTree); // 仅在 subtree 不为空的时候,处理 pretree if ($sSqlSubtree and !empty($token['pretree'])) { $sSql .= ' ' . $this->compile($token, $arrFactors, $arrTokenTree, 'pretree'); } $sSql .= ' ' . $sSqlSubtree; } } } else { throw new SqlCompileException($arrTokenTree, $token, "遇到类型无效的 sql token: %s", Type::detectType($token)); } } } } return $sSql ? substr($sSql, 1) : ''; }
protected function processNameSeparator(&$sToken, ParseState $aParseState) { $prevToken = end($aParseState->arrTree); if (is_array($prevToken)) { if (!($nextToken = next($aParseState->arrTokenList))) { throw new SqlParserException($aParseState, "遇到无效的名称分隔符“.” , “.” 后面没有内容了"); } if (!($nextName = $this->parseName($nextToken))) { if ($nextToken === '*') { $nextName = $nextToken; } else { throw new SqlParserException($aParseState, "遇到无效的名称分隔符“.” , “.” 后面不是一个合法的名称:%s", $nextToken); } } switch ($prevToken['expr_type']) { case 'column': if (!empty($prevToken['table'])) { $prevToken['db'] = $prevToken['table']; } $prevToken['table'] = $prevToken['column']; $prevToken['column'] = $nextName; break; case 'table': $prevToken['db'] = $prevToken['table']; $prevToken['table'] = $nextName; break; default: throw new SqlParserException($aParseState, "遇到无效的名称分隔符“.” , “.” 前不是一个字段或数据表的表达式:%s", $prevToken['expr_type']); break; } array_pop($aParseState->arrTree); array_push($aParseState->arrTree, $prevToken); } else { if (is_string($prevToken)) { throw new SqlParserException($aParseState, "遇到无效的名称分隔符“.” , “.” 前不是一个字段或数据表的表达式:%s", $prevToken); } else { throw new SqlParserException($aParseState, "遇到遇到意外的token类型:%s", Type::detectType($prevToken)); } } }
public function verifyFile(File $file, $bThrowException) { if (!$file instanceof File) { throw new Exception(__CLASS__ . "的" . __METHOD__ . "传入了错误的data参数(得到的参数是%s类型)", array(Type::detectType($file))); } $nDataSize = $file->length(); if ($this->nMaxSize != -1 && $nDataSize > $this->nMaxSize) { if ($bThrowException) { throw new VerifyFailed("上传的文件大小大于网站限制的" . $this->nMaxSize . "字节"); } return false; } if ($this->nMinSize != -1 && $nDataSize < $this->nMinSize) { if ($bThrowException) { throw new VerifyFailed("上传的文件大小小于网站限制的" . $this->nMaxSize . "字节"); } return false; } return true; }
public function generateTargetCode(TokenPool $aTokenPool, Token $aObject) { if (!$aObject instanceof ClassDefine) { throw new ClassCompileException(null, $aObject, "传入的类新必须为 ClassDefine: %s", Type::detectType($aObject)); } $aClassEnd = $aObject->bodyToken()->theOther(); $sTargetClassName = $aObject->fullName(); // 反射父类的所有方法 $arrParentMethodNames = array(); $aRefParentClass = null; if ($aObject->isClass()) { foreach ($aObject->parentClassNameIterator() as $sParentClass) { if (!class_exists($sParentClass)) { throw new ClassCompileException(null, $aObject, "编译class时遇到错误,class %s 的父类 %s 不存在 ", array($sTargetClassName, $sParentClass)); } $aRefParentClass = new \ReflectionClass($sParentClass); foreach ($aRefParentClass->getMethods() as $aRefParentMethod) { if (!$aRefParentMethod->isPrivate() and !$aRefParentMethod->isAbstract() and !$aRefParentMethod->isFinal()) { $arrParentMethodNames[$aRefParentMethod->getName()] = $aRefParentMethod; } } } } // 需要编入的方法 $arrNeedWeaveMethods = array(); foreach ($this->aop()->aspects()->iterator() as $aAspect) { foreach ($aAspect->pointcuts()->iterator() as $aPointcut) { foreach ($aPointcut->jointPoints()->iterator() as $aJointPoint) { if (!$aJointPoint instanceof JointPointMethodDefine) { continue; } // 模糊匹配函数名 ----------------------- if ($aJointPoint->weaveMethodIsPattern()) { foreach ($aTokenPool->functionIterator($aObject->fullName()) as $aMethodToken) { // bingo ! if ($aJointPoint->matchExecutionPoint($aMethodToken)) { $sMethodName = $aMethodToken->name(); if (empty($arrNeedWeaveMethods[$sMethodName])) { $arrNeedWeaveMethods[$sMethodName] = new GenerateStat($aTokenPool, $aMethodToken); } $arrNeedWeaveMethods[$sMethodName]->addAdvices($aPointcut->advices()->iterator()); } } } else { if (!$aJointPoint->matchClass($sTargetClassName)) { continue; } $sFuncName = $aJointPoint->weaveMethod(); if (empty($arrNeedWeaveMethods[$sFuncName])) { $arrNeedWeaveMethods[$sFuncName] = new GenerateStat($aTokenPool); } $arrNeedWeaveMethods[$sFuncName]->addAdvices($aPointcut->advices()->iterator()); // 目标类的方法 if ($aMethodToken = $aTokenPool->findFunction($sFuncName, $sTargetClassName)) { $arrNeedWeaveMethods[$sFuncName]->aExecutePoint = $aMethodToken; } else { if (isset($arrParentMethodNames[$sFuncName])) { $aMethodRef = $arrParentMethodNames[$sFuncName]; $aMethodRef instanceof \ReflectionMethod; // 产生函数定义和函数调用的参数表 $this->generateArgvsByReflection($arrNeedWeaveMethods[$sFuncName], $aMethodRef); if ($aMethodRef->isPublic()) { $sAccess = 'public'; } else { if ($aMethodRef->isProtected()) { $sAccess = 'protected'; } else { if ($aMethodRef->isPrivate()) { $sAccess = 'private'; } } } // 创建一个覆盖父类的方法用于 aop $aMethodToken = $this->createMethod($sFuncName, $arrNeedWeaveMethods[$sFuncName]->sOriginCallArgvsLit, $sAccess, $aMethodRef->isStatic(), $aTokenPool, $aClassEnd, 'insertBefore'); $aMethodToken->setBelongsClass($aObject); $aMethodToken->setBelongsNamespace($aObject->belongsNamespace()); $arrNeedWeaveMethods[$sFuncName]->aExecutePoint = $aMethodToken; // 创建函数内容 $aTokenPool->insertAfter($aMethodToken->bodyToken(), new Token(T_STRING, "\n\t\t\t// 调用父类方法\n\t\t\treturn parent::{$sFuncName}({$arrNeedWeaveMethods[$sFuncName]->sOriginCallArgvsLit}) ;\n\t\t")); } else { // 创建一个全新的方法用于 aop $aMethodToken = $this->createMethod($sFuncName, $arrNeedWeaveMethods[$sFuncName]->sOriginCallArgvsLit, 'private', false, $aTokenPool, $aClassEnd, 'insertBefore'); $aMethodToken->setBelongsClass($aObject); $aMethodToken->setBelongsNamespace($aObject->belongsNamespace()); $arrNeedWeaveMethods[$sFuncName]->aExecutePoint = $aMethodToken; $aTokenPool->insertAfter($aMethodToken->bodyToken(), new Token(T_STRING, " // 这只是一个影子方法 ")); } } } } } } // 开始编织 foreach ($arrNeedWeaveMethods as $aState) { if (!empty($aState->arrAdvices)) { $this->weave($aState); } } }
/** * @wiki /认证和授权/授权-许可(Authorizer) * ==Bean配置数组== * {| * |perms * |可选 * |array * |perms属性数组的成员可以是字符串或数组: * |如果是字符串,则表示 IPermission 类的类名(可以是在 BeanFeactory 中注册过的别名),该类必须实现 ISingleton 接口; * 如果是数组,则表示一个 IPermission 对象的 Bean 配置数组。 * perms属性数组的键名如果是字符串类型,可以做为对应元素Bean Config的class属性。 * |} */ public function buildBean(array &$arrConfig, $sNamespace = '*', BeanFactory $aBeanFactory = null) { if (!$aBeanFactory) { $aBeanFactory = BeanFactory::singleton(); } if (!empty($arrConfig['perms'])) { if (!is_array($arrConfig['perms'])) { throw new BeanConfException('%s 类的Bean Config的属性 perms必须是数组格式,传入的格式是:%s', array(__CLASS__, Type::detectType($arrConfig['perms']))); } foreach ($arrConfig['perms'] as $key => &$config) { if (is_string($config)) { $sClass = $aBeanFactory->beanClassNameByAlias($config); if (!Type::hasImplements($sClass, 'org\\jecat\\framework\\pattern\\ISingletonable')) { throw new BeanConfException('Bean 类 %s(%s) 没有实现 org\\jecat\\framework\\pattern\\ISingletonable 接口,无法只是通过类名创建对象', array($config, $sClass)); } if (!Type::hasImplements($sClass, 'org\\jecat\\framework\\auth\\IPermission')) { throw new BeanConfException('Bean 类 %s(%s) 没有实现 org\\jecat\\framework\\auth\\IPermission 接口,不能做为许可对象', array($config, $sClass)); } $this->requirePermission($sClass::singleton()); } else { if (is_array($config)) { if (is_string($key) and empty($config['class'])) { $config['class'] = $key; } $aPermission = $aBeanFactory->createBean($config, $sNamespace, true); if (!$aPermission instanceof IPermission) { throw new BeanConfException('%s 的Bean配置中提供了无效的 Permission 配置:%s 不是一个实现 org\\jecat\\framework\\auth\\IPermission 接口的类', array(__CLASS__, $config['class'])); } $this->requirePermission($aPermission); } } } } $this->arrBeanConfig = $arrConfig; }
public function verifyFile(File $file, $bThrowException) { if (!$file instanceof File) { throw new Exception(__CLASS__ . "的" . __METHOD__ . "传入了错误的data参数(得到的参数是%s类型)", array(Type::detectType($file))); } // TODO 纠正文件类型 $nImageInfo = getImageSize($file); $nImageArea = $nImageInfo[1] * $nImageInfo[0]; if ($this->nMaxArea != -1 && $nImageArea > $this->nMaxArea) { if ($bThrowException) { throw new VerifyFailed("图片面积太大了,应该小于:" . $this->nMaxArea . ',现在为:' . $nImageArea); } return false; } if ($this->nMinArea != -1 && $nImageArea < $this->nMinArea) { if ($bThrowException) { throw new VerifyFailed("图片面积太小了,应该大于:" . $this->nMinArea . ',现在为:' . $nImageArea); } return false; } return true; }
public function verifyFile(File $file, $bThrowException) { if (!$file instanceof File) { throw new Exception(__CLASS__ . "的" . __METHOD__ . "传入了错误的data参数(得到的参数是%s类型)", array(Type::detectType($file))); } // TODO 纠正文件类型 $nImageInfo = getImageSize($file); $nImageWidth = $nImageInfo[1]; $nImageHeight = $nImageInfo[0]; if ($this->nMinHeight != -1 && $nImageHeight < $this->nMinHeight) { if ($bThrowException) { throw new VerifyFailed("图片太短了,应该大于:" . $this->nMinHeight . '像素,现在为:' . $nImageHeight . '像素'); } return false; } if ($this->nMaxHeight != -1 && $nImageHeight > $this->nMaxHeight) { if ($bThrowException) { throw new VerifyFailed("图片太长了,应该小于:" . $this->nMaxHeight . '像素,现在为:' . $nImageHeight . '像素'); } return false; } if ($this->nMinWidth != -1 && $nImageWidth < $this->nMinWidth) { if ($bThrowException) { throw new VerifyFailed("图片太窄了,应该大于:" . $this->nMinWidth . '像素,现在为:' . $nImageWidth . '像素'); } return false; } if ($this->nMaxWidth != -1 && $nImageWidth > $this->nMaxWidth) { if ($bThrowException) { throw new VerifyFailed("图片太宽了,应该小于:" . $this->nMaxWidth . '像素,现在为:' . $nImageWidth . '像素'); } return false; } return true; }
public function verifyFile(File $file, $bThrowException) { if (!$file instanceof File) { throw new Exception(__CLASS__ . "的" . __METHOD__ . "传入了错误的data参数(得到的参数是%s类型)", array(Type::detectType($file))); } $nFileExt = $file->extname(); if ($this->bAllow && !in_array($nFileExt, $this->arrExt) || !$this->bAllow && in_array($nFileExt, $this->arrExt)) { if ($bThrowException) { throw new VerifyFailed("不允许上传的文件类型:" . $nFileExt); } return false; } return true; }