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


PHP RequestInterface::getHeaderLine方法代码示例

本文整理汇总了PHP中Psr\Http\Message\RequestInterface::getHeaderLine方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestInterface::getHeaderLine方法的具体用法?PHP RequestInterface::getHeaderLine怎么用?PHP RequestInterface::getHeaderLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Psr\Http\Message\RequestInterface的用法示例。


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

示例1: signRequest

 public function signRequest(RequestInterface $request, CredentialsInterface $credentials)
 {
     $params = Psr7\parse_query($request->getBody());
     $params['Timestamp'] = gmdate('c');
     $params['SignatureVersion'] = '2';
     $params['SignatureMethod'] = 'HmacSHA256';
     $params['AWSAccessKeyId'] = $credentials->getAccessKeyId();
     if ($token = $credentials->getSecurityToken()) {
         $params['SecurityToken'] = $token;
     }
     // build string to sign
     $sign = $request->getMethod() . "\n" . $request->getHeaderLine('Host') . "\n" . '/' . "\n" . $this->getCanonicalizedParameterString($params);
     $params['Signature'] = base64_encode(hash_hmac('sha256', $sign, $credentials->getSecretKey(), true));
     return $request->withBody(Psr7\stream_for(http_build_query($params)));
 }
开发者ID:aws,项目名称:aws-sdk-php-v3-bridge,代码行数:15,代码来源:SignatureV2.php

示例2: signResponse

 /**
  * {@inheritDoc}
  */
 public function signResponse(ResponseInterface $response)
 {
     $authHeader = AuthorizationHeader::createFromRequest($this->request);
     $parts = [$authHeader->getNonce(), $this->request->getHeaderLine('X-Authorization-Timestamp'), (string) $response->getBody()];
     $message = implode("\n", $parts);
     $signature = $this->digest->sign($message, $this->key->getSecret());
     /** @var \Psr\Http\Message\ResponseInterface $response */
     $response = $response->withHeader('X-Server-Authorization-HMAC-SHA256', $signature);
     return $response;
 }
开发者ID:acquia,项目名称:http-hmac-php,代码行数:13,代码来源:ResponseSigner.php

示例3: getOverrideMethod

 /**
  * Returns the override method.
  * 
  * @param RequestInterface $request
  * 
  * @return string|null
  */
 private function getOverrideMethod(RequestInterface $request)
 {
     $method = $request->getHeaderLine(self::HEADER);
     if (!empty($method) && $method !== $request->getMethod()) {
         return strtoupper($method);
     }
 }
开发者ID:snapshotpl,项目名称:psr7-middlewares,代码行数:14,代码来源:MethodOverride.php

示例4: renderRequest

 /**
  * Render a PSR-7 request.
  *
  * @param RequestInterface $request
  * @return string
  */
 public function renderRequest(RequestInterface $request)
 {
     $return = '';
     $return .= sprintf("URL:     %s\n", $request->getUri());
     $return .= sprintf("METHOD:  %s\n", $request->getMethod());
     if ($request->getHeaders()) {
         $return .= 'HEADERS:';
     }
     $indent = false;
     foreach ($request->getHeaders() as $name => $values) {
         if ($indent) {
             $return .= str_repeat(' ', 8);
         }
         $return .= sprintf(" %s: %s\n", $name, implode(', ', $values));
         $indent = true;
     }
     if ($body = (string) $request->getBody()) {
         $return .= 'BODY:    ';
         switch ($request->getHeaderLine('Content-Type')) {
             case 'application/json':
                 $return .= json_encode(json_decode($body, true), JSON_PRETTY_PRINT);
                 break;
             default:
                 $return .= $body;
                 break;
         }
         $return .= "\n";
     }
     return $return;
 }
开发者ID:php-school,项目名称:php-workshop,代码行数:36,代码来源:RequestRenderer.php

