Пример #1
0
 /**
  * 根据规则获取参数
  *
  * 根据提供的参数规则,进行参数创建工作,并返回错误信息
  *
  * @param $rule array('name' => '', 'type' => '', 'defalt' => ...) 参数规则
  * @return mixed
  */
 public function getByRule($rule)
 {
     $rs = NULL;
     if (!isset($rule['name'])) {
         throw new PhalApi_Exception_InternalServerError(T('miss name for rule'));
     }
     $rs = PhalApi_Request_Var::format($rule['name'], $rule, $this->data);
     if ($rs === NULL && (isset($rule['require']) && $rule['require'])) {
         throw new PhalApi_Exception_BadRequest(T('{name} require, but miss', array('name' => $rule['name'])));
     }
     return $rs;
 }
Пример #2
0
 /**
  * @expectedException PhalApi_Exception_InternalServerError
  */
 public function testFormatCallableButWroing()
 {
     $rs = PhalApi_Request_Var::format('testKey', array('name' => 'testKey', 'type' => 'callable', 'callback' => 'xxx'), array('testKey' => 1));
 }
 /**
  * @expectedException PhalApi_Exception_BadRequest
  */
 public function testStringWithRegxWrong()
 {
     $rule = array('name' => 'key', 'type' => 'string', 'regex' => '/^[0-9]{11}/');
     PhalApi_Request_Var::formatString('no a number', $rule);
 }