當前位置: 首頁>>代碼示例>>PHP>>正文


PHP RequestInterface::withHeader方法代碼示例

本文整理匯總了PHP中Psr\Http\Message\RequestInterface::withHeader方法的典型用法代碼示例。如果您正苦於以下問題:PHP RequestInterface::withHeader方法的具體用法?PHP RequestInterface::withHeader怎麽用?PHP RequestInterface::withHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Psr\Http\Message\RequestInterface的用法示例。


在下文中一共展示了RequestInterface::withHeader方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: fetchResumeUri

 private function fetchResumeUri()
 {
     $result = null;
     $body = $this->request->getBody();
     if ($body) {
         $headers = array('content-type' => 'application/json; charset=UTF-8', 'content-length' => $body->getSize(), 'x-upload-content-type' => $this->mimeType, 'x-upload-content-length' => $this->size, 'expect' => '');
         foreach ($headers as $key => $value) {
             $this->request = $this->request->withHeader($key, $value);
         }
     }
     $response = $this->client->execute($this->request, false);
     $location = $response->getHeaderLine('location');
     $code = $response->getStatusCode();
     if (200 == $code && true == $location) {
         return $location;
     }
     $message = $code;
     $body = json_decode((string) $this->request->getBody(), true);
     if (isset($body['error']['errors'])) {
         $message .= ': ';
         foreach ($body['error']['errors'] as $error) {
             $message .= "{$error[domain]}, {$error[message]};";
         }
         $message = rtrim($message, ';');
     }
     $error = "Failed to start the resumable upload (HTTP {$message})";
     $this->client->getLogger()->error($error);
     throw new GoogleException($error);
 }
開發者ID:Devids,項目名稱:google-api-php-client,代碼行數:29,代碼來源:MediaFileUpload.php

示例2: sign

 /**
  * @param \Psr\Http\Message\RequestInterface $request
  *
  * @return \Psr\Http\Message\RequestInterface
  */
 public function sign(RequestInterface $request)
 {
     $timestamp = (new \DateTime('now', new \DateTimeZone('UTC')))->getTimestamp();
     $data = implode('|', [$request->getMethod(), rtrim((string) $request->getUri(), '/'), $timestamp]);
     $signature = $this->signer->sign($data);
     return $request->withHeader(self::TIMESTAMP_HEADER, $timestamp)->withHeader(self::SIGNATURE_HEADER, $signature);
 }
開發者ID:livetyping,項目名稱:hermitage-php-client,代碼行數:12,代碼來源:RequestSigner.php

示例3: authenticate

 /**
  * {@inheritdoc}
  */
 public function authenticate(RequestInterface $request)
 {
     // TODO: add error handling
     // TODO: support other grant types?
     $accessToken = $this->provider->getAccessToken('client_credentials');
     return $request->withHeader('Authorization', 'Bearer ' . $accessToken);
 }
開發者ID:godmodelabs,項目名稱:flora-client-php-auth,代碼行數:10,代碼來源:OAuth2.php

示例4: authenticate

 /**
  * {@inheritdoc}
  */
 public function authenticate(RequestInterface $request)
 {
     // TODO: generate better nonce?
     $nonce = substr(md5(uniqid(uniqid() . '_', true)), 0, 16);
     $created = date('c');
     $digest = base64_encode(sha1(base64_decode($nonce) . $created . $this->password, true));
     $wsse = sprintf('UsernameToken Username="%s", PasswordDigest="%s", Nonce="%s", Created="%s"', $this->username, $digest, $nonce, $created);
     return $request->withHeader('Authorization', 'WSSE profile="UsernameToken"')->withHeader('X-WSSE', $wsse);
 }
開發者ID:php-http,項目名稱:message,代碼行數:12,代碼來源:Wsse.php

示例5: onRequest

 /**
  *
  * @param RequestInterface $request
  */
 public function onRequest(RequestInterface $request)
 {
     reset($this->headers);
     $newRequest = $request->withHeader('Host', $request->getUri()->getHost())->withHeader('User-Agent', self::USER_AGENT);
     $addHeaders = function (&$array, RequestInterface $request, callable $callback) {
         $item = each($array);
         if (!$item) {
             return $request;
         }
         return $callback($array, $request, $callback)->withHeader($item['key'], $item['value']);
     };
     return $addHeaders($this->headers, $newRequest, $addHeaders);
 }
