123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- /**
- * API��ξ�̬�����
- * ���Զ�API�IJ������͡����ȡ����ֵ�Ƚ���У��
- *
- **/
- class RequestCheckUtil {
- /**
- * У���ֶ� fieldName ��ֵ$value�ǿ�
- *
- **/
- public static function checkNotNull($value, $fieldName) {
- if (self::checkEmpty($value)) {
- throw new Exception("client-check-error:Missing Required Arguments: ".$fieldName, 40);
- }
- }
- /**
- * �����ֶ�fieldName��ֵvalue �ij���
- *
- **/
- 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
- );
- }
- }
- /**
- * �����ֶ�fieldName��ֵvalue������б���
- *
- **/
- 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
- );
- }
- }
- /**
- * �����ֶ�fieldName��ֵvalue �����ֵ
- *
- **/
- 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
- );
- }
- }
- /**
- * �����ֶ�fieldName��ֵvalue ����Сֵ
- *
- **/
- 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
- );
- }
- }
- /**
- * �����ֶ�fieldName��ֵvalue�Ƿ���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
- );
- }
- }
- /**
- * У��$value�Ƿ�ǿ�
- * 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 (trim($value) === "") {
- return true;
- }
- return false;
- }
- }
- ?>
|