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


PHP ResponseInterface::json方法代码示例

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


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

示例1: populateFromResponse

 /**
  * {@inheritDoc}
  */
 public function populateFromResponse(ResponseInterface $response)
 {
     $entries = $response->json()['access']['serviceCatalog'];
     foreach ($entries as $entry) {
         $this->entries[] = $this->model('Entry', $entry);
     }
 }
开发者ID:boxrice007,项目名称:openstack,代码行数:10,代码来源:Catalog.php

示例2: __construct

 /**
  * Creates a response object
  * @param ResponseInterface $responseInterface
  * @throws ParseException
  */
 public function __construct(ResponseInterface $responseInterface)
 {
     $this->response = $responseInterface->json();
     $this->status = isset($this->response['meta']['code']) ? $this->response['meta']['code'] : 500;
     $this->errorCode = isset($this->response['meta']['error_code']) ? $this->response['meta']['error_code'] : null;
     $this->responseErrorCodes = new ResponseErrorCodes();
 }
开发者ID:credibility,项目名称:dandb,代码行数:12,代码来源:Response.php

示例3: handleResponse

 /**
  * @param ResponseInterface $response
  */
 private function handleResponse(ResponseInterface $response, Request $request)
 {
     $context = $this->prepareBaseContext($request);
     $data = $response->json();
     if (isset($data['results'])) {
         foreach ($data['results'] as $registrationIdIdx => $result) {
             $context['registrationId'] = $this->registrationIds[$registrationIdIdx];
             $context['result'] = var_export($result, true);
             switch (key($result)) {
                 case 'message_id':
                     if (isset($result['registration_id'])) {
                         $this->callback(EventsEnum::ON_PUSH_SUCCESS_BUT_NEED_NEW_ID, [$context]);
                     } else {
                         $this->callback(EventsEnum::ON_PUSH_SUCCESS, [$context]);
                     }
                     break;
                 case 'error':
                     $currentResult = current($result);
                     switch ($currentResult) {
                         case 'Unavailable':
                             $this->callback(EventsEnum::ON_PUSH_UNAVAILABLE, [$context]);
                             break;
                         case 'InvalidRegistration':
                             $this->callback(EventsEnum::ON_PUSH_INVALID_REGISTRATION, [$context]);
                             break;
                         case 'NotRegistered':
                             $this->callback(EventsEnum::ON_PUSH_NOT_REGISTERED, [$context]);
                             break;
                     }
                     break;
             }
         }
     }
     return ['success' => $data['success'], 'failure' => $data['failure']];
 }
开发者ID:akentner,项目名称:incoming-ftp,代码行数:38,代码来源:GoogleCloudMessaging.php

示例4: decodeHttpResponse

 /**
  * Decode an HTTP Response.
  * @static
  * @throws Google_Service_Exception
  * @param GuzzleHttp\Message\RequestInterface $response The http response to be decoded.
  * @param GuzzleHttp\Message\ResponseInterface $response
  * @return mixed|null
  */
 public static function decodeHttpResponse(ResponseInterface $response, RequestInterface $request = null)
 {
     $body = (string) $response->getBody();
     $code = $response->getStatusCode();
     $result = null;
     // return raw response when "alt" is "media"
     $isJson = !($request && 'media' == $request->getQuery()->get('alt'));
     // set the result to the body if it's not set to anything else
     if ($isJson) {
         try {
             $result = $response->json();
         } catch (ParseException $e) {
             $result = $body;
         }
     } else {
         $result = $body;
     }
     // retry strategy
     if (intVal($code) >= 300) {
         $errors = null;
         // Specific check for APIs which don't return error details, such as Blogger.
         if (isset($result['error']) && isset($result['error']['errors'])) {
             $errors = $result['error']['errors'];
         }
         throw new Google_Service_Exception($body, $code, null, $errors);
     }
     return $result;
 }
