|
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* API<50><49><EFBFBD>ξ<EFBFBD>̬<EFBFBD><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* <20><><EFBFBD>Զ<EFBFBD>API<50>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͡<EFBFBD><CDA1><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>Ƚ<EFBFBD><C8BD><EFBFBD>У<EFBFBD><D0A3>
|
|
|
|
|
*
|
|
|
|
|
**/
|
|
|
|
|
class RequestCheckUtil
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* У<><D0A3><EFBFBD>ֶ<EFBFBD> fieldName <20><>ֵ$value<75>ǿ<EFBFBD>
|
|
|
|
|
*
|
|
|
|
|
**/
|
|
|
|
|
public static function checkNotNull($value,$fieldName) {
|
|
|
|
|
|
|
|
|
|
if(self::checkEmpty($value)){
|
|
|
|
|
throw new Exception("client-check-error:Missing Required Arguments: " .$fieldName , 40);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <20><><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>fieldName<6D><65>ֵvalue <20>ij<EFBFBD><C4B3><EFBFBD>
|
|
|
|
|
*
|
|
|
|
|
**/
|
|
|
|
|
public static function checkMaxLength($value,$maxLength,$fieldName){
|
|
|
|
|
if(!self::checkEmpty($value) && mb_strlen($value , "UTF-8") > $maxLength){
|
|
|
|
|
throw new Exception("client-check-error:Invalid Arguments:the length of " .$fieldName . " can not be larger than " . $maxLength . "." , 41);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <20><><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>fieldName<6D><65>ֵvalue<75><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*
|
|
|
|
|
**/
|
|
|
|
|
public static function checkMaxListSize($value,$maxSize,$fieldName) {
|
|
|
|
|
|
|
|
|
|
if(self::checkEmpty($value))
|
|
|
|
|
return ;
|
|
|
|
|
|
|
|
|
|
$list=preg_split("/,/",$value);
|
|
|
|
|
if(count($list) > $maxSize){
|
|
|
|
|
throw new Exception("client-check-error:Invalid Arguments:the listsize(the string split by \",\") of ". $fieldName . " must be less than " . $maxSize . " ." , 41);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <20><><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>fieldName<6D><65>ֵvalue <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
*
|
|
|
|
|
**/
|
|
|
|
|
public static function checkMaxValue($value,$maxValue,$fieldName){
|
|
|
|
|
|
|
|
|
|
if(self::checkEmpty($value))
|
|
|
|
|
return ;
|
|
|
|
|
|
|
|
|
|
self::checkNumeric($value,$fieldName);
|
|
|
|
|
|
|
|
|
|
if($value > $maxValue){
|
|
|
|
|
throw new Exception("client-check-error:Invalid Arguments:the value of " . $fieldName . " can not be larger than " . $maxValue ." ." , 41);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <20><><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>fieldName<6D><65>ֵvalue <20><><EFBFBD><EFBFBD>Сֵ
|
|
|
|
|
*
|
|
|
|
|
**/
|
|
|
|
|
public static function checkMinValue($value,$minValue,$fieldName) {
|
|
|
|
|
|
|
|
|
|
if(self::checkEmpty($value))
|
|
|
|
|
return ;
|
|
|
|
|
|
|
|
|
|
self::checkNumeric($value,$fieldName);
|
|
|
|
|
|
|
|
|
|
if($value < $minValue){
|
|
|
|
|
throw new Exception("client-check-error:Invalid Arguments:the value of " . $fieldName . " can not be less than " . $minValue . " ." , 41);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <20><><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>fieldName<6D><65>ֵvalue<75>Ƿ<EFBFBD><C7B7><EFBFBD>number
|
|
|
|
|
*
|
|
|
|
|
**/
|
|
|
|
|
protected static function checkNumeric($value,$fieldName) {
|
|
|
|
|
if(!is_numeric($value))
|
|
|
|
|
throw new Exception("client-check-error:Invalid Arguments:the value of " . $fieldName . " is not number : " . $value . " ." , 41);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* У<><D0A3>$value<75>Ƿ<EFBFBD><C7B7>ǿ<EFBFBD>
|
|
|
|
|
* if not set ,return true;
|
|
|
|
|
* if is null , return true;
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
**/
|
|
|
|
|
public static function checkEmpty($value) {
|
|
|
|
|
if(!isset($value))
|
|
|
|
|
return true ;
|
|
|
|
|
if($value === null )
|
|
|
|
|
return true;
|
|
|
|
|
if(is_array($value) && count($value) == 0)
|
|
|
|
|
return true;
|
|
|
|
|
if(is_string($value) &&trim($value) === "")
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
?>
|