開發者ID:softrog,項目名稱:gloo-client,代碼行數:17,代碼來源:HeaderMiddleware.php

示例6: __invoke

 /**
  * @param RequestInterface $request
  *
  * @return RequestInterface
  */
 public function __invoke(RequestInterface $request)
 {
     $uri = $request->getUri();
     $path = $uri->getPath();
     $path .= $uri->getQuery() != null ? '?' . $uri->getQuery() : '';
     $payload = ['key' => 'master', 'exp' => time() + $this->exp, 'method' => $request->getMethod(), 'path' => $path];
     if (in_array($request->getMethod(), ['PUT', 'POST'])) {
         $body = $request->getBody();
         $computedHash = \GuzzleHttp\Psr7\hash($body, 'sha256');
         $payload['body'] = ['alg' => 'sha256', 'hash' => $computedHash];
     }
     $jws = new JWS(['typ' => 'JWT', 'alg' => 'HS256']);
     $jws->setPayload($payload)->sign($this->secret);
     $token = $jws->getTokenString();
     return $request->withHeader('Authorization', 'JWT token="' . $token . '"');
 }
開發者ID:caxy,項目名稱:badgekit-client,代碼行數:21,代碼來源:JwtMiddleware.php

示例7: addHeaderToRequest

 /**
  * @param string $header
  * @param string|string[] $value
  */
 public function addHeaderToRequest($header, $value)
 {
     $this->request = $this->request->withHeader($header, $value);
 }
開發者ID:jacmoe,項目名稱:php-workshop,代碼行數:8,代碼來源:CgiExecuteEvent.php

示例8: withHeader

 public function withHeader($name, $value)
 {
     $new = clone $this;
     $new->request = $this->request->withHeader($name, $value);
     return $new;
 }
開發者ID:deepfreeze,項目名稱:zend-diactoros,代碼行數:6,代碼來源:Request.php

示例9: __construct

 /**
  * @since 2.0.0
  * @param string $dsn Data Source Name
  */
 public function __construct($dsn)
 {
     $this->driver = new CurlDriver();
     $this->request = new Request($dsn);
     $this->request->withHeader('Content-Type', 'application/json');
 }
開發者ID:jpcsupplies,項目名稱:bitcoind-php,代碼行數:10,代碼來源:Client.php

