• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Message\Response类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: parseQuery

 /**
  * @param Response $response
  * @return array
  */
 public static function parseQuery(Response $response)
 {
     $responseBody = $response->getBody();
     $params = [];
     parse_str($responseBody, $params);
     return $params;
 }
开发者ID:assad2012,项目名称:EvaOAuth,代码行数:11,代码来源:ResponseParser.php


示例2: createResponse

 /**
  * Taken from Mink\BrowserKitDriver
  *
  * @param Response $response
  *
  * @return \Symfony\Component\BrowserKit\Response
  */
 protected function createResponse(Response $response)
 {
     $contentType = $response->getHeader('Content-Type');
     $matches = null;
     if (!$contentType or strpos($contentType, 'charset=') === false) {
         $body = $response->getBody(true);
         if (preg_match('/\\<meta[^\\>]+charset *= *["\']?([a-zA-Z\\-0-9]+)/i', $body, $matches)) {
             $contentType .= ';charset=' . $matches[1];
         }
         $response->setHeader('Content-Type', $contentType);
     }
     $headers = $response->getHeaders();
     $status = $response->getStatusCode();
     $matchesMeta = null;
     $matchesHeader = null;
     $isMetaMatch = preg_match('/\\<meta[^\\>]+http-equiv="refresh" content="(\\d*)\\s*;?\\s*url=(.*?)"/i', $response->getBody(true), $matchesMeta);
     $isHeaderMatch = preg_match('~(\\d*);?url=(.*)~', (string) $response->getHeader('Refresh'), $matchesHeader);
     $matches = $isMetaMatch ? $matchesMeta : $matchesHeader;
     if (!empty($matches) && (empty($matches[1]) || $matches[1] < $this->refreshMaxInterval)) {
         $uri = $this->getAbsoluteUri($matches[2]);
         $partsUri = parse_url($uri);
         $partsCur = parse_url($this->getHistory()->current()->getUri());
         foreach ($partsCur as $key => $part) {
             if ($key === 'fragment') {
                 continue;
             }
             if (!isset($partsUri[$key]) || $partsUri[$key] !== $part) {
                 $status = 302;
                 $headers['Location'] = $uri;
                 break;
             }
         }
     }
     return new BrowserKitResponse($response->getBody(), $status, $headers);
 }
开发者ID:alexanderkuz,项目名称:test-yii2,代码行数:42,代码来源:Guzzle.php


示例3: formatProvider

 public function formatProvider()
 {
     $request = new Request('PUT', '/', ['x-test' => 'abc'], Stream::factory('foo'));
     $response = new Response(200, ['X-Baz' => 'Bar'], Stream::factory('baz'));
     $err = new RequestException('Test', $request, $response);
     return [['{request}', [$request], (string) $request], ['{response}', [$request, $response], (string) $response], ['{request} {response}', [$request, $response], $request . ' ' . $response], ['{request} {response}', [$request], $request . ' '], ['{req_headers}', [$request], "PUT / HTTP/1.1\r\nx-test: abc"], ['{res_headers}', [$request, $response], "HTTP/1.1 200 OK\r\nX-Baz: Bar"], ['{res_headers}', [$request], 'NULL'], ['{req_body}', [$request], 'foo'], ['{res_body}', [$request, $response], 'baz'], ['{res_body}', [$request], 'NULL'], ['{method}', [$request], $request->getMethod()], ['{url}', [$request], $request->getUrl()], ['{resource}', [$request], $request->getResource()], ['{req_version}', [$request], $request->getProtocolVersion()], ['{res_version}', [$request, $response], $response->getProtocolVersion()], ['{res_version}', [$request], 'NULL'], ['{host}', [$request], $request->getHost()], ['{hostname}', [$request, $response], gethostname()], ['{hostname}{hostname}', [$request, $response], gethostname() . gethostname()], ['{code}', [$request, $response], $response->getStatusCode()], ['{code}', [$request], 'NULL'], ['{phrase}', [$request, $response], $response->getReasonPhrase()], ['{phrase}', [$request], 'NULL'], ['{error}', [$request, $response, $err], 'Test'], ['{error}', [$request], 'NULL'], ['{req_header_x-test}', [$request], 'abc'], ['{req_header_x-not}', [$request], ''], ['{res_header_X-Baz}', [$request, $response], 'Bar'], ['{res_header_x-not}', [$request, $response], ''], ['{res_header_X-Baz}', [$request], 'NULL']];
 }
开发者ID:assad2012,项目名称:EvaOAuth,代码行数:7,代码来源:FormatterTest.php