示例5: getRequestHeaders

 /**
  * @param RequestInterface $request
  * @return string[]
  */
 protected function getRequestHeaders(RequestInterface $request)
 {
     $headers = array();
     foreach (array_keys($request->getHeaders()) as $name) {
         $headers[] = $name . ': ' . $request->getHeaderLine($name);
     }
     return $headers;
 }
开发者ID:ringcentral,项目名称:ringcentral-php,代码行数:12,代码来源:Client.php

示例6: isAcceptable

 /**
  * Is the strategy acceptable for this request?
  *
  * @param \Psr\Http\Message\RequestInterface $request The request
  *
  * @return bool Returns true on success, false otherwise
  */
 public function isAcceptable(RequestInterface $request)
 {
     $accept = $request->getHeaderLine('Accept');
     if ($accept && preg_match('#^application/([^+\\s]+\\+)?json#', $accept)) {
         return true;
     }
     return false;
 }
开发者ID:easy-system,项目名称:es-error,代码行数:15,代码来源:JsonErrorStrategy.php

示例7: __invoke

 /**
  * Execute the middleware.
  *
  * @param RequestInterface  $request
  * @param ResponseInterface $response
  * @param callable          $next
  *
  * @return ResponseInterface
  */
 public function __invoke(RequestInterface $request, ResponseInterface $response, callable $next)
 {
     $authorization = self::parseAuthorizationHeader($request->getHeaderLine('Authorization'));
     if ($authorization && $this->checkUserPassword($authorization['username'], $authorization['password'])) {
         return $next($request, $response);
     }
     return $response->withStatus(401)->withHeader('WWW-Authenticate', 'Basic realm="' . $this->realm . '"');
 }
开发者ID:snapshotpl,项目名称:psr7-middlewares,代码行数:17,代码来源:BasicAuthentication.php

示例8: render

 public function render(RequestInterface $request, ResponseInterface $response, $data)
 {
     $mediaType = $this->determineMediaType($request->getHeaderLine('Accept'));
     $output = $this->renderOutput($mediaType, $data);
     $response = $this->writeBody($response, $output);
     $response = $response->withHeader('Content-type', $mediaType);
     return $response;
 }
开发者ID:stefanotorresi,项目名称:rka-content-type-renderer,代码行数:8,代码来源:Renderer.php

示例9: detect

 public function detect()
 {
     if ($this->detected === null) {
         $headers = $this->request->getHeaders();
         $userAgent = $this->request->getHeaderLine('user-agent');
         if ($this->detector->isMobile($headers, $userAgent)) {
             $this->detected = 'mobile';
         } else {
             if ($this->detector->isTablet($headers, $userAgent)) {
                 $this->detected = 'tablet';
             } else {
                 $this->detected = 'desktop';
             }
         }
     }
     return $this->detected;
 }
开发者ID:maboiteaspam,项目名称:im-device-detect,代码行数:17,代码来源:MobileDetect.php

示例10: normalizeCustomHeaders

 /**
  * Normalizes the custom headers for signing.
  *
  * @return string[]
  *   An array of normalized headers.
  */
 protected function normalizeCustomHeaders()
 {
     $headers = [];
     // The spec requires that headers are sorted by header name.
     sort($this->headers);
     foreach ($this->headers as $header) {
         if ($this->request->hasHeader($header)) {
             $headers[] = strtolower($header) . ':' . $this->request->getHeaderLine($header);
         }
     }
     return $headers;
 }
开发者ID:acquia,项目名称:http-hmac-php,代码行数:18,代码来源:AuthorizationHeaderBuilder.php

