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


PHP Response::json方法代码示例

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


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

示例1: getFailedReason

 /**
  * get the response phrase
  * @return array
  */
 public function getFailedReason()
 {
     if ($this->isFailed()) {
         $error = $this->response->json();
         return array_key_exists('error', $error) ? $error['error'] : array();
     }
     return null;
 }
开发者ID:nasrulhazim,项目名称:Laravel5-billplz,代码行数:12,代码来源:TransportResponse.php

示例2: deduce

 /**
  * @return ErrorResponse|SuccessResponse
  */
 public function deduce()
 {
     /* @var array $response */
     $response = (array) $this->response->json();
     if (array_key_exists('type', $response) && $response['type'] === 'error') {
         return new ErrorResponse($this->response->getStatusCode(), $this->response->getHeaders(), $this->response->getBody());
     }
     return new SuccessResponse($this->response->getStatusCode(), $this->response->getHeaders(), $this->response->getBody());
 }
开发者ID:mahsanamin,项目名称:box-php-sdk,代码行数:12,代码来源:Response.php

示例3: getDecodedJson

 /**
  * @return array
  */
 private function getDecodedJson()
 {
     if (!$this->decoded) {
         try {
             $this->decoded = $this->response->json();
         } catch (ParseException $e) {
             return array();
         }
     }
     return $this->decoded;
 }
开发者ID:codecloud,项目名称:symfony-shopify-bundle,代码行数:14,代码来源:JsonResponse.php

示例4: checkResponse

 /**
  * Check the return of a request response
  *
  * @param Response $response 
  * @return false if error, decoded response if valid status
  * @author Niko
  */
 private function checkResponse(Response $response)
 {
     if ($response->getStatusCode() != 200) {
         $res = $response->json();
         var_dump($response->getStatusCode());
         if (isset($res['Error'])) {
             $this->log($response->getStatusCode(), $res['Error']);
         }
         return false;
     }
     return $response->json();
 }
开发者ID:petit2m,项目名称:seriesTracker,代码行数:19,代码来源:GenericService.php

示例5: parseBody

 /**
  * Parse body of response
  *
  * @return Crawler | array | string
  */
 private function parseBody()
 {
     $type = $this->getType();
     $body = (string) $this->resource->getBody();
     if (!$body) {
         return '';
     }
     if (in_array($type, ['text/html', 'text/xml'])) {
         return new Crawler($body);
     }
     if ($type === 'application/json') {
         return $this->resource->json();
     }
     return $body;
 }
开发者ID:efiku,项目名称:Scraper,代码行数:20,代码来源:Response.php

示例6: wrapResponse

 private static function wrapResponse(Response $response)
 {
     $payload = $response->json(["object" => true]);
     // strip the envelope
     if (isset($payload->data) && isset($payload->meta)) {
         return new static($payload->data);
     }
     return new static($payload);
 }
开发者ID:purplapp,项目名称:purplapp-adn-lib,代码行数:9,代码来源:DataContainerTrait.php

示例7: __construct

 public function __construct(Response $response)
 {
     try {
         $this->details = $response->json();
         $message = $this->details['error']['message'];
     } catch (ParseException $e) {
         $message = $response->getReasonPhrase();
     }
     parent::__construct(sprintf('The request failed and returned an invalid status code ("%d") : %s', $response->getStatusCode(), $message), $response->getStatusCode());
 }
开发者ID:rgazelot,项目名称:Office365Adapter,代码行数:10,代码来源:ApiErrorException.php

示例8: Payment

 function it_maps_declined_response_402_to_payment_result_object(ClientException $exception, Response $response, ResultObjectMapperInterface $resultMapper, MethodInterface $method)
 {
     $result = ['error' => 'Error string'];
     $resultObject = new Payment();
     $response->getStatusCode()->willReturn(402);
     $response->json()->willReturn($result);
     $method->createResultObject()->willReturn($resultObject);
     $exception->getResponse()->willReturn($response);
     $resultMapper->map($result, $resultObject)->shouldBeCalled()->willReturn($resultObject);
     $this->get($exception, $method)->getResult()->shouldReturn($resultObject);
 }
开发者ID:web3d,项目名称:mincart,代码行数:11,代码来源:ExceptionMapperSpec.php

