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


PHP Response::getContent方法代码示例

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


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

示例1: processResponse

 private function processResponse(Response $response)
 {
     if (null !== $this->logger) {
         $this->logger->info(sprintf('Status Code %s', $response->getStatusCode()));
         $this->logger->debug(var_export($response->getContent(), true));
     }
     if (500 <= $response->getStatusCode()) {
         throw new ApiServerException($response->getStatusCode(), $response->getContent(), $response->getReasonPhrase(), $response->getHeaders());
     }
     if (400 <= $response->getStatusCode()) {
         try {
             $error = $this->parser->parse($response->getContent());
             $error = $error instanceof Model\Error ? $error : new Model\Error();
         } catch (ApiParserException $e) {
             throw new ApiClientException($response->getStatusCode(), $response->getContent(), $response->getReasonPhrase(), $response->getHeaders(), null, $e);
         }
         throw new ApiClientException($response->getStatusCode(), $response->getContent(), $response->getReasonPhrase(), $response->getHeaders(), $error);
     }
     if (204 === $response->getStatusCode()) {
         return true;
     }
     $content = trim($response->getContent());
     if (empty($content)) {
         return true;
     }
     $object = $this->parser->parse($content);
     $object->setApi($this);
     return $object;
 }
开发者ID:iamluc,项目名称:connect,代码行数:29,代码来源:Api.php

示例2: assertHttpResponseCodeEquals

 protected function assertHttpResponseCodeEquals(HttpResponse $response, $expected)
 {
     $responseCode = $response->getStatusCode();
     if ($responseCode != $expected) {
         $errorMessageString = '';
         if ($response->getHeader('Content-Type') == 'application/vnd.ez.api.ErrorMessage+xml') {
             $body = \simplexml_load_string($response->getContent());
             $errorMessageString = $body->errorDescription;
         } elseif ($response->getHeader('Content-Type') == 'application/vnd.ez.api.ErrorMessage+json') {
             $body = json_decode($response->getContent());
             $errorMessageString = "Error message: {$body->ErrorMessage->errorDescription}";
         }
         self::assertEquals($expected, $responseCode, $errorMessageString);
     }
 }
开发者ID:Heyfara,项目名称:ezpublish-kernel,代码行数:15,代码来源:TestCase.php

示例3: assertHttpResponseCodeEquals

 protected function assertHttpResponseCodeEquals(HttpResponse $response, $expected)
 {
     $responseCode = $response->getStatusCode();
     if ($responseCode != $expected) {
         $errorMessageString = '';
         if (strpos($response->getHeader('Content-Type'), 'application/vnd.ez.api.ErrorMessage+xml') !== false) {
             $body = \simplexml_load_string($response->getContent());
             $errorMessageString = $this->getHttpResponseCodeErrorMessage($body);
         } elseif (strpos($response->getHeader('Content-Type'), 'application/vnd.ez.api.ErrorMessage+json') !== false) {
             $body = json_decode($response->getContent());
             $errorMessageString = $this->getHttpResponseCodeErrorMessage($body->ErrorMessage);
         }
         self::assertEquals($expected, $responseCode, $errorMessageString);
     }
 }
开发者ID:emodric,项目名称:ezpublish-kernel,代码行数:15,代码来源:TestCase.php

示例4: getResponse

 /**
  * Parse a response.
  *
  * @return \Tev\Bs\Contracts\ResponseInterface
  *
  * @throws \Exception
  * @throws \Tev\Bs\Exception\ErrorResponseException
  */
 public function getResponse()
 {
     $content = json_decode($this->response->getContent());
     if ($content === null) {
         throw new Exception('Failed to get response from server');
     }
     if (isset($content->error) && $content->error) {
         $excp = new ErrorResponseException($content->message, $this->response->getStatusCode());
         $excp->setResponse(new Response($content, $this->endpoint));
         throw $excp;
     }
     if (isset($content->per_page)) {
         return new PaginatedResponse($content, $this->endpoint);
     }
     return new Response($content, $this->endpoint);
 }
开发者ID:tinavas,项目名称:booking-api,代码行数:24,代码来源:Parser.php

示例5: parse

 /**
  * @param Response $curlResponse
  *
  * @throws HttpStatusParserException
  */
 public function parse(Response $curlResponse)
 {
     $statusCode = $curlResponse->getStatusCode();
     if ($this->shouldThrowException($statusCode)) {
         throw new HttpStatusParserException($curlResponse->getContent(), $statusCode);
     }
 }
开发者ID:krzysztof-gzocha,项目名称:payu,代码行数:12,代码来源:HttpStatusParser.php

示例6: processResponse

 /**
  * This public method is also for other context(s) to process REST API call and inject response into this context.
  *
  * @param  \Buzz\Message\Response $response
  * @param  boolean                $asJson   Process the response as JSON or not.
  * @return void
  */
 public function processResponse(\Buzz\Message\Response $response = null, $asJson = true)
 {
     if (!empty($response)) {
         $this->response = $response;
     }
     return $this->processResponseBody($this->response->getContent(), $asJson);
 }
开发者ID:sourcefabric,项目名称:newscoop,代码行数:14,代码来源:RestContext.php

示例7: it_can_search_with__query

 public function it_can_search_with__query(Browser $client, Response $response)
 {
     $response->getContent()->shouldBeCalled();
     $client->get(sprintf('%s/search?%s', 'http://endpoint', http_build_query(['q' => 'pilkington avenue, birmingham', 'format' => 'json'])), ['User-Agent' => 'Nomatim PHP Library (https://github.com/nixilla/nominatim-consumer); email: not set'])->shouldBeCalled()->willReturn($response);
     $query = new Query();
     $query->setQuery('pilkington avenue, birmingham');
     $this->search($query)->shouldReturnAnInstanceOf('Nominatim\\Result\\Collection');
 }
