当前位置: 首页>>代码示例>>PHP>>正文


PHP Response::setError方法代码示例

本文整理汇总了PHP中Response::setError方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::setError方法的具体用法?PHP Response::setError怎么用?PHP Response::setError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Response的用法示例。


在下文中一共展示了Response::setError方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: call

 /**
  * @param Request $request
  * @return Response
  */
 public function call(Request $request)
 {
     // Create cURL
     $ch = curl_init();
     // Set-up URL
     curl_setopt($ch, CURLOPT_URL, $request->getUrl());
     // Set-up headers
     $headers = $request->getHeaders();
     array_walk($headers, function (&$item, $key) {
         $item = "{$key}: {$item}";
     });
     curl_setopt($ch, CURLOPT_HTTPHEADER, array_values($headers));
     // Set-up others
     curl_setopt_array($ch, $request->getOpts());
     // Receive result
     $result = curl_exec($ch);
     // Parse response
     $response = new Response();
     if ($result === FALSE) {
         $response->setError(curl_strerror(curl_errno($ch)));
         $response->setData(FALSE);
         $response->setCode(curl_errno($ch));
         $response->setHeaders(curl_getinfo($ch));
     } else {
         $response->setData(json_decode($result));
         $response->setCode(curl_getinfo($ch, CURLINFO_HTTP_CODE));
         $response->setHeaders(curl_getinfo($ch));
     }
     // Close cURL
     curl_close($ch);
     return $response;
 }
开发者ID:r01261,项目名称:GopayInline,代码行数:36,代码来源:Curl.php

示例2: testSetError

 /** @dataProvider provideSetError */
 public function testSetError($expected, $statusCode, $error, $error_description = null, $error_uri = null)
 {
     $response = new Response();
     $response->setError($statusCode, $error, $error_description, $error_uri);
     $this->assertEquals($expected, $response->getContent());
     $this->assertEquals($statusCode, $response->getStatusCode());
 }
开发者ID:Insantani,项目名称:SourceTree-diovi,代码行数:8,代码来源:ResponseTest.php

示例3: testSetError

 public function testSetError()
 {
     $response = new Response();
     $response->setError("DEFAULT_ERROR", "DEFAULT_ERROR_DETAIL");
     $error = $response->getError(true);
     $this->assertEquals('DEFAULT_ERROR', $error['error']);
     $this->assertEquals('DEFAULT_ERROR_DETAIL', $error["errorDetail"]);
 }
开发者ID:softhui,项目名称:AlibabaSDK,代码行数:8,代码来源:ResponseTest.php

示例4: testSetError

 public function testSetError()
 {
     $error = "ERROR_TEST";
     $errorDetail = 1;
     $response = new Response();
     $response->setError($error, $errorDetail);
     $this->assertFalse($response->isOk());
     $this->assertEquals($error, $response->getError());
     $errorRes = $response->getError(true);
     $this->assertEquals($errorDetail, $errorRes['errorDetail']);
 }
开发者ID:HorseLuke,项目名称:QcloudApi-SDK-PHP,代码行数:11,代码来源:ResponseTest.php

示例5: doQueryResponse

 /**
  * Execute an SQL select query and generate Response object
  * @param  string $type   [description]
  * @param  string $sql SQL string to execute
  * @param  bool $isSingle Whether only one record should be returned
  * @return Response $response Generated Response object
  */
 public function doQueryResponse(Response $response, $sql, $type, $isSingle = false)
 {
     try {
         // Execute the query
         $result = $this->doQuery($sql, $isSingle);
         // Save the data to the response object
         $response->setData($type, $result);
     } catch (\Rapi\PDOException $e) {
         // Save the PDO error to the response
         $response->setError($e->getCode(), $e->getMessage());
     }
     return $response;
 }
开发者ID:grzchr15,项目名称:phplist-plugin-restapi,代码行数:20,代码来源:PdoEx.php

示例6: enforceRequestLimit

 public static function enforceRequestLimit($limit)
 {
     $response = new Response();
     try {
         $db = PDO::getConnection();
         $stmt = $db->prepare('select count(cmd) as num from ' . $GLOBALS['table_prefix'] . 'restapi_request_log where date > date_sub(now(),interval 1 minute)');
         $stmt->execute();
         $result = $stmt->fetch(PDO::FETCH_OBJ);
         if ($result->num > $limit) {
             $response->outputErrorMessage('Too many requests. Requests are limited to ' . $limit . ' per minute');
             die(0);
         }
     } catch (\Exception $e) {
         $response->setError($e->getCode(), $e->getMessage());
     }
 }
