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


PHP Response::json方法代码示例

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


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

示例1: getResponse

 /**
  * Get the response of the query.
  * Will be the json decoded data if success, else the error message.
  *
  * @return array|string
  */
 public function getResponse()
 {
     if (false === $this->response->isSuccessful()) {
         return $this->response->getMessage();
     }
     return $this->response->json();
 }
开发者ID:pompdelux,项目名称:kraken-bundle,代码行数:13,代码来源:KrakenResponse.php

示例2: genderize

 /**
  * @param array $query
  *
  * @return array
  */
 public function genderize(array $query)
 {
     $queryString = '?' . http_build_query($query);
     $request = $this->get($queryString);
     $this->setLastResponse($request->send());
     return $this->lastResponse->json();
 }
开发者ID:javihgil,项目名称:genderize-io-client,代码行数:12,代码来源:GenderizeClient.php

示例3: getResponseAsArray

 /**
  * Get response as an array.
  *
  * @return array
  */
 private function getResponseAsArray()
 {
     $this->result = $this->response->json();
     if ($this->responseHasErrors()) {
         return false;
     }
     return $this->result;
 }
开发者ID:RuslanZavacky,项目名称:JiraApiBundle,代码行数:13,代码来源:AbstractService.php

示例4: extractFromResponse

 /**
  * @param string $what
  * @return null
  */
 protected function extractFromResponse($what)
 {
     $data = $this->guzzleResponse->json();
     if ($data && is_array($data)) {
         if (array_key_exists($what, $data)) {
             return $data[$what];
         }
     }
     return null;
 }
开发者ID:peterculak,项目名称:apis,代码行数:14,代码来源:Response.php

示例5: __construct

 public function __construct(\Guzzle\Http\Message\Response $response, $type)
 {
     $this->_response = $response;
     // if json returned - parse and fill structure
     $contentType = $this->_response->getContentType();
     if (strpos($contentType, ';')) {
         list($contentType, ) = explode(';', $contentType);
     }
     if ($contentType == 'application/json') {
         $this->_structure = new $type($this->_response->json());
     } else {
         throw new \Exception('Structure parser for content type "' . $this->_response->getContentType() . '" not implemented');
     }
 }
开发者ID:sokil,项目名称:php-rest,代码行数:14,代码来源:Response.php

示例6: factory

 /**
  * Simple exception factory for creating Intercom standardised exceptions
  *
  * @param RequestInterface $request The Request
  * @param Response $response The response
  * @return BadResponseException
  */
 public static function factory(RequestInterface $request, Response $response)
 {
     $response_json = $response->json();
     $intercom_unavailable_error = NULL;
     if (!static::isValidIntercomError($response_json)) {
         if ($response->isServerError()) {
             $label = 'Server error response';
             $class = __NAMESPACE__ . '\\ServerErrorResponseException';
             $intercom_unavailable_error = 'Service Unavailable: Back-end server is at capacity';
         } else {
             $label = 'Unsuccessful response';
             $class = __CLASS__;
         }
     } elseif ($response->isClientError()) {
         $label = 'Client error response';
         $class = __NAMESPACE__ . '\\ClientErrorResponseException';
     } elseif ($response->isServerError()) {
         $label = 'Server error response';
         $class = __NAMESPACE__ . '\\ServerErrorResponseException';
     } else {
         $label = 'Unsuccessful response';
         $class = __CLASS__;
     }
     $message = $label . PHP_EOL . implode(PHP_EOL, array('[status code] ' . $response->getStatusCode(), '[reason phrase] ' . $response->getReasonPhrase(), '[url] ' . $request->getUrl()));
     $e = new $class($message);
     $e->setResponse($response);
     $e->setRequest($request);
     // Sets the errors if the error response is the standard Intercom error type
     if (static::isValidIntercomError($response_json)) {
         $e->setErrors($response_json['errors']);
     } elseif ($intercom_unavailable_error != NULL) {
         $e->setErrors(array('code' => 'service_unavailable', "message" => $intercom_unavailable_error));
     }
     return $e;
 }
开发者ID:scup,项目名称:intercom-php,代码行数:42,代码来源:IntercomException.php

示例7: factory

 /**
  * Simple exception factory for creating Intercom standardised exceptions
  *
  * @param RequestInterface $request The Request
  * @param Response $response The response
  * @return BadResponseException
  */
 public static function factory(RequestInterface $request, Response $response)
 {
     if (!static::isValidIntercomError($response->json())) {
         $label = 'Unsuccessful response';
         $class = __CLASS__;
     } elseif ($response->isClientError()) {
         $label = 'Client error response';
         $class = __NAMESPACE__ . '\\ClientErrorResponseException';
     } elseif ($response->isServerError()) {
         $label = 'Server error response';
         $class = __NAMESPACE__ . '\\ServerErrorResponseException';
     } else {
         $label = 'Unsuccessful response';
         $class = __CLASS__;
     }
     $message = $label . PHP_EOL . implode(PHP_EOL, array('[status code] ' . $response->getStatusCode(), '[reason phrase] ' . $response->getReasonPhrase(), '[url] ' . $request->getUrl()));
     $e = new $class($message);
     $e->setResponse($response);
     $e->setRequest($request);
     // Sets the errors if the error response is the standard Intercom error type
     if (static::isValidIntercomError($response->json())) {
         $e->setErrors($response->json()['errors']);
     }
     return $e;
 }
