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


PHP Message\RequestInterface类代码示例

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


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

示例1: send

 /**
  * {@inheritdoc}
  *
  * @return array
  */
 public function send(RequestInterface $request)
 {
     // Disable HTTP error codes unless requested so that we can parse out
     // the errors ourselves.
     if (!$request->getQuery()->hasKey('httpError')) {
         $request->getQuery()->set('httpError', 'false');
     }
     $response = parent::send($request);
     // Parse out exceptions from the response body.
     $contentType = $response->getHeader('Content-Type');
     if (preg_match('~^(application|text)/json~', $contentType)) {
         // @todo Figure out how we can support the big_int_string option here.
         // @see http://stackoverflow.com/questions/19520487/json-bigint-as-string-removed-in-php-5-5
         $data = $response->json();
         if (!empty($data['responseCode']) && !empty($data['isException'])) {
             throw new ApiException("Error {$data['title']} on request to {$request->getUrl()}: {$data['description']}", (int) $data['responseCode']);
         } elseif (!empty($data[0]['entry']['responseCode']) && !empty($data[0]['entry']['isException'])) {
             throw new ApiException("Error {$data[0]['entry']['title']} on request to {$request->getUrl()}: {$data[0]['entry']['description']}", (int) $data[0]['entry']['responseCode']);
         }
         return $data;
     } elseif (preg_match('~^(application|text)/(atom\\+)?xml~', $contentType)) {
         if (strpos((string) $response->getBody(), 'xmlns:e="http://xml.theplatform.com/exception"') !== FALSE) {
             if (preg_match('~<e:title>(.+)</e:title><e:description>(.+)</e:description><e:responseCode>(.+)</e:responseCode>~', (string) $response->getBody(), $matches)) {
                 throw new ApiException("Error {$matches[1]} on request to {$request->getUrl()}: {$matches[2]}", (int) $matches[3]);
             } elseif (preg_match('~<title>(.+)</title><summary>(.+)</summary><e:responseCode>(.+)</e:responseCode>~', (string) $response->getBody(), $matches)) {
                 throw new ApiException("Error {$matches[1]} on request to {$request->getUrl()}: {$matches[2]}", (int) $matches[3]);
             }
         }
         $data = $response->xml();
         $data = array($data->getName() => static::convertXmlToArray($data));
         return $data;
     } else {
         throw new ParseException("Unable to handle response with type {$contentType}.", $response);
     }
 }
开发者ID:lullabot,项目名称:mpx-php,代码行数:40,代码来源:Client.php

示例2: signRequest

 /**
  * Always add a x-amz-content-sha-256 for data integrity.
  */
 public function signRequest(RequestInterface $request, CredentialsInterface $credentials)
 {
     if (!$request->hasHeader('x-amz-content-sha256')) {
         $request->setHeader('X-Amz-Content-Sha256', $this->getPayload($request));
     }
     parent::signRequest($request, $credentials);
 }
开发者ID:briareos,项目名称:aws-sdk-php,代码行数:10,代码来源:S3SignatureV4.php

示例3: after

 public function after(GuzzleCommandInterface $command, RequestInterface $request, Operation $operation, array $context)
 {
     foreach ($this->buffered as $param) {
         $this->visitWithValue($command[$param->getName()], $param, $command);
     }
     $this->buffered = array();
     $additional = $operation->getAdditionalParameters();
     if ($additional && $additional->getLocation() == $this->locationName) {
         foreach ($command->toArray() as $key => $value) {
             if (!$operation->hasParam($key)) {
                 $additional->setName($key);
                 $this->visitWithValue($value, $additional, $command);
             }
         }
         $additional->setName(null);
     }
     // If data was found that needs to be serialized, then do so
     $xml = null;
     if ($this->writer) {
         $xml = $this->finishDocument($this->writer);
     } elseif ($operation->getData('xmlAllowEmpty')) {
         // Check if XML should always be sent for the command
         $writer = $this->createRootElement($operation);
         $xml = $this->finishDocument($writer);
     }
     if ($xml) {
         $request->setBody(Stream::factory($xml));
         // Don't overwrite the Content-Type if one is set
         if ($this->contentType && !$request->hasHeader('Content-Type')) {
             $request->setHeader('Content-Type', $this->contentType);
         }
     }
     $this->writer = null;
 }
开发者ID:bobozhangshao,项目名称:HeartCare,代码行数:34,代码来源:XmlLocation.php

示例4: addExpectHeader

 private function addExpectHeader(RequestInterface $request, StreamInterface $body)
 {
     // Determine if the Expect header should be used
     if ($request->hasHeader('Expect')) {
         return;
     }
     $expect = $request->getConfig()['expect'];
     // Return if disabled or if you're not using HTTP/1.1
     if ($expect === false || $request->getProtocolVersion() !== '1.1') {
         return;
     }
     // The expect header is unconditionally enabled
     if ($expect === true) {
         $request->setHeader('Expect', '100-Continue');
         return;
     }
     // By default, send the expect header when the payload is > 1mb
     if ($expect === null) {
         $expect = 1048576;
     }
     // Always add if the body cannot be rewound, the size cannot be
     // determined, or the size is greater than the cutoff threshold
     $size = $body->getSize();
     if ($size === null || $size >= (int) $expect || !$body->isSeekable()) {
         $request->setHeader('Expect', '100-Continue');
     }
 }
开发者ID:ChenOhayon,项目名称:sitepoint_codes,代码行数:27,代码来源:Prepare.php