开发者ID:OlivierBarbier,项目名称:google-api-php-client,代码行数:36,代码来源:REST.php

示例5: it_handle_unexpected_oboom_response

 public function it_handle_unexpected_oboom_response(Client $guzzleClient, ResponseInterface $response)
 {
     $url = 'http://example.com';
     $response->json()->shouldBeCalled()->willReturn([400]);
     $guzzleClient->get($url, ['query' => []])->willReturn($response);
     $this->shouldThrow(new RuntimeException('API error', 400))->during('call', [$url]);
 }
开发者ID:vantoozz,项目名称:oboom-php-sdk,代码行数:7,代码来源:GuzzleTransportSpec.php

示例6: getCount

 public function getCount($content, ResponseInterface $response = null)
 {
     $data = $response->json();
     if (empty($data)) {
         return false;
     }
     return (int) array_shift($data)['shares'];
 }
开发者ID:xdimedrolx,项目名称:shares,代码行数:8,代码来源:MailRu.php

示例7:

 function it_should_return_results_as_an_object(ClientInterface $client, ResponseInterface $response)
 {
     $params = 'key=' . $this->test_key . '&hero_id=12345&skill=2';
     $expectedUrl = $this->test_base_url . 'IDOTA2Match_570/GetMatchDetails/v001/?' . $params;
     $responseReturn = json_decode('{"result": {"status": 1, "num_results": 0, "total_results": 407, "results_remaining": 307} }');
     $response->json(['object' => true])->shouldBeCalled()->willReturn($responseReturn);
     $client->get($expectedUrl)->shouldBeCalled()->willReturn($response);
     $this->endpoint('IDOTA2Match_570/GetMatchDetails/v001')->options(['hero_id' => 12345, 'skill' => 2])->get()->shouldReturn($responseReturn);
 }
开发者ID:bdunn313,项目名称:phpdota,代码行数:9,代码来源:SteamApiCallerSpec.php

示例8: before

 public function before(CommandInterface $command, ResponseInterface $response, Parameter $model, &$result, array $context = [])
 {
     $this->json = $response->json() ?: [];
     // relocate named arrays, so that they have the same structure as
     //  arrays nested in objects and visit can work on them in the same way
     if ($model->getType() == 'array' && ($name = $model->getName())) {
         $this->json = [$name => $this->json];
     }
 }
开发者ID:shaun785,项目名称:guzzle-services,代码行数:9,代码来源:JsonLocation.php

示例9: populateFromResponse

 /**
  * Populates the current resource from a response object.
  *
  * @param ResponseInterface $response
  *
  * @return $this|ResourceInterface
  */
 public function populateFromResponse(ResponseInterface $response)
 {
     if (strpos($response->getHeader('Content-Type'), 'application/json') === 0) {
         $json = $response->json();
         if (!empty($json)) {
             $this->populateFromArray($this->flatten($json));
         }
     }
     return $this;
 }
开发者ID:boxrice007,项目名称:openstack,代码行数:17,代码来源:AbstractResource.php

