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

PHP Message\RequestInterface类代码示例

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

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



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


示例16: assertRequestHasPostParameter

 protected function assertRequestHasPostParameter($parameterName, $expectedValue, RequestInterface $request)
 {
     /** @var PostBody $requestBody */
     $requestBody = $request->getBody();
     $this->assertNotEmpty($requestBody);
     $this->assertInstanceOf(PostBody::class, $requestBody);
     $actualValue = $requestBody->getField($parameterName);
     $this->assertNotNull($actualValue, "The request should have the post body parameter '{$parameterName}'");
     $this->assertEquals($expectedValue, $actualValue);
 }
开发者ID:fgrosse,项目名称:gitlab-api,代码行数:10,代码来源:GitlabGuzzleClientTest.php


示例17: after

 public function after(CommandInterface $command, RequestInterface $request, Operation $operation, array $context)
 {
     $additional = $operation->getAdditionalParameters();
     if ($additional && $additional->getLocation() == $this->locationName) {
         foreach ($command->toArray() as $key => $value) {
             if (!$operation->hasParam($key)) {
                 $request->setHeader($key, $additional->filter($value));
             }
         }
     }
 }
开发者ID:ryanwinchester-forks,项目名称:guzzle-services,代码行数:11,代码来源:HeaderLocation.php


示例18: __construct

 public function __construct(RequestInterface $pRequest)
 {
     /** url parsing "formula" for resource */
     list(, $subscription, $format, , $season, $week) = explode('/', $pRequest->getPath());
     $file_partial = __DIR__ . '/' . implode('.', [$subscription, $format, $season, $week]);
     $headers = (include $file_partial . '.header.php');
     $response_code = explode(' ', $headers[0])[1];
     $mocked_response = file_get_contents($file_partial . '.body.' . $format);
     $stream = Stream\Stream::factory($mocked_response);
     parent::__construct($response_code, $headers, $stream);
 }
开发者ID:JJVV27,项目名称:FantasyDataAPI,代码行数:11,代码来源:Mock.php


示例19: applyRequestHeaders

 /**
  * Applies request headers to a request based on the POST state
  *
  * @param RequestInterface $request Request to update
  */
 public function applyRequestHeaders(RequestInterface $request)
 {
     if ($this->files || $this->forceMultipart) {
         $request->setHeader('Content-Type', 'multipart/form-data; boundary=' . $this->getBody()->getBoundary());
     } elseif ($this->fields) {
         $request->setHeader('Content-Type', 'application/x-www-form-urlencoded');
     }
     if ($size = $this->getSize()) {
         $request->setHeader('Content-Length', $size);
     }
 }
开发者ID:GTAWWEKID,项目名称:tsiserver.us,代码行数:16,代码来源:PostBody.php


示例20: after

 public function after(GuzzleCommandInterface $command, RequestInterface $request, Operation $operation, array $context)
 {
     $additional = $operation->getAdditionalParameters();
     if ($additional && $additional->getLocation() == $this->locationName) {
         foreach ($command->toArray() as $key => $value) {
             if (!$operation->hasParam($key)) {
                 $request->getQuery()[$key] = $this->prepareValue($value, $additional);
             }
         }
     }
 }
开发者ID:daskleinesys,项目名称:slimpd,代码行数:11,代码来源:QueryLocation.php



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP Message\Response类代码示例发布时间:2022-05-23
下一篇:
PHP Exception\RequestException类代码示例发布时间: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