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


PHP ActivitiResponseObject::fromArray方法代码示例

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


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

示例1: parseResponse

 public function parseResponse($url, $response, $returnType, $isArray, $expectedHttpCodes, $errorHttpCodes)
 {
     // parse response
     $header = false;
     $content = array();
     $status = null;
     foreach (explode("\r\n", $response) as $line) {
         if (strpos($line, 'HTTP/1.1') === 0) {
             $lineParts = explode(' ', $line);
             $status = intval($lineParts[1]);
             $header = true;
         } else {
             if ($line == '') {
                 $header = false;
             } else {
                 if ($header) {
                     $line = explode(': ', $line);
                     switch ($line[0]) {
                         case 'Status':
                             $status = intval(substr($line[1], 0, 3));
                             break;
                     }
                 } else {
                     $content[] = $line;
                 }
             }
         }
     }
     if (is_null($status)) {
         throw new ActivitiClientException("No valid response accepted, URL [{$url}]", ActivitiClientException::NO_VALID_RESPONSE);
     }
     if (in_array($status, $expectedHttpCodes)) {
         $response = implode("\r\n", $content);
         if (!trim($response)) {
             return;
         }
         if ($returnType == 'string') {
             return $response;
         }
         $response = json_decode($response);
         if ($returnType) {
             if ($isArray) {
                 return ActivitiResponseObject::fromArray($response, $returnType);
             }
             return new $returnType($response);
         }
         return;
     }
     if ($response && json_decode(implode("\n", $content))) {
         $error = json_decode(implode("\n", $content));
         if (isset($error->statusCode) && isset($error->errorMessage)) {
             throw new ActivitiClientException("Status [{$error->statusCode}], URL [{$url}]: {$error->errorMessage}", ActivitiClientException::INVALID_HTTP_CODE);
         }
     }
     if (isset($errorHttpCodes[$status])) {
         throw new ActivitiClientException("Status [{$status}], URL [{$url}]: " . $errorHttpCodes[$status], ActivitiClientException::INVALID_HTTP_CODE);
     }
     if (ActivitiResponseType::isExpectedCode($status)) {
         throw new ActivitiClientException("Status [{$status}], URL [{$url}]: " . ActivitiResponseType::getCodeDescription($status), ActivitiClientException::INVALID_HTTP_CODE);
     }
     throw new ActivitiClientException("Unexpected status [{$status}], URL [{$url}]", ActivitiClientException::INVALID_HTTP_CODE);
 }
开发者ID:DBezemer,项目名称:server,代码行数:62,代码来源:ActivitiClientBase.php


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