示例9: testCanReadFindAddressResponse

 public function testCanReadFindAddressResponse()
 {
     $json = file_get_contents(__DIR__ . '\\GetAddressIO.json');
     $response = new Response(200, [], Stream::factory($json));
     $json = $response->json();
     $address = new Address();
     $address->setLatitude($json['Latitude'])->setLongitude($json['Longitude'])->setStreet($json['Addresses'][0]);
     $this->assertEquals($address->getLatitude(), '51.503038');
     $this->assertEquals($address->getLongitude(), '-0.128371');
     $this->assertEquals($address->getStreet(), 'Prime Minister & First Lord of the Treasury, 10 Downing Street, , , , London, Greater London');
 }
开发者ID:akempes,项目名称:laravel-postcodeapi,代码行数:11,代码来源:GetAddressIOTest.php

示例10: parseResponse

 /**
  * Parse the returned response.
  *
  * @param  \GuzzleHttp\Message\Response  $response
  * @return array
  *
  * @throws \RuntimeException
  */
 protected function parseResponse(Response $response)
 {
     $contentType = explode(';', $response->getHeader('content-type'))[0];
     switch ($contentType) {
         case 'text/javascript':
         case 'application/json':
             return $response->json();
         case 'application/xml':
             return $response->xml();
     }
     throw new \RuntimeException("Unsupported returned content-type [{$contentType}]");
 }
开发者ID:pcextreme,项目名称:cloudstack-client,代码行数:20,代码来源:CloudstackConnector.php

示例11: handleResponse

 /**
  * @param \GuzzleHttp\Message\Response $response
  * @return Error
  */
 protected function handleResponse($response)
 {
     $contentType = $response->getHeader('content-type');
     if (stripos($contentType, 'application/json') === false) {
         return $response;
     }
     $json = $response->json();
     if ($response->getStatusCode() >= 400) {
         // oops an error with the response
         return new Error($response->getStatusCode(), $json['code'], $json['message']);
     }
     return $json;
 }
开发者ID:nsbucky,项目名称:echosign,代码行数:17,代码来源:Guzzle.php

示例12: testCanReadFindAddressResponse

 public function testCanReadFindAddressResponse()
 {
     $json = file_get_contents(__DIR__ . '\\PostcodeData.json');
     $response = new Response(200, [], Stream::factory($json));
     $json = $response->json();
     $address = new Address();
     $address->setStreet($json['details'][0]['street'])->setTown($json['details'][0]['city'])->setMunicipality($json['details'][0]['municipality'])->setProvince($json['details'][0]['province'])->setLatitude($json['details'][0]['lat'])->setLongitude($json['details'][0]['lon']);
     $this->assertEquals($address->getStreet(), 'Evert van de Beekstraat');
     $this->assertEquals($address->getTown(), 'Schiphol');
     $this->assertEquals($address->getMunicipality(), 'Haarlemmermeer');
     $this->assertEquals($address->getProvince(), 'Noord-Holland');
     $this->assertEquals($address->getLatitude(), '52.3035437835548');
     $this->assertEquals($address->getLongitude(), '4.7474064734608');
 }
开发者ID:akempes,项目名称:laravel-postcodeapi,代码行数:14,代码来源:PostcodeDataTest.php

示例13: handleResponse

 /**
  * @param Response $response
  * @return array|mixed
  * @throws JsonApiResponseException
  */
 public function handleResponse($response)
 {
     $contentType = $response->getHeader('content-type');
     // if its not json, then just return the response and handle it in your own object.
     if (stripos($contentType, 'application/json') === false) {
         return $response;
     }
     $json = $response->json();
     // adobe says hey this didn't work!
     if ($response->getStatusCode() >= 400) {
         // oops an error with the response, from Adobe complaining about something in your code.
         throw new JsonApiResponseException($response->getStatusCode(), $json['message'], $json['code']);
     }
     return $json;
 }
开发者ID:nsbucky,项目名称:echosignv3,代码行数:20,代码来源:GuzzleTransport.php