示例4: __construct

 /**
  * Constructor
  *
  * @param GuzzleResponse $response
  */
 public function __construct(GuzzleResponse $response)
 {
     $headers = $response->getHeaders();
     //-- this is a hack on my part and I'm terribly sorry it exists
     //-- but deal with it.
     foreach ($headers as $header => $value) {
         $this->headers[$header] = implode(',', array_values((array) $value));
     }
     $this->url = $response->getEffectiveUrl();
     $url_parts = explode('?', $this->url);
     if (isset($url_parts[1])) {
         $query = explode('&', $url_parts[1]);
         foreach ($query as $params) {
             $kv = explode('=', $params);
             $this->params[$kv[0]] = isset($kv[1]) ? $kv[1] : '';
         }
     }
     // $this->params = $response->request_parameters;
     // $this->method = $response->request_method;
     $this->json = $response->json();
     // $json = json_decode($this->json, TRUE);
     $this->data = isset($this->json['data']) ? $this->json['data'] : [];
     $this->meta = isset($this->json['meta']) ? $this->json['meta'] : [];
     if (isset($this->json['code']) && $this->json['code'] !== 200) {
         $this->meta = $this->json;
     }
     $this->pagination = isset($this->json['pagination']) ? $this->json['pagination'] : [];
     $this->user = isset($this->json['user']) ? $this->json['user'] : [];
     $this->access_token = isset($this->json['access_token']) ? $this->json['access_token'] : NULL;
     $this->limit = isset($this->headers[self::RATE_LIMIT_HEADER]) ? $this->headers[self::RATE_LIMIT_HEADER] : 0;
     $this->remaining = isset($this->headers[self::RATE_LIMIT_REMAINING_HEADER]) ? $this->headers[self::RATE_LIMIT_REMAINING_HEADER] : 0;
 }
开发者ID:delta98,项目名称:Instaphp,代码行数:37,代码来源:Response.php


示例5: handleResponse

 protected function handleResponse(Response $response)
 {
     if ($response->getStatusCode() == 200) {
         return $response->getBody()->getContents();
     }
     throw new ApiException('Request failed, received the following status: ' . $response->getStatusCode() . ' Body: ' . $response->getBody()->getContents());
 }
开发者ID:erikdubbelboer,项目名称:atomx-api-php,代码行数:7,代码来源:ApiClient.php


示例6: getMessages

 protected function getMessages(Response $response)
 {
     $body = (string) $response->getBody();
     if (empty($body)) {
         throw new InvalidResponseException('There was no messages returned from the server at: ' . $this->uri);
     }
     $messages = array();
     $messageCounter = 0;
     while ($body) {
         $lineLengthHex = substr($body, 0, 4);
         if (strlen($lineLengthHex) != 4) {
             throw new InvalidResponseException('A corrupt package was received from the server.  Uri: ' . $this->uri);
         }
         if ($lineLengthHex == '0000') {
             $messageCounter++;
             $body = substr_replace($body, '', 0, 4);
             continue;
         }
         $lineLength = hexdec($lineLengthHex);
         $line = substr($body, 4, $lineLength - 4);
         $body = substr_replace($body, '', 0, $lineLength);
         $messages[$messageCounter][] = trim($line);
     }
     return $messages;
 }
开发者ID:reliv,项目名称:git,代码行数:25,代码来源:Client.php


示例7: debug

 function debug(\GuzzleHttp\Message\Response $response)
 {
     $this->dump_respuesta = 'status: ' . $response->getStatusCode() . "<br/>body: <br/>" . $response->getBody();
     //un string encodeado utf-8
     $this->dump_url = $response->getEffectiveUrl();
     //un string encodeado utf-8
 }
开发者ID:emma5021,项目名称:toba,代码行数:7,代码来源:ci_cliente_rest.php


示例8: getResponse

 protected function getResponse($body)
 {
     $stream = Stream::factory($body);
     $response = new Response(200);
     $response->setBody($stream);
     return $response;
 }
开发者ID:eclipsegc,项目名称:acquia-sdk-php-cloud-api,代码行数:7,代码来源:GuzzleTestClient.php


示例9: makeResponse

 /**
  * Create a Response object from a stub.
  *
  * @param $stub
  * @return \GuzzleHttp\Message\Response
  */
 private function makeResponse($stub)
 {
     $response = new Response(200);
     $response->setHeader('Content-Type', 'application/json');
     $responseBody = Stream::factory(fopen('./tests/Destiny/stubs/' . $stub . '.txt', 'r+'));
     $response->setBody($responseBody);
     return $response;
 }