示例10: __construct

 public function __construct(ResponseInterface $response)
 {
     try {
         $this->details = $response->json();
         $message = isset($this->details['error']['message']) ? $this->details['error']['message'] : $response->getReasonPhrase();
     } 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:krichprollsch,项目名称:Office365Adapter,代码行数:10,代码来源:ApiErrorException.php

示例11: theResponseShouldContainJson

 /**
  * Checks that response body contains JSON from PyString.
  *
  * Do not check that the response body /only/ contains the JSON from PyString,
  *
  * @param PyStringNode $jsonString
  *
  * @throws \RuntimeException
  *
  * @Then /^(?:the )?response should contain json:$/
  */
 public function theResponseShouldContainJson(PyStringNode $jsonString)
 {
     $etalon = json_decode($this->replacePlaceHolder($jsonString->getRaw()), true);
     $actual = $this->response->json();
     if (null === $etalon) {
         throw new \RuntimeException("Can not convert etalon to json:\n" . $this->replacePlaceHolder($jsonString->getRaw()));
     }
     $factory = new SimpleFactory();
     $matcher = $factory->createMatcher();
     Assertions::assertTrue($matcher->match($actual, $etalon));
 }
开发者ID:nabelhm,项目名称:api,代码行数:22,代码来源:WebApiContext.php

示例12: assertResponseMatch

 /**
  * Asserts response match with the response schema.
  *
  * @param ResponseInterface $response
  * @param SchemaManager $schemaManager
  * @param string $path percent-encoded path used on the request.
  * @param string $httpMethod
  * @param string $message
  */
 public function assertResponseMatch(ResponseInterface $response, SchemaManager $schemaManager, $path, $httpMethod, $message = '')
 {
     $this->assertResponseMediaTypeMatch($response->getHeader('Content-Type'), $schemaManager, $path, $httpMethod, $message);
     $httpCode = $response->getStatusCode();
     $headers = $response->getHeaders();
     foreach ($headers as &$value) {
         $value = implode(', ', $value);
     }
     $this->assertResponseHeadersMatch($headers, $schemaManager, $path, $httpMethod, $httpCode, $message);
     $this->assertResponseBodyMatch($response->json(['object' => true]), $schemaManager, $path, $httpMethod, $httpCode, $message);
 }
开发者ID:Beanhunter,项目名称:SwaggerAssertions,代码行数:20,代码来源:GuzzleAssertsTrait.php

示例13: __construct

 public function __construct(RequestInterface $request, ResponseInterface $response)
 {
     $payload = $response->json();
     $this->id = $payload['id'];
     $result = $payload['result'];
     $this->status = [];
     if (isset($result['status'])) {
         $this->status = $result['status'];
         unset($result['status']);
     }
     parent::__construct($result);
 }
开发者ID:lacunaphp,项目名称:api-client,代码行数:12,代码来源:Result.php

示例14: theResponseShouldContainJson

 /**
  * Checks that response body contains JSON from PyString.
  *
  * Do not check that the response body /only/ contains the JSON from PyString,
  *
  * @param PyStringNode $jsonString
  *
  * @throws \RuntimeException
  *
  * @Then /^(?:the )?response should contain json:$/
  */
 public function theResponseShouldContainJson(PyStringNode $jsonString)
 {
     $etalon = json_decode($this->replacePlaceHolder($jsonString->getRaw()), true);
     $actual = $this->response->json();
     if (null === $etalon) {
         throw new \RuntimeException("Can not convert etalon to json:\n" . $this->replacePlaceHolder($jsonString->getRaw()));
     }
     Assertions::assertGreaterThanOrEqual(count($etalon), count($actual));
     foreach ($etalon as $key => $needle) {
         Assertions::assertArrayHasKey($key, $actual);
         Assertions::assertEquals($etalon[$key], $actual[$key]);
     }
 }
开发者ID:pavelsmolka,项目名称:WebApiExtension,代码行数:24,代码来源:WebApiContext.php

示例15: __construct

 /**
  * Creates a new Funnelback response.
  *
  * @param \GuzzleHttp\Message\ResponseInterface $http_response
  *   The http response.
  */
 public function __construct(ResponseInterface $http_response)
 {
     $this->httpResponse = $http_response;
     $this->responseJson = $http_response->json();
     $this->query = $this->responseJson['question']['query'];
     $response = $this->responseJson['response'];
     $this->returnCode = $response['returnCode'];
     $this->totalTimeMillis = $response['performanceMetrics']['totalTimeMillis'];
     $result_packet = $response['resultPacket'];
     $this->resultsSummary = new ResultSummary($result_packet['resultsSummary']);
     $this->results = $this->buildResults($result_packet['results']);
     $this->facets = $this->buildFacets($response['facets']);
 }
开发者ID:matason,项目名称:funnelback-php,代码行数:19,代码来源:Response.php


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