示例14: sendRequest

 /**
  * Making request using Guzzle
  *
  * @param string $method Type of request, either POST, GET, PUT or DELETE
  * @param string $endpoint The operation / task for API
  * @param array $data The parameter need to be passed
  * @param array $options The options like header, body, etc
  *
  * @return EntityBodyInterface|string
  * @throws \Exception
  */
 private function sendRequest($method, $endpoint, array $data = array(), array $options = array())
 {
     $uri = $this->buildUri($endpoint);
     if ($method === "GET" || $method === "PUT") {
         $uri = $this->buildUri($endpoint, $data);
     } elseif (count($data)) {
         $options['body'] = $data;
     }
     $this->request = $this->client->createRequest($method, $uri, $options);
     $this->response = $this->client->send($this->request);
     if ($this->response->getStatusCode() >= 400) {
         $bt = debug_backtrace();
         $caller = $bt[2];
         if (isset($caller['class']) && $caller['class'] === get_class(new StacklaModel())) {
             $json = (string) $this->response->getBody();
             if (JsonValidator::validate($json, true)) {
                 $content = json_decode($json, true);
                 if (isset($content['errors'])) {
                     $caller['object']->fromArray($content);
                 }
             }
         }
         if ($this->logger) {
             $this->logger->addError('-> REQUEST [' . $this->request->getMethod() . ' - ' . $this->request->getUrl() . "]", array($this->request->getMethod() !== "GET" ? (string) $this->request->getBody() : ""));
             $this->logger->addError('<- RESPONSE [' . $this->response->getStatusCode() . ':' . $this->response->getReasonPhrase() . "]", array((string) $this->response->getBody()));
         }
     } else {
         if ($this->logger) {
             $this->logger->addInfo('-> REQUEST [' . $this->request->getMethod() . ' - ' . $this->request->getUrl() . "]", array($this->request->getMethod() !== "GET" ? (string) $this->request->getBody() : ""));
             $this->logger->addInfo('<- RESPONSE [' . $this->response->getStatusCode() . ':' . $this->response->getReasonPhrase() . "]", array($this->response->json()));
         }
     }
     $statusCode = $this->response->getStatusCode();
     switch ($statusCode) {
         case 200:
             return (string) $this->response->getBody();
         case 400:
             throw ApiException::create(sprintf("Server return %s error code. Bad request: The request could not be understood. %s", $this->response->getStatusCode(), (string) $this->response->getBody()), $statusCode, (string) $this->response->getBody());
         case 401:
             throw ApiException::create(sprintf("Server return %s error code. Unauthorized: Authentication credentials invalid or not authorised to access resource", $this->response->getStatusCode()), $statusCode, (string) $this->response->getBody());
         case 403:
             throw ApiException::create(sprintf("\n                  Server return %s error code. Rate limit exceeded: Too many requests in the current time window", $this->response->getStatusCode()), $statusCode, (string) $this->response->getBody());
         case 404:
             throw ApiException::create(sprintf("Server return %s error code. Invalid resource: Invalid resource specified or resource not found", $this->response->getStatusCode()), $statusCode, (string) $this->response->getBody());
         default:
             throw ApiException::create(sprintf("Server return %s error code.Server error: An error on the server prohibited a successful response; please contact support. %s", $this->response->getStatusCode(), (string) $this->response->getBody()), $statusCode, (string) $this->response->getBody());
     }
 }
开发者ID:stackla,项目名称:stackla-php-sdk,代码行数:59,代码来源:Request.php

示例15: parseBody

 /**
  * {@inheritdoc}
  */
 public function parseBody(Response $response, $format = '')
 {
     $output = NULL;
     if (empty($format)) {
         $format = isset($this->defaults['form']) ? $this->defaults['form'] : NULL;
     }
     if ($format == $this::FORMAT_JSON || $format == $this::FORMAT_CJSON) {
         $output = $response->json();
     }
     if ($format == $this::FORMAT_ATOM || $format == $this::FORMAT_RSS) {
         $output = $this->xmlToArray($response->xml());
     }
     if ($output['isException']) {
         throw new MpxException(sprintf('Exception returned: %s', print_r($output, TRUE)), $output['responseCode']);
     }
     if (isset($output)) {
         return $output;
     }
     throw new MpxException('Custom formats are not supported.');
 }
开发者ID:robcolburn,项目名称:mpx-php,代码行数:23,代码来源:Client.php


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