开发者ID:grzchr15,项目名称:phplist-plugin-restapi,代码行数:16,代码来源:common.php

示例7: exec

 /**
  * Execute the query
  *
  * @return Response
  */
 private function exec()
 {
     $ch = $this->init();
     // Collect response data
     $response = new Response(['response' => curl_exec($ch), 'options' => $this->_options, 'info' => curl_getinfo($ch)]);
     $errno = curl_errno($ch);
     if ($errno) {
         $response->setError([$errno => curl_error($ch)]);
     }
     curl_close($ch);
     return $response;
 }
开发者ID:ArtiResh,项目名称:Script_for_smm,代码行数:17,代码来源:Client.php

示例8: rawSend

 /**
  * 原始发送请求
  * @param string $url 完整URL
  * @param string|array $bodyParam body请求体。$requestMethod为POST时有效
  * @param string $requestMethod 请求方法,必须全大写
  * @param Response $response
  * @return Response $response
  */
 public function rawSend($url, $bodyParam = null, $requestMethod = 'GET', Response $response = null)
 {
     if (null === $response) {
         $response = new Response();
     }
     if (null === $this->curlInit) {
         $this->curlInit = curl_init();
     }
     $curlOpt = $this->getDefaultCurlOpt();
     $curlOpt[CURLOPT_URL] = $url;
     if ($requestMethod == 'POST') {
         $curlOpt[CURLOPT_POST] = true;
     }
     $curlOpt[CURLOPT_CUSTOMREQUEST] = $requestMethod;
     if ($requestMethod == 'POST' || $requestMethod == 'PUT') {
         if (is_array($bodyParam)) {
             if (!$this->rawSendCheckHasFile($bodyParam)) {
                 $bodyParam = http_build_query($bodyParam);
             } else {
                 $bodyParam = $this->rawSendBuildCleanUploadBody($bodyParam);
             }
         }
         if ($bodyParam !== null && $bodyParam !== "") {
             $curlOpt[CURLOPT_POSTFIELDS] = $bodyParam;
         } else {
             $curlOpt[CURLOPT_POSTFIELDS] = "";
         }
     }
     curl_setopt_array($this->curlInit, $curlOpt);
     $rawResult = curl_exec($this->curlInit);
     $curlInfo = curl_getinfo($this->curlInit);
     $curl_errno = curl_errno($this->curlInit);
     if ($curl_errno) {
         $response->setError("CURL_ERROR", curl_error($this->curlInit) . '[ErrCode ' . $curl_errno . ']');
     } else {
         $response->create($curlInfo['http_code'], $rawResult);
     }
     $response->setExtractInfo($curlInfo);
     if (!empty($this->requestLoggerStack)) {
         $this->dispatchRequestLogger($url, isset($curlOpt[CURLOPT_POSTFIELDS]) ? $curlOpt[CURLOPT_POSTFIELDS] : null, $requestMethod, $response);
     }
     return $response;
 }
开发者ID:HorseLuke,项目名称:QcloudApi-SDK-PHP,代码行数:51,代码来源:Request.php

示例9: outputErrorMessage

 /**
  * Generate and output an error response from an error message
  * @note Wraps other error handling methods for convenience
  * @param string $message Error message
  */
 static function outputErrorMessage($message)
 {
     $response = new Response();
     $response->setError(0, $message);
     $response->output();
 }
开发者ID:grzchr15,项目名称:phplist-plugin-restapi,代码行数:11,代码来源:Response.php

示例10: dispatch

 /**
  * 分发请求到对象的方法
  */
 public function dispatch($handler, $require_oauth = false, $request = null)
 {
     // 检查handler
     if (!is_string($handler)) {
         throw new PrismException('No handler given to dispatcher');
     }
     // 创建Request和Response
     if (!$request) {
         $request = new Request();
     }
     $response = new Response($request->getRequestID());
     // oauth判断
     if ($require_oauth && !$request->getOauth()) {
         $response->setError('Invalid Request', 'Oauth is required')->send();
     }
     // 使用middlewares
     foreach ($this->middlewares as $middleware) {
         list($class_name, $action_name) = explode('@', $middleware);
         call_user_func(array(new $class_name(), $action_name), $request, $response);
     }
     // 清理不需要的params
     if ($this->routing_key) {
         unset($request->params[$this->routing_key]);
     }
     // 解析对象名和方法名
     list($class_name, $action_name) = explode('@', $handler);
     // 执行方法
     call_user_func(array(new $class_name(), $action_name), $request, $response);
 }
开发者ID:453111208,项目名称:bbc,代码行数:32,代码来源:PrismServer.php


注:本文中的Response::setError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。