示例10: applyRequest

 /**
  * {@inheritdoc}
  */
 public function applyRequest(HttpRequestInterface $request, array $options)
 {
     return $request->withHeader('Accept-Encoding', 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3')->withHeader('Content-Type', 'application/json');
 }
開發者ID:yashb,項目名稱:generator,代碼行數:7,代碼來源:RequestHeaderMiddleware.php

示例11: handleRequest

 /**
  * Add authentication data to the request and sends it. Calls handleResponse when done.
  *
  * @param RequestInterface $request
  *
  * @return mixed
  */
 protected function handleRequest(RequestInterface $request, array $requestOptions = [])
 {
     $request->withHeader('Authorization', 'Bearer ' . $this->options['token']);
     try {
         $response = $this->httpClient->send($request);
     } catch (ClientException $ex) {
         return $this->handleResponse($ex->getResponse());
     }
     return $this->handleResponse($response, $requestOptions);
 }
開發者ID:eresults,項目名稱:unity-php-api,代碼行數:17,代碼來源:Client.php

示例12: withHeader

 /**
  * @param string $header
  * @param string|\string[] $value
  * @return \Psr\Http\Message\MessageInterface
  */
 public function withHeader($header, $value)
 {
     $this->request = $this->request->withHeader($header, $value);
     return $this;
 }
開發者ID:bweston92,項目名稱:expressive-async,代碼行數:10,代碼來源:ServerRequest.php

示例13: authenticate

 /**
  * {@inheritdoc}
  */
 public function authenticate(RequestInterface $request)
 {
     $header = sprintf('Basic %s', base64_encode(sprintf('%s:%s', $this->username, $this->password)));
     return $request->withHeader('Authorization', $header);
 }
開發者ID:php-http,項目名稱:message,代碼行數:8,代碼來源:BasicAuth.php

示例14: __invoke

 /**
  * Add HTTP header to request.
  *
  * {@inheritdoc}
  */
 public function __invoke(Request $request, Response $response, callable $next)
 {
     return call_user_func($next, $request->withHeader(self::HEADER, $this->key), $response);
 }
開發者ID:Teknologica,項目名稱:rebilly-php,代碼行數:9,代碼來源:ApiKeyAuthentication.php

示例15: __invoke

 public function __invoke(RequestInterface $request, array $options)
 {
     $fn = $this->nextHandler;
     if (!isset($options['oxygen_site']) || !$options['oxygen_site'] instanceof Site) {
         throw new \RuntimeException(sprintf('The option "oxygen_site" is expected to contain an instance of %s.', Site::class));
     }
     if (!isset($options['oxygen_action']) || !$options['oxygen_action'] instanceof ActionInterface) {
         throw new \RuntimeException(sprintf('The option "oxygen_action" is expected to contain an instance of %s.', ActionInterface::class));
     }
     $transferInfo = $previousCallable = null;
     if (isset($options['on_stats'])) {
         $previousCallable = $options['on_stats'];
     }
     $options['on_stats'] = function (TransferStats $stats) use(&$transferInfo, $previousCallable) {
         $transferInfo = new TransferInfo($stats->getHandlerStats());
         if ($previousCallable) {
             /* @var callable $previousCallable */
             $previousCallable($stats);
         }
     };
     /** @var Site $site */
     $site = $options['oxygen_site'];
     /** @var ActionInterface $action */
     $action = $options['oxygen_action'];
     $options['request_id'] = $requestId = \Undine\Functions\generate_uuid();
     // Kind of like str_rot8, for hexadecimal strings.
     $responseId = strtr($requestId, 'abcdef0123456789', '23456789abcdef01');
     $expiresAt = time() + 86400;
     $userName = '';
     $stateParameters = $this->stateTracker->getParameters($site);
     $requestData = ['oxygenRequestId' => $requestId, 'requestExpiresAt' => $expiresAt, 'publicKey' => $site->getPublicKey(), 'signature' => \Undine\Functions\openssl_sign_data($site->getPrivateKey(), sprintf('%s|%d', $requestId, $expiresAt)), 'handshakeKey' => $this->handshakeKeyName, 'handshakeSignature' => \Undine\Functions\openssl_sign_data($this->handshakeKeyValue, $this->getUrlSlug($site->getUrl())), 'version' => $this->moduleVersion, 'baseUrl' => (string) $site->getUrl(), 'actionName' => $action->getName(), 'actionParameters' => $action->getParameters(), 'userName' => $userName, 'userId' => $site->getUser()->getId(), 'stateParameters' => $stateParameters];
     $oxygenRequest = $request->withHeader('accept', 'text/html,application/json,application/oxygen')->withBody(\GuzzleHttp\Psr7\stream_for(json_encode($requestData)));
     if ($site->hasHttpCredentials()) {
         $oxygenRequest = $oxygenRequest->withHeader('Authorization', 'Basic ' . base64_encode(sprintf('%s:%s', $site->getHttpCredentials()->getUsername(), $site->getHttpCredentials()->getPassword())));
     }
     return $fn($oxygenRequest, $options)->then(function (ResponseInterface $response) use($site, $request, $options, &$transferInfo, $responseId, $action) {
         $responseData = $this->extractData($responseId, $request, $options, $response, $transferInfo);
         try {
             $reaction = $this->createReaction($action, $responseData);
         } catch (ExceptionInterface $e) {
             throw new ResponseException(ResponseException::ACTION_RESULT_MALFORMED, $request, $options, $response, $transferInfo, $e);
         }
         try {
             $this->stateTracker->setResult($site, $responseData['stateResult']);
         } catch (\Exception $e) {
             throw new ResponseException(ResponseException::STATE_MALFORMED, $request, $options, $response, $transferInfo, $e);
         }
         return $reaction;
     }, function (RequestException $e) use($options, &$transferInfo) {
         throw new NetworkException($e->getHandlerContext()['errno'], $e->getRequest(), $options, $e->getResponse(), $transferInfo);
     })->otherwise(function (\Exception $exception) use($site) {
         $this->stateTracker->setException($site, $exception);
         throw $exception;
     });
 }
開發者ID:Briareos,項目名稱:Undine,代碼行數:55,代碼來源:OxygenProtocolMiddleware.php


注:本文中的Psr\Http\Message\RequestInterface::withHeader方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。