开发者ID:nixilla,项目名称:nominatim-consumer,代码行数:8,代码来源:ConsumerSpec.php

示例8: _parse

 public function _parse(Response $response, $mime = null)
 {
     $data = $this->decode($response->getContent(), $mime);
     if (isset($data->error)) {
         throw new RugException($data->error, $this->_error($data));
     }
     return $data;
 }
开发者ID:o100ja,项目名称:rug,代码行数:8,代码来源:AbstractParser.php

示例9: getContent

 /**
  * {@inheritDoc}
  */
 public function getContent()
 {
     $response = parent::getContent();
     $content = json_decode($response, true);
     if (JSON_ERROR_NONE !== json_last_error()) {
         return $response;
     }
     return $content;
 }
开发者ID:nschappl,项目名称:software_engineering,代码行数:12,代码来源:Response.php

示例10: processResponse

 /**
  * @param  Response $response
  *
  * @return string
  */
 private function processResponse(Response $response)
 {
     $matches = [];
     preg_match('/<input.*value="(.*)"/U', $response->getContent(), $matches);
     if (!isset($matches[1])) {
         throw new \RuntimeException('Screenshot upload failed');
     }
     return $matches[1];
 }
开发者ID:stof,项目名称:behat-screenshot-image-driver-uploadpie,代码行数:14,代码来源:UploadPieApi.php

示例11: handleException

 /**
  * Lets us know if something went wrong
  *
  * @param Response $response
  * @throws \Twitter\Exception\TwitterApiException
  * @throws \Exception
  */
 protected function handleException(Response $response)
 {
     $json_string = $response->getContent();
     $output = json_decode($json_string, true);
     if (count($output['errors'])) {
         throw new TwitterApiException($output['errors'][0]['message'], $output['errors'][0]['code']);
     } else {
         throw new \Exception(sprintf('Unknown error: %s', $json_string));
     }
 }
开发者ID:nixilla,项目名称:twitter-api-consumer,代码行数:17,代码来源:Consumer.php

示例12: getContent

 /**
  * @return mixed
  */
 public function getContent()
 {
     $response = parent::getContent();
     if ($this->getHeader('Content-Type') === 'application/json') {
         $content = json_decode($response, true);
         if (JSON_ERROR_NONE !== json_last_error()) {
             return $response;
         }
         return $content;
     }
     return $response;
 }
开发者ID:brianalbers,项目名称:php-sonarqube-api,代码行数:15,代码来源:Response.php

示例13: processResponse

 private function processResponse(Response $response)
 {
     if (null !== $this->logger) {
         $this->logger->info(sprintf('Status Code %s', $response->getStatusCode()));
         $this->logger->debug(var_export($response->getContent(), true));
     }
     if (500 <= $response->getStatusCode()) {
         throw new ApiServerException($response->getStatusCode(), $response->getContent(), $response->getReasonPhrase(), $response->getHeaders());
     }
     if (400 <= $response->getStatusCode()) {
         throw new ApiClientException($response->getStatusCode(), $response->getContent(), $response->getReasonPhrase(), $response->getHeaders());
     }
     if (204 === $response->getStatusCode()) {
         return true;
     }
     if (null !== $response->getContent()) {
         $object = $this->parser->parse($response->getContent());
         $object->setApi($this);
         return $object;
     }
 }
开发者ID:nfabre,项目名称:connect,代码行数:21,代码来源:Api.php

示例14: validateResponse

 /**
  * {@inheritdoc}
  */
 protected function validateResponse(Response $response)
 {
     $content = $response->getContent();
     $success = false;
     $xml = new \DOMDocument();
     if ($xml->loadXML($content)) {
         foreach ($xml->firstChild->childNodes as $child) {
             if ($child->nodeName === 'cas:authenticationSuccess') {
                 $root = $child;
                 $success = true;
                 break;
             } elseif ($child->nodeName === 'cas:authenticationFailure') {
                 $root = $child;
                 $success = false;
                 break;
             }
         }
         if ($success) {
             foreach ($root->childNodes as $child) {
                 switch ($child->nodeName) {
                     case 'cas:user':
                         $this->username = $child->textContent;
                         break;
                     case 'cas:attributes':
                         foreach ($child->childNodes as $attr) {
                             if ($attr->nodeName != '#text') {
                                 $this->attributes[$attr->nodeName] = $attr->textContent;
                             }
                         }
                         break;
                     case 'cas:attribute':
                         $name = $child->attributes->getNamedItem('name')->value;
                         $value = $child->attributes->getNamedItem('value')->value;
                         if ($name && $value) {
                             $this->attributes[$name] = $value;
                         }
                         break;
                     case '#text':
                         break;
                     default:
                         $this->attributes[substr($child->nodeName, 4)] = $child->textContent;
                 }
             }
         } else {
             $this->error = (string) $root->textContent;
         }
     } else {
         $success = false;
         $this->error = 'Invalid response';
     }
     return $success;
 }
开发者ID:nicolasbui,项目名称:BeSimpleSsoAuthBundle,代码行数:55,代码来源:XmlValidation.php

示例15: validateResponse

 /**
  * {@inheritdoc}
  */
 protected function validateResponse(Response $response)
 {
     $content = $response->getContent();
     $data = explode("\n", str_replace("\n\n", "\n", str_replace("\r", "\n", $content)));
     $success = strtolower($data[0]) === 'yes';
     $message = count($data) > 1 && $data[1] ? $data[1] : null;
     if ($success) {
         $this->username = $message;
     } else {
         $this->error = $message;
     }
     return $success;
 }
开发者ID:nh293,项目名称:BeSimpleSsoAuthBundle,代码行数:16,代码来源:PlainValidation.php


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