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


PHP ResponseInterface::getBody方法代码示例

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


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

示例1: forUnexpectedContent

 public static function forUnexpectedContent(ResponseInterface $response, $expected)
 {
     $response->getBody()->rewind();
     $ex = new self(sprintf('Unexpected content in reponse. Expected a %s got %s', $expected, $response->getBody()->getContents()));
     $ex->responseObject = $response;
     return $ex;
 }
开发者ID:boekkooi,项目名称:icepay,代码行数:7,代码来源:BadResponseException.php

示例2: _getResult

 /**
  * @param ResponseInterface $response
  *
  * @return ApiResult
  */
 protected function _getResult($response)
 {
     if (!$response instanceof ResponseInterface) {
         throw new \InvalidArgumentException("{$response} should be an instance of ResponseInterface");
     }
     $result = new ApiResult();
     $result->setStatusCode($response->getStatusCode());
     $callId = $response->getHeader('X-Call-Id');
     if (!empty($callId)) {
         $result->setCallId($callId);
     }
     $decoded = json_decode((string) $response->getBody());
     if (isset($decoded->meta) && isset($decoded->data) && isset($decoded->meta->code) && $decoded->meta->code == $response->getStatusCode()) {
         $meta = $decoded->meta;
         $data = $decoded->data;
         if (isset($meta->message)) {
             $result->setStatusMessage($meta->message);
         }
         $result->setContent(json_encode($data));
     } else {
         $result->setContent((string) $response->getBody());
     }
     $result->setHeaders($response->getHeaders());
     return $result;
 }
开发者ID:fortifi,项目名称:api,代码行数:30,代码来源:Guzzle6Connection.php

示例3: decode

 public static function decode(ResponseInterface $response)
 {
     if ($response->hasHeader('Content-Type') && $response->getHeader('Content-Type')[0] == 'application/json') {
         return json_decode((string) $response->getBody(), true);
     }
     return (string) $response->getBody();
 }
开发者ID:keboola,项目名称:orchestrator-bundle,代码行数:7,代码来源:ResponseDecoder.php

示例4: convertIncomingResponseToArray

 /**
  * Turns an HTTP response object, with JSON in the body, into an array
  */
 public function convertIncomingResponseToArray(ResponseInterface $response) : array
 {
     $response->getBody()->rewind();
     $body = $response->getBody()->getContents();
     $bodyArray = json_decode($body, true);
     return $bodyArray ?: [];
 }
开发者ID:wadjei,项目名称:request-and-response-helper,代码行数:10,代码来源:RequestAndResponseHelper.php

示例5: getLastResponseData

 /**
  * @return string|null
  */
 public function getLastResponseData()
 {
     if (is_null($this->lastResponse)) {
         return null;
     }
     return $this->lastResponse->getBody()->getContents();
 }
开发者ID:survos,项目名称:platform-api-php,代码行数:10,代码来源:GuzzleListener.php

示例6: __invoke

 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
 {
     $accessToken = Helper::getTokenFromReq($request);
     if ($accessToken == null) {
         $res['ret'] = 0;
         $res['msg'] = "token is null";
         $response->getBody()->write(json_encode($res));
         return $response;
     }
     $storage = Factory::createTokenStorage();
     $token = $storage->get($accessToken);
     if ($token == null) {
         $res['ret'] = 0;
         $res['msg'] = "token is null";
         $response->getBody()->write(json_encode($res));
         return $response;
     }
     if ($token->expireTime < time()) {
         $res['ret'] = 0;
         $res['msg'] = "token is expire";
         $response->getBody()->write(json_encode($res));
         return $response;
     }
     $response = $next($request, $response);
     return $response;
 }
开发者ID:NothingToDoCN,项目名称:ss-panel,代码行数:26,代码来源:Api.php

示例7: getResponse

 /**
  * Get content of response.
  *
  * @param bool $parseJsonToObject Parse JSON response to PHP object?
  *
  * @return string|object
  * @throws ComicApiException
  */
 public function getResponse($parseJsonToObject = false)
 {
     if ($this->response instanceof ResponseInterface) {
         return $this->response->getBody();
     }
     throw new ComicApiException("You can't get response without making request.");
 }
开发者ID:grz-gajda,项目名称:comic-api,代码行数:15,代码来源:GuzzleConnection.php