示例11: forgeServerGlobal

 /**
  * Take a request and update the $_SERVER global to match
  *
  * @param RequestInterface $request
  */
 private function forgeServerGlobal(RequestInterface $request)
 {
     $_SERVER['REQUEST_URI'] = $request->getUri()->getPath();
     $_SERVER['REQUEST_METHOD'] = $request->getMethod();
     $_SERVER['QUERY_STRING'] = $request->getUri()->getQuery();
     if ($request->hasHeader('Content-Type')) {
         $_SERVER['CONTENT_TYPE'] = $request->getHeaderLine('Content-Type');
     }
     if ($request->hasHeader('Referer')) {
         $_SERVER['HTTP_REFERER'] = $request->getHeaderLine('Referer');
     }
     if ($request->hasHeader('X-Requested-with')) {
         $_SERVER['HTTP_X_REQUESTED_WITH'] = $request->getHeaderLine('X-Requested-With');
     }
     if ($request->hasHeader('User-Agent')) {
         $_SERVER['HTTP_USER_AGENT'] = $request->getHeaderLine('User-Agent');
     }
     if ($request->hasHeader('X-Forwarded-For')) {
         $_SERVER['HTTP_X_FORWARDED_FOR'] = $request->getHeaderLine('X-Forwarded-For');
     }
     return $this;
 }
开发者ID:liamja,项目名称:bunsen,代码行数:27,代码来源:TestCase.php

示例12: render

 public function render(RequestInterface $request, ResponseInterface $response, $data)
 {
     $mediaType = $this->determineMediaType($request->getHeaderLine('Accept'));
     $mediaSubType = explode('/', $mediaType)[1];
     $dataIsValidForMediatype = $this->isDataValidForMediaType($mediaSubType, $data);
     if (!$dataIsValidForMediatype) {
         throw new RuntimeException('Data for mediaType ' . $mediaType . ' must be ' . implode($this->mediaSubtypesToAllowedDataTypesMap[$mediaSubType], ' or '));
     }
     $output = $this->renderOutput($mediaType, $data);
     $response = $this->writeBody($response, $output);
     $response = $response->withHeader('Content-type', $mediaType);
     return $response;
 }
开发者ID:akrabat,项目名称:rka-content-type-renderer,代码行数:13,代码来源:Renderer.php

示例13: login

 /**
  * Login or check the user credentials.
  *
  * @param RequestInterface $request
  *
  * @return bool
  */
 private function login(RequestInterface $request)
 {
     //Check header
     $authorization = self::parseAuthorizationHeader($request->getHeaderLine('Authorization'));
     if (!$authorization) {
         return false;
     }
     //Check whether user exists
     if (!isset($this->users[$authorization['username']])) {
         return false;
     }
     //Check authentication
     return $this->checkAuthentication($authorization, $request->getMethod(), $this->users[$authorization['username']]);
 }
开发者ID:snapshotpl,项目名称:psr7-middlewares,代码行数:21,代码来源:DigestAuthentication.php

示例14: render

 public function render(RequestInterface $request, ResponseInterface $response, $data)
 {
     $contentType = $this->determineMediaType($request->getHeaderLine('Accept'));
     $output = $this->renderOutput($contentType, $data);
     $response = $this->writeBody($response, $output);
     // set the HAL content type for JSON or XML
     if (stripos($contentType, 'json')) {
         $contentType = 'application/hal+json';
     } elseif (stripos($contentType, 'xml')) {
         $contentType = 'application/hal+xml';
     }
     $response = $response->withHeader('Content-type', $contentType);
     return $response;
 }
开发者ID:akrabat,项目名称:rka-content-type-renderer,代码行数:14,代码来源:HalRenderer.php

示例15: assertValidBody

 /**
  * @param RequestInterface $request
  */
 private function assertValidBody(RequestInterface $request)
 {
     $body = $request->getBody()->getContents();
     $method = $request->getMethod();
     $path = $request->getUri()->getPath();
     $contentType = $request->getHeaderLine('Content-Type');
     $schemaBody = $this->schemaHelper->getRequestBody($method, $path, $contentType);
     try {
         $schemaBody->getSchema()->validate($body);
     } catch (InvalidSchemaException $exception) {
         $message = sprintf('Request body for %s %s with content type %s does not match schema: %s', strtoupper($method), $path, $contentType, $this->getSchemaErrorsAsString($exception->getErrors()));
         throw new ValidatorRequestException($message, 0, $exception);
     }
 }
开发者ID:alecsammon,项目名称:php-raml-parser,代码行数:17,代码来源:RequestValidator.php


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