开发者ID:atlir,项目名称:intercom-php,代码行数:32,代码来源:IntercomException.php

示例8: parseResponseIntoArray

 /**
  * Parses response into an array
  *
  * @param Response $response
  * @return array
  */
 protected function parseResponseIntoArray($response)
 {
     if (strpos($response->getContentType(), 'json') === false) {
         parse_str($response->getBody(true), $array);
         return $array;
     }
     return $response->json();
 }
开发者ID:opdavies,项目名称:nwdrupalwebsite,代码行数:14,代码来源:MeetupResponseParser.php

示例9: json

 /**
  * {@inheritdoc}
  */
 public function json()
 {
     try {
         $result = $this->response->json();
     } catch (\Exception $exception) {
         throw GuzzleRestException::createFromException($exception);
     }
     return $result;
 }
开发者ID:ramunasd,项目名称:platform,代码行数:12,代码来源:GuzzleRestResponse.php

示例10: formatResponse

 /**
  * Format the raw API response into an array of Models.
  *
  * @param Guzzle\Http\Message\Response $response api response
  * @param string $model the name of the class to instantiate
  *
  * @return array
  */
 public function formatResponse(Response $response, $model)
 {
     $body = $response->json();
     $collection = [];
     foreach ($body['data'] as $item) {
         $collection[] = new $model($this, $item);
     }
     // foreach body[data]
     return $collection;
 }
开发者ID:behance,项目名称:kong,代码行数:18,代码来源:Client.php

示例11: decodeResponse

 public function decodeResponse(Response $response)
 {
     $jsonResponse = $response->json();
     if (isset($jsonResponse["result"]) && ($result = $jsonResponse["result"]) !== "success") {
         throw new RpcErrorException($result);
     }
     if (!isset($jsonResponse["arguments"])) {
         throw new RpcNoResultException();
     }
     return $jsonResponse["arguments"];
 }
开发者ID:mdjward,项目名称:php-rpc-client,代码行数:11,代码来源:TransmissionJsonRpcEncoder.php

示例12: decodeResponse

 public function decodeResponse(Response $response)
 {
     $json = $response->json();
     if (isset($json["error"])) {
         throw new RpcErrorException($json["error"]);
     }
     if (!isset($json["result"])) {
         throw new RpcNoResultException();
     }
     return $json["result"];
 }
开发者ID:mdjward,项目名称:php-rpc-client,代码行数:11,代码来源:AbstractJsonRpcEncoder.php

示例13: testMagicOperationsReturnResult

 /**
  * Executing service description defined operations returns the result
  * @group unit
  */
 public function testMagicOperationsReturnResult()
 {
     $responseData = array("this" => "that");
     Phockito::when($this->mockResponse->getStatusCode())->return(200);
     Phockito::when($this->mockResponse->json())->return($this->testDescription);
     Phockito::when($this->mockRequest->send())->return($this->mockResponse);
     Phockito::when($this->client)->get(anything())->return($this->mockRequest);
     Phockito::when($this->client)->callParent(anything(), anything())->return($responseData);
     $result = $this->client->SomeOperation(array());
     $this->assertEquals($result, $responseData);
 }
开发者ID:balihoo,项目名称:publish-service-client,代码行数:15,代码来源:ClientTest.php

示例14: testSuccess

 public function testSuccess()
 {
     $body = file_get_contents(dirname(dirname(__FILE__)) . '/Mock/TokenPurchaseSuccess.txt');
     $httpResponse = new Response(200, array('Content-Type' => 'application/json'), $body);
     $response = new TokenPurchaseResponse($this->getMockRequest(), $httpResponse->json());
     $this->assertTrue($response->isSuccessful());
     $this->assertFalse($response->isRedirect());
     $this->assertNull($response->getCode());
     $this->assertNull($response->getMessage());
     $this->assertSame('205182114555', $response->getTransactionReference());
 }
开发者ID:collizo4sky,项目名称:omnipay-2checkout,代码行数:11,代码来源:TokenPurchaseResponseTest.php

示例15: __construct

 /**
  * @param \Guzzle\Http\Message\Response $response
  */
 public function __construct(\Guzzle\Http\Message\Response $response)
 {
     if ($response->isSuccessful()) {
         $this->response = $response->json();
         foreach ($this->response as $key => $value) {
             $this->response[$key] = $value;
         }
     } else {
         // TODO: Error handling
     }
 }
开发者ID:Atyz,项目名称:etherpad-lite-client,代码行数:14,代码来源:Response.php


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