示例8: display

 /**
  * Outputs the error popup, or a plain message, depending on the response content type.
  *
  * @param \Exception|\Error      $exception Note: can't be type hinted, for PHP7 compat.
  * @param ResponseInterface|null $response  If null, it outputs directly to the client. Otherwise, it assumes the
  *                                          object is a new blank response.
  * @return ResponseInterface|null
  */
 static function display($exception, ResponseInterface $response = null)
 {
     // For HTML pages, output the error popup
     if (strpos(get($_SERVER, 'HTTP_ACCEPT'), 'text/html') !== false) {
         ob_start();
         ErrorConsoleRenderer::renderStyles();
         $stackTrace = self::getStackTrace($exception->getPrevious() ?: $exception);
         ErrorConsoleRenderer::renderPopup($exception, self::$appName, $stackTrace);
         $popup = ob_get_clean();
         // PSR-7 output
         if ($response) {
             $response->getBody()->write($popup);
             return $response->withStatus(500);
         }
         // Direct output
         echo $popup;
     } else {
         // PSR-7 output
         if ($response) {
             $response->getBody()->write($exception->getMessage());
             if (self::$devEnv) {
                 $response->getBody()->write("\n\nStack trace:\n" . $exception->getTraceAsString());
             }
             return $response->withoutHeader('Content-Type')->withHeader('Content-Type', 'text-plain')->withStatus(500);
         }
         // Direct output
         header("Content-Type: text/plain");
         http_response_code(500);
         echo $exception->getMessage();
         if (self::$devEnv) {
             echo "\n\nStack trace:\n" . $exception->getTraceAsString();
         }
     }
     return null;
 }
开发者ID:impactwave,项目名称:php-web-console,代码行数:43,代码来源:ErrorConsole.php

示例9: dispatch

    public function dispatch(ServerRequestInterface $request, ResponseInterface $response) : ResponseInterface
    {
        $lang = LanguageNegotiator::getLanguage($request);
        $query = $this->db->prepare('SELECT n.id, n.title, n.parent_id from nodes n
INNER JOIN node_attributes na ON na.node_id = n.id
INNER JOIN attribute_values av on na.`attribute_value_id` = av.`id`
where av.`attribute_value` = :language;');
        $query->bindParam(':language', $lang);
        $query->execute();
        $data = $query->fetchAll(\PDO::FETCH_ASSOC);
        $neg = new FormatNegotiator();
        $contentType = $neg->getFormat($request);
        switch ($contentType) {
            case 'xml':
                $xml = new \SimpleXMLElement('<root/>');
                array_walk_recursive($this->treeBuilder->build($data), array($xml, 'addChild'));
                $response->getBody()->write($xml->asXML());
                break;
            default:
                $response->getBody()->write(json_encode($this->treeBuilder->build($data)));
                break;
        }
        return $response->withoutHeader('Content-Type');
        // Remove the Content-Type Header
    }
开发者ID:studioromeo,项目名称:skelly,代码行数:25,代码来源:GetNodeTreeAction.php

示例10: parseStream

 /**
  * @param callable $fn
  */
 public function parseStream(callable $fn)
 {
     $body = $this->response->getBody();
     while (!$body->eof()) {
         $data = $this->parseEventData($body->read(1024));
         $fn($data);
     }
 }
开发者ID:partner-it,项目名称:firebase-rest-php,代码行数:11,代码来源:FirebaseResponse.php

示例11: getResponse

 public function getResponse()
 {
     if ($this->response && ($body = $this->response->getBody())) {
         // Rewind response body in case it has already been read
         $body->seek(0, SEEK_SET);
     }
     return $this->response;
 }
开发者ID:php-http,项目名称:vcr-plugin,代码行数:8,代码来源:Track.php

示例12: asArray

 /**
  * Retrieve the json encoded response as a php associative array
  *
  * @return array
  */
 public function asArray()
 {
     $stream = $this->response->getBody();
     if ($stream->eof()) {
         $stream->rewind();
     }
     return json_decode($stream->getContents(), true);
 }
开发者ID:opensoft,项目名称:tfs-rest-api,代码行数:13,代码来源:Response.php

示例13: createErrorDocument

 /**
  * @return \WoohooLabs\Yin\JsonApi\Document\AbstractErrorDocument
  */
 protected function createErrorDocument()
 {
     $errorDocument = new ErrorDocument();
     if ($this->includeOriginalBody === true) {
         $errorDocument->setMeta(["original" => json_decode($this->response->getBody(), true)]);
     }
     return $errorDocument;
 }
开发者ID:garethwi,项目名称:yin,代码行数:11,代码来源:ResponseBodyInvalidJson.php

示例14: to

 /**
  * Return response with JSON header and status.
  *
  * @param \Psr\Http\Message\ResponseInterface $response
  * @param int $status
  * @return mixed
  */
 public function to(ResponseInterface $response, $status = 200)
 {
     if ($this->isRender) {
         $response->getBody()->write($this->jsonEncode($this->data, $this->encodingOptions));
     } else {
         $response->getBody()->write($this->data);
     }
     return $response->withStatus($status)->withHeader('Content-Type', 'application/json;charset=utf-8');
 }
开发者ID:aracaw,项目名称:wiring,代码行数:16,代码来源:JsonRenderer.php

示例15: parseResponse

 /**
  * @param ResponseInterface $response
  * @return array
  * @throws SurvosException
  */
 protected function parseResponse($response)
 {
     $content = $response->getBody()->getContents();
     $data = json_decode($content, true);
     if (!is_array($data)) {
         throw new SurvosException("Bad data in server response: " . substr($response->getBody(), 0, 200));
     }
     return $data;
 }
开发者ID:survos,项目名称:platform-api-php,代码行数:14,代码来源:BaseResource.php


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