示例5: buildRequest

 public function buildRequest(GuzzleRequestInterface $request)
 {
     if (!$this->query) {
         throw new \UnexpectedValueException(sprintf('CharacterSearchRequest requires at least a search query.'));
     }
     $query = $request->getQuery();
     $query->set('q', $this->getQuery());
     if ($this->getClass()) {
         $query->set('classjob', $this->getClass());
     }
     if ($this->getWorld()) {
         $query->set('worldname', $this->getWorld());
     }
     if ($this->getRace()) {
         $query->set('race_tribe', $this->getRace());
     }
     if ($this->getGrandCompanies()) {
         $query->set('gcid', $this->getGrandCompanies());
     }
     if ($this->getLanguages()) {
         $query->set('blog_lang', $this->getLanguages());
     }
     if ($this->getPage()) {
         $query->set('page', $this->getPage());
     }
     if ($this->getOrder()) {
         $query->set('order', $this->getOrder());
     } else {
         $query->set('order', static::ORDER_NAME_ASC);
     }
 }
开发者ID:ghassani,项目名称:xiv-lodestone-php-api,代码行数:31,代码来源:CharacterSearchRequest.php

示例6: setRequestParams

 /**
  * 
  * @param RequestInterface $request
  * @param array $params
  */
 protected function setRequestParams(RequestInterface $request, $params = array())
 {
     $query = $request->getQuery();
     foreach ($params as $param) {
         $query->set(key($param), current($param));
     }
 }
开发者ID:adurolms,项目名称:tincan,代码行数:12,代码来源:LRSRepository.php

示例7: buildRequest

 /**
  * @param RequestInterface $request
  * @param bool $acceptJsonResponse
  */
 protected function buildRequest(RequestInterface $request, $acceptJsonResponse = true)
 {
     if ($acceptJsonResponse) {
         $request->addHeader('Accept', 'application/json');
     }
     $request->addHeader('Accept-Charset', 'UTF-8');
 }
开发者ID:schibsted-tech-polska,项目名称:php-sndapi,代码行数:11,代码来源:Client.php

示例8: assertAuthorization

 /**
  * Asserts that the authorization header is correct.
  *
  * @param RequestInterface $request Request to test
  *
  * @return void
  */
 protected function assertAuthorization(RequestInterface $request)
 {
     list($alg, $digest) = explode(' ', $request->getHeader('Authorization'));
     $this->assertEquals('Basic', $alg);
     $expected = self::MERCHANT_ID . ':' . self::SHARED_SECRET;
     $this->assertEquals($expected, base64_decode($digest));
 }
开发者ID:NoviumDesign,项目名称:polefitness,代码行数:14,代码来源:ResourceTestCase.php

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

示例10: __construct

 /**
  * @param string           $message
  * @param RequestInterface $request
  */
 public function __construct($message = null, RequestInterface $request = null)
 {
     $message = $message ?: $this->message;
     if ($request !== null) {
         $message .= "\nRequest URL: " . $request->getUrl();
     }
     parent::__construct($message, $this->code);
 }
开发者ID:CompanyOnTheWorld,项目名称:platformsh-cli,代码行数:12,代码来源:HttpExceptionBase.php

示例11: 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);
 }
开发者ID:glooby,项目名称:debug-bundle,代码行数:12,代码来源:AbstractMessageFormatter.php

示例12: buildMessage

 /**
  * @param RequestInterface $request
  * @param ResponseInterface $response
  * @return string
  */
 protected function buildMessage($request, $response)
 {
     $resource = $this->getResponseBody();
     if (is_null($resource)) {
         $resource = '';
     }
     $message = sprintf('[url] %s [http method] %s [status code] %s [reason phrase] %s: %s', $request->getUrl(), $request->getMethod(), $response->getStatusCode(), $response->getReasonPhrase(), $resource);
     return $message;
 }
开发者ID:finix-payments,项目名称:processing-php-client,代码行数:14,代码来源:HalException.php

示例13: isRequestAuthorized

 /**
  * @param RequestInterface $httpRequest The HTTP request before it is sent.
  * @return bool false if the request needs to be authorized
  */
 private function isRequestAuthorized(RequestInterface $httpRequest)
 {
     $authorization = trim($httpRequest->getHeader('Authorization'));
     if (!$authorization) {
         return false;
     } else {
         return strpos($authorization, 'Basic') === 0;
     }
 }
开发者ID:finix-payments,项目名称:processing-php-client,代码行数:13,代码来源:BasicAuthentication.php

示例14: __construct

 /**
  * Gets the relevant data from the Guzzle clients.
  *
  * @param RequestInterface $request
  * @param ResponseInterface $response
  */
 public function __construct(RequestInterface $request, ResponseInterface $response)
 {
     if ($response instanceof FutureResponse) {
         $this->httpStatusCode = null;
     } else {
         $this->httpStatusCode = $response->getStatusCode();
     }
     $this->requestUrl = $request->getUrl();
 }
开发者ID:HeidiWang123,项目名称:our-world-in-data-grapher,代码行数:15,代码来源:AnalyticsResponse.php

示例15: setGuzzleHeaders

 /**
  * Set Headers for a Request specified by $headers.
  *
  * @param RequestInterface $request a Guzzle Request
  * @param array            $headers headers to set (should be an assoc array).
  */
 private function setGuzzleHeaders(RequestInterface $request, array $headers)
 {
     //iterate over the headers array and set each item
     foreach ($headers as $key => $value) {
         //Sets Header
         $request->setHeader($key, $value);
     }
     //return the request
     return $request;
 }
开发者ID:backupManager,项目名称:Twitter-API-PHP,代码行数:16,代码来源:Connection.php


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