本文整理汇总了PHP中GuzzleHttp\Message\ResponseInterface类的典型用法代码示例。如果您正苦于以下问题:PHP ResponseInterface类的具体用法?PHP ResponseInterface怎么用?PHP ResponseInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ResponseInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
public function parse(Session $rets, ResponseInterface $response, $parameters)
{
$xml = $response->xml();
$rs = new Results();
$rs->setSession($rets)->setResource($parameters['SearchType'])->setClass($parameters['Class']);
if ($this->getRestrictedIndicator($rets, $xml, $parameters)) {
$rs->setRestrictedIndicator($this->getRestrictedIndicator($rets, $xml, $parameters));
}
$rs->setHeaders($this->getColumnNames($rets, $xml, $parameters));
$rets->debug(count($rs->getHeaders()) . ' column headers/fields given');
$this->parseRecords($rets, $xml, $parameters, $rs);
if ($this->getTotalCount($rets, $xml, $parameters) !== null) {
$rs->setTotalResultsCount($this->getTotalCount($rets, $xml, $parameters));
$rets->debug($rs->getTotalResultsCount() . ' total results found');
}
$rets->debug($rs->getReturnedResultsCount() . ' results given');
if ($this->foundMaxRows($rets, $xml, $parameters)) {
// MAXROWS tag found. the RETS server withheld records.
// if the server supports Offset, more requests can be sent to page through results
// until this tag isn't found anymore.
$rs->setMaxRowsReached();
$rets->debug('Maximum rows returned in response');
}
unset($xml);
return $rs;
}
示例2: 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;
}
示例3: populateFromResponse
/**
* {@inheritDoc}
*/
public function populateFromResponse(ResponseInterface $response)
{
$entries = $response->json()['access']['serviceCatalog'];
foreach ($entries as $entry) {
$this->entries[] = $this->model('Entry', $entry);
}
}
示例4: 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']];
}
示例5: parse
public function parse(Session $rets, ResponseInterface $response)
{
$xml = $response->xml();
$base = $xml->METADATA->{'METADATA-SYSTEM'};
$metadata = new \PHRETS\Models\Metadata\System();
$metadata->setSession($rets);
$configuration = $rets->getConfiguration();
if ($configuration->getRetsVersion()->is1_5()) {
if (isset($base->System->SystemID)) {
$metadata->setSystemId((string) $base->System->SystemID);
}
if (isset($base->System->SystemDescription)) {
$metadata->setSystemDescription((string) $base->System->SystemDescription);
}
} else {
if (isset($base->SYSTEM->attributes()->SystemID)) {
$metadata->setSystemId((string) $base->SYSTEM->attributes()->SystemID);
}
if (isset($base->SYSTEM->attributes()->SystemDescription)) {
$metadata->setSystemDescription((string) $base->SYSTEM->attributes()->SystemDescription);
}
if (isset($base->SYSTEM->attributes()->TimeZoneOffset)) {
$metadata->setTimezoneOffset((string) $base->SYSTEM->attributes()->TimeZoneOffset);
}
}
if (isset($base->SYSTEM->Comments)) {
$metadata->setComments((string) $base->SYSTEM->Comments);
}
if (isset($base->attributes()->Version)) {
$metadata->setVersion((string) $xml->METADATA->{'METADATA-SYSTEM'}->attributes()->Version);
}
return $metadata;
}
示例6: isNotJsonError
private function isNotJsonError(HttpResponseInterface $httpResponse)
{
if ($httpResponse->getStatusCode() == ResponseInterface::HTTP_CODE_NOT_FOUND || $httpResponse->getStatusCode() == ResponseInterface::HTTP_CODE_INTERNAL_SERVER_ERROR || $httpResponse->getStatusCode() == ResponseInterface::HTTP_CODE_METHOD_NOT_ALLOWED) {
return true;
}
return false;
}
示例7: 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]);
}
示例8: __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();
}
示例9:
function it_should_make_post_request(ResponseInterface $responce)
{
$responce->getHeader("Content-Type")->willReturn('blablaxmlblabla');
$responce->getBody()->willReturn('<xml></xml>');
$this->client->post(Argument::any(), Argument::any())->willReturn($responce);
$responce->xml()->willReturn(new \SimpleXMLElement('<xml></xml>'));
$this->post(Argument::type('string'))->shouldBeAnInstanceOf('Bxav\\Component\\ResellerClub\\Model\\XmlResponse');
}
示例10: __construct
/**
* Sets attributes from response xml.
*
* @param ResponseInterface $response
* @param array $attributes
*/
public function __construct(ResponseInterface $response, array $attributes = null)
{
$this->response = $response;
if (is_null($attributes)) {
$attributes = Xml::elementsToArray($response->xml()->xpath('/RESPONSE/FIELDS/*'));
}
parent::__construct($attributes);
}
示例11: setResponse
/**
* Set Http response in case of successful request
*
* @param GuzzleHttp\Message\ResponseInterface $response
* @return CurrencyExchange\HttpClient
* @throws CurrencyExchange\Exception\ResponseException
*/
public function setResponse(ResponseInterface $response)
{
if ($response->getStatusCode() != 200) {
throw new ResponseException('Unsuccessful HTTP request: ' . $response->getStatusCode() . ' on ' . $this->getUri());
}
$this->_response = $response;
return $this;
}
示例12: __construct
/**
* @param ResponseInterface $response raw json response
* @param bool $throw Should throw API errors as exceptions
*
* @throws \Exception
*/
public function __construct(ResponseInterface $response = null, $throw = true)
{
if ($response !== null) {
$this->_executionTime = $response->getHeader('X-Execution-Time');
$this->_callTime = $response->getHeader('X-Call-Time');
$this->readJson((string) $response->getBody(), $throw);
}
}
示例13: getCount
public function getCount($content, ResponseInterface $response = null)
{
$data = $response->json();
if (empty($data)) {
return false;
}
return (int) array_shift($data)['shares'];
}
示例14: formatHeaders
/**
* @param RequestInterface|ResponseInterface $message
* @return string
*/
protected function formatHeaders($message)
{
$headers = [];
foreach ($message->getHeaders() as $header => $value) {
$headers[] = sprintf('%s: %s', $header, implode("\n : ", $value));
}
return implode("\n", $headers);
}
示例15: parseHeaders
private function parseHeaders(ResponseInterface $response, array &$data)
{
$data['message'] = $response->getStatusCode() . ' ' . $response->getReasonPhrase();
if ($requestId = $response->getHeader('x-amz-request-id')) {
$data['request_id'] = $requestId;
$data['message'] .= " (Request-ID: {$requestId})";
}
}