public static function getInstance() { if (null == self::$param) { self::$param = new Param(); } return self::$param; }
function CheckXYMo($args) { $rules = array("mobile" => array("type" => "string", "minLen" => 1, 'nullable' => true, 'emptyable' => true), "linkid" => array("type" => "string", "minLen" => 1), "content" => array("type" => "string", "minLen" => 1), "createDate" => array("type" => "string", "minLen" => 1), "spcode" => array("type" => "string", "minLen" => 1)); $result = ParamChecker::getInstance()->checkParam($rules, $args); if (!$result['result']) { return false; } return true; }
public function verifyInput(&$args) { $req = $args['interface']['para']; $rules = array("userId" => array("type" => "int"), "userName" => array('type' => 'string', 'nullable' => true), "money" => array('type' => 'int', 'nullable' => true), "bulletNum" => array('type' => 'int', 'nullable' => true), "xsft" => array('type' => 'int', 'nullable' => true), "hdcx" => array('type' => 'int', 'nullable' => true), "chxs" => array('type' => 'int', 'nullable' => true), "sszm" => array('type' => 'int', 'nullable' => true), "win" => array('type' => 'int', 'nullable' => true), "loss" => array('type' => 'int', 'nullable' => true), "password" => array('type' => 'string', 'nullable' => true), "email" => array('type' => 'string', 'nullable' => true)); $result = ParamChecker::getInstance()->checkParam($rules, $req); if (!$result['result']) { $this->_retValue = EC_INVALID_INPUT; $this->_retMsg = $result['msg']; interface_log(ERROR, $this->_retValue, $this->_retMsg); return false; } $keys = array_keys($rules); extract($req); $this->_args = compact($keys); if (count($this->_args) == 1) { $this->_retValue = EC_INVALID_INPUT; $this->_retMsg = "not enough parameter"; interface_log(ERROR, $this->_retValue, $this->_retMsg); return false; } return true; }
function testCheckWithFlags() { $myvar = null; $results = array(); ParamChecker::checkWithFlags($myvar, "myvar", ParamChecker::NOT_NULL, $results); $this->assertTrue(count($results) != 0, "Non viene lanciata l'eccezione per myvar==null!"); $myvar = 0; $results = array(); ParamChecker::checkWithFlags($myvar, "myvar", ParamChecker::NOT_ZERO, $results); $this->assertTrue(count($results) != 0, "Non viene lanciata l'eccezione per myvar==0!"); $myvar = array(); $results = array(); ParamChecker::checkWithFlags($myvar, "myvar", ParamChecker::NOT_NULL | ParamChecker::NOT_ZERO, $results); $this->assertTrue(count($results) == 0, "Errore nell'utilizzo dei check : array considerato nullo o 0!"); $results = array(); ParamChecker::checkWithFlags($myvar, "myvar", ParamChecker::NOT_EMPTY, $results); $this->assertTrue(count($results) != 0, "Non viene lanciata l'eccezione per myvar==array()!"); $myvar = -2; $results = array(); ParamChecker::checkWithFlags($myvar, "myvar", ParamChecker::NOT_EMPTY | ParamChecker::NOT_NULL | ParamChecker::NOT_ZERO, $results); $this->assertTrue(count($results) == 0, "Errore nell'utilizzo dei check : array considerato nullo o 0!"); $myvar = -2; $results = array(); ParamChecker::checkWithFlags($myvar, "myvar", ParamChecker::VALID_ID, $results); $this->assertTrue(count($results) != 0, "Non viene lanciata l'eccezione per myvar==-2!"); }
protected function _verifyInput(&$args, $rules) { $req = $args['interface']['para']; $result = ParamChecker::getInstance()->checkParam($rules, $req); if (!$result['result']) { $this->_retValue = EC_INVALID_INPUT; $this->_retMsg = $result['msg']; live_log(ERROR, $this->_retValue, $this->_retMsg); return false; } $keys = array_keys($rules); extract($req); $this->_args = compact($keys); if (isset($channel_id)) { $this->setLogAppIdAndChannelId($app_id, $channel_id); } else { $this->setLogAppIdAndChannelId($app_id); } return true; }
/** * * 参数检查方法 * @param array $rules * @param array $args 示例1: $rules = array( 'appId' => 'int', //int类型 'owners' => 'array', //array类型 'instanceIds' => 'intArr', //array类型,元素为int类型 'instanceTypes' => 'strArr', //array类型,元素为string类型 'ips' => 'ipArr',//array类型,元素为ip 'deviceId' => 'int/array', //int类型或者array类型,最后转化为元素为idArr类型 'deviceClass' => 'string/array', //string类型或者array类型,最后转化为strArr类型 'blocks' => array('type' => 'int', 'range' => '(5,10)'), //int类型,> 5,< 10 'blocks2' => array('type' => 'int', 'range' => '[5,10]'), //int类型,>= 5,<= 10 'percent' => array('type' => 'float', 'range' => '[5.1,10.9]'), //int类型,>= 5,<= 10 'appName' => array('type' => 'string'), //string类型 'appName2' => array('type' => 'string', 'reg' => '[^0-9A-Za-z]', 'maxLen' => 10, 'minLen' => 1, 'nullable' => true), //string类型,支持正则表达式 ); 示例2: $rules = array( 'appId' => 'int', 'appName' => array('type' => 'string', 'maxLen' => 255, 'minLen' => 1, 'nullable' => true), 'isDistribute' => array('type' => 'int', 'enum' => array(0, 1), 'nullable' => true, 'emptyable' => true), 'ownerUin' => array('type' => 'string', 'reg' => "^[0-9]{4,}$", 'nullable' => true), 'owner' => array('type' => 'string', 'nullable' => true), 'sets' => array('type' => 'strArr', 'nullable' => true) ); 示例3: 参数格式: “wsName”:” /cloudsns/app/app123456/app123456_cee/app123456_rs1” "blocks":[{"ipName":"10.135.130.35","blockCnt ":20, alterBlockCnt:2}, {"ipName":"10.135.130.36","blockCnt ":20, alterBlockCnt:2}] 对应的rules: $rules = array( 'wsName' => 'string', 'blocks' => array( 'type' => 'array', 'elem' => array( 'type' => 'object', 'items' => array( 'ipName' => 'ip', 'blockCnt' => array('int', 'range' => '[1,+)'), 'alterBlockCnt' => 'int', ) ) ) ); */ function checkParam($rules = array(), &$args) { return ParamChecker::getInstance()->checkParam($rules, $args); }