开发者ID:EVPohovich,项目名称:EVPohovich.github.io,代码行数:14,代码来源:TestCase.php


示例10: getMockWithCode

 private function getMockWithCode($code, $body = null)
 {
     $response = new Response($code, array());
     if (isset($body) === true) {
         $response->setBody(Stream::factory(json_encode($body)));
     }
     $this->mockResponse = new Mock(array($response));
 }
开发者ID:everlytic,项目名称:api-wrapper,代码行数:8,代码来源:ApiTester.php


示例11: __construct

 /**
  * Response constructor
  *
  * @param  HttpResponse $httpResponse
  * @return self
  */
 public function __construct(HttpResponse $httpResponse)
 {
     if (stripos($httpResponse->getHeader('Content-Type'), 'text/javascript') !== false) {
         $this->_response = $this->processJson($httpResponse->getBody());
     } else {
         $this->_response = $this->processXml($httpResponse->getBody());
     }
 }
开发者ID:zimbra-api,项目名称:soap,代码行数:14,代码来源:Response.php


示例12: addClientMock

 /**
  * Adds a mock repsonse to the response queue
  *
  * @param \GuzzleHttp\Stream\Stream $data Stream data object
  * @param int $response_code desired response code
  */
 protected function addClientMock($data, $response_code = 200)
 {
     //create a response with the data and response code
     $api_response = new Response($response_code);
     $api_response->setBody($data);
     $mock_response = $this->getMockObject();
     $mock_response->addResponse($api_response);
 }
开发者ID:chielsen,项目名称:guzzle5-oauth2-subscriber,代码行数:14,代码来源:ClientTestCase.php


示例13: 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


示例14: saveResponseToFile

 protected function saveResponseToFile(Response &$response)
 {
     $fileName = __DIR__ . '\\json\\' . sizeof($this->fileHandles) . '.json';
     $reponseSavedToFile = file_put_contents($fileName, $response->getBody());
     if ($reponseSavedToFile != false) {
         $this->fileHandles[] = $fileName;
     }
     unset($response);
 }
开发者ID:EtienneLamoureux,项目名称:durmand-scriptorium,代码行数:9,代码来源:BatchRequestManager.php


示例15: validateBody

 public function validateBody(Response $response, Spec\Response $responseSpec)
 {
     $actualBody = (string) $response->getBody();
     $actualBodyData = json_decode($actualBody, true);
     if ($actualBodyData !== $responseSpec->getBody()) {
         $message = sprintf("\t\t<error>JSON in body of the response is invalid, actual:</error>\n%s\n\t\t<error>Expected:</error>\n%s", $this->getOutput()->formatArray($actualBodyData, 3), $this->getOutput()->formatArray($responseSpec->getBody(), 3));
         $this->addViolation($message);
     }
 }
开发者ID:talkrz,项目名称:rest-spec,代码行数:9,代码来源:Json.php


示例16: parse

 public static function parse(\GuzzleHttp\Message\Response $response)
 {
     $body = (string) $response->getBody();
     $params = json_decode($body, true);
     if ($params !== NULL) {
         return $params;
     }
     parse_str($body, $params);
     return $params;
 }
开发者ID:onefasteuro,项目名称:http-client,代码行数:10,代码来源:HttpClient.php


示例17: __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


示例18: getResponse

 private function getResponse(HttpResponse $httpResponse)
 {
     $response = new Response();
     if ($httpResponse->getBody()) {
         $resp = (string) $httpResponse->getBody();
         $decoded = json_decode($resp, true);
         $response->setBody($decoded);
     }
     return $response;
 }
开发者ID:EMPAT94,项目名称:Talent_Acquisition_System,代码行数:10,代码来源:GuzzleHttpClient.php


示例19: createMessage

 /**
  * @param Response $response
  *
  * @return string
  */
 protected static function createMessage(Response $response)
 {
     if ($response->getStatusCode() != 400) {
         return '[' . $response->getStatusCode() . '] A HTTP error has occurred: ' . $response->getBody(true);
     }
     $message = 'Some errors occurred:';
     foreach ($response->xml()->error as $error) {
         $message .= PHP_EOL . '[' . (string) $error->code . '] ' . (string) $error->message;
     }
     return $message;
 }
开发者ID:leonardorifeli,项目名称:pagseguro,代码行数:16,代码来源:PagSeguroException.php


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Message\ResponseInterface类代码示例发布时间:2022-05-23
下一篇:
PHP Message\RequestInterface类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap