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


PHP ServerRequestInterface::hasHeader方法代码示例

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


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

示例1: getRealUri

 public static function getRealUri(ServerRequestInterface $request)
 {
     $uri = $request->getUri();
     if ($request->hasHeader(self::PROTO_HEADER_HEROKU)) {
         $uri = $uri->withScheme($request->getHeader(self::PROTO_HEADER_HEROKU)[0]);
     }
     if ($request->hasHeader(self::PORT_HEADER_HEROKU)) {
         $uri = $uri->withPort(intval($request->getHeader(self::PORT_HEADER_HEROKU)[0]));
     }
     return $uri;
 }
开发者ID:corporateanon,项目名称:cisco-twitter,代码行数:11,代码来源:ProxiedHttpsSupport.php

示例2: back

/**
 * @param \Psr\Http\Message\ServerRequestInterface $request
 * @return \Psr\Http\Message\ResponseInterface
 * @throws \Wandu\Http\Exception\BadRequestException
 */
function back(ServerRequestInterface $request)
{
    if ($request->hasHeader('referer')) {
        return redirect($request->getHeader('referer'));
    }
    throw new BadRequestException();
}
开发者ID:Festiv,项目名称:Festiv,代码行数:12,代码来源:functions.php

示例3: __invoke

 public function __invoke(Request $request)
 {
     /** Check for token on header */
     if (isset($this->options['header'])) {
         if ($request->hasHeader($this->options['header'])) {
             $header = $request->getHeader($this->options['header'])[0];
             if (preg_match($this->options['regex'], $header, $matches)) {
                 return $matches[1];
             }
         }
     }
     /** If nothing on header, try query parameters */
     if (isset($this->options['parameter'])) {
         if (!empty($request->getQueryParams()[$this->options['parameter']])) {
             return $request->getQueryParams()[$this->options['parameter']];
         }
     }
     /** If nothing on parameters, try cookies */
     if (isset($this->options['cookie'])) {
         $cookie_params = $request->getCookieParams();
         if (!empty($cookie_params[$this->options["cookie"]])) {
             return $cookie_params[$this->options["cookie"]];
         }
     }
     /** If nothing until now, check argument as last try */
     if (isset($this->options['argument'])) {
         if ($route = $request->getAttribute('route')) {
             $argument = $route->getArgument($this->options['argument']);
             if (!empty($argument)) {
                 return $argument;
             }
         }
     }
     throw new TokenNotFoundException('Token not found');
 }
开发者ID:dyorg,项目名称:slim-token-authentication,代码行数:35,代码来源:TokenSearch.php

示例4: validateAuthorization

 /**
  * {@inheritdoc}
  */
 public function validateAuthorization(ServerRequestInterface $request)
 {
     if ($request->hasHeader('authorization') === false) {
         throw OAuthServerException::accessDenied('Missing "Authorization" header');
     }
     $header = $request->getHeader('authorization');
     $jwt = trim(preg_replace('/^(?:\\s+)?Bearer\\s/', '', $header[0]));
     try {
         // Attempt to parse and validate the JWT
         $token = (new Parser())->parse($jwt);
         if ($token->verify(new Sha256(), $this->publicKey->getKeyPath()) === false) {
             throw OAuthServerException::accessDenied('Access token could not be verified');
         }
         // Ensure access token hasn't expired
         $data = new ValidationData();
         $data->setCurrentTime(time());
         if ($token->validate($data) === false) {
             throw OAuthServerException::accessDenied('Access token is invalid');
         }
         // Check if token has been revoked
         if ($this->accessTokenRepository->isAccessTokenRevoked($token->getClaim('jti'))) {
             throw OAuthServerException::accessDenied('Access token has been revoked');
         }
         // Return the request with additional attributes
         return $request->withAttribute('oauth_access_token_id', $token->getClaim('jti'))->withAttribute('oauth_client_id', $token->getClaim('aud'))->withAttribute('oauth_user_id', $token->getClaim('sub'))->withAttribute('oauth_scopes', $token->getClaim('scopes'));
     } catch (\InvalidArgumentException $exception) {
         // JWT couldn't be parsed so return the request as is
         throw OAuthServerException::accessDenied($exception->getMessage());
     } catch (\RuntimeException $exception) {
         //JWR couldn't be parsed so return the request as is
         throw OAuthServerException::accessDenied('Error while decoding to JSON');
     }
 }
开发者ID:tylerian,项目名称:illuminate-oauth2-server,代码行数:36,代码来源:BearerTokenValidator.php

示例5: __invoke

 /**
  * Invoking the middleware
  *
  * @param ServerRequestInterface $request
  * @param ResponseInterface $response
  * @param callable $next
  * @return ResponseInterface $response
  * @throws InternalServerError
  * @throws UnsupportedMediaType
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
 {
     // Make sure we have deserializers
     if (!isset($this->container['contentTypes'])) {
         throw new InternalServerError('No serializers seems to be configured');
     }
     // Make sure we have a content type header to work with
     if ($request->hasHeader('Content-Type')) {
         // Get the content of the header
         $header = $request->getHeaderLine('Content-Type');
         // Make sure the header value isn't empty
         if (!empty($header)) {
             // Get priorities
             $supported = $this->container['contentTypes'];
             // Remove included parts that aren't part of the RFC
             $header = preg_replace('/(;[a-z]*=[a-z0-9\\-]*)/i', '', $header);
             // Replace the original header value
             $request = $request->withHeader('Content-Type', $header);
             // Check if the content type is supported
             if (!in_array($header, $supported)) {
                 // The content type isn't supported
                 throw new UnsupportedMediaType('Can not handle the supplied content type. Supported types are ' . implode(', ', $supported));
             }
         }
     }
     // Call next middleware
     return $next($request, $response, $next);
 }
开发者ID:phapi,项目名称:middleware-postbox,代码行数:38,代码来源:PostBox.php

示例6: __invoke

 /**
  * {@inheritdoc}
  */
 public function __invoke(Request $request, Response $response, callable $out = null)
 {
     if ($request->getMethod() === 'POST' && $request->hasHeader(self::HEADER_NAME)) {
         $fakeMethod = $request->getHeaderLine(self::HEADER_NAME);
         $request = $request->withMethod(strtoupper($fakeMethod));
     }
     return $out ? $out($request, $response) : $response;
 }
开发者ID:clops,项目名称:core,代码行数:11,代码来源:FakeHttpMethods.php

示例7: getSignatureFromRequest

 /**
  * @param \Psr\Http\Message\ServerRequestInterface $request
  *
  * @return string
  * @throws \livetyping\hermitage\app\exceptions\UnauthorizedException
  */
 protected function getSignatureFromRequest(Request $request) : string
 {
     if (!$request->hasHeader(self::HEADER_AUTHENTICATE_SIGNATURE)) {
         throw new UnauthorizedException('Signature is required.');
     }
     $signature = current($request->getHeader(self::HEADER_AUTHENTICATE_SIGNATURE));
     return $signature;
 }
开发者ID:livetyping,项目名称:hermitage,代码行数:14,代码来源:Authenticate.php

示例8: __invoke

 /**
  * Process an incoming request and/or response.
  *
  * Accepts a server-side request and a response instance, and does
  * something with them.
  *
  * If the response is not complete and/or further processing would not
  * interfere with the work done in the middleware, or if the middleware
  * wants to delegate to another process, it can use the `$out` callable
  * if present.
  *
  * If the middleware does not return a value, execution of the current
  * request is considered complete, and the response instance provided will
  * be considered the response to return.
  *
  * Alternately, the middleware may return a response instance.
  *
  * Often, middleware will `return $out();`, with the assumption that a
  * later middleware will return a response.
  *
  * @param Request $request
  * @param Response $response
  * @param null|callable $out
  * @return null|Response
  */
 public function __invoke(Request $request, Response $response, callable $out = null)
 {
     if (!$request->hasHeader('Accept-Language')) {
         return $out($request, $response);
     }
     $locale = $request->getHeaderLine('Accept-Language');
     $this->translator->setLocale($this->normalizeLocale($locale));
     return $out($request, $response);
 }
开发者ID:shlinkio,项目名称:shlink,代码行数:34,代码来源:LocaleMiddleware.php

示例9: enrichRequestWithParsedBody

 public function enrichRequestWithParsedBody(ServerRequestInterface $request)
 {
     if ($request->hasHeader(HeaderName::CONTENT_TYPE) && $request->getHeaderLine(HeaderName::CONTENT_TYPE) === 'application/json') {
         $parsedBody = $this->serializer->deserialize($request->getBody()->__toString(), 'array', 'json');
         return $request->withParsedBody($parsedBody);
     } else {
         return $request->withParsedBody([]);
     }
 }
开发者ID:jonasrudolph,项目名称:php-component-web-project,代码行数:9,代码来源:RequestBodyParser.php

示例10: __invoke

 public function __invoke(Request $request, Response $response, callable $out = null)
 {
     if (!$request->hasHeader('authorization')) {
         return $response->withStatus(401);
     }
     if (!$this->isValid($request)) {
     }
     return $out($request, $response);
 }
开发者ID:eminetto,项目名称:restbeer-expressive,代码行数:9,代码来源:Auth.php

示例11: __invoke

 public function __invoke(Request $request, Response $response, callable $next) : Response
 {
     $parent = $request->getOriginalRequest();
     $parentUrl = str_replace('/thank-you', '', (string) $parent->getUri());
     if (!$request->hasHeader('Referer') || !preg_match('#^' . $parentUrl . '#', $request->getHeaderLine('Referer'))) {
         return $response->withStatus(302)->withHeader('Location', $parentUrl);
     }
     return new HtmlResponse($this->template->render('contact::thankyou', []));
 }
开发者ID:vrkansagara,项目名称:mwop.net,代码行数:9,代码来源:ThankYouPage.php

示例12: getHeadersFromRequest

 /**
  * @param ServerRequestInterface $request
  *
  * @return array
  */
 private function getHeadersFromRequest(ServerRequestInterface $request)
 {
     $headerNames = [];
     foreach ($this->service->getOverrideHeaders() as $headerName) {
         if ($request->hasHeader($headerName)) {
             $headerNames[$headerName] = $request->getHeaderLine($headerName);
         }
     }
     return $headerNames;
 }
开发者ID:rstgroup,项目名称:http-method-override,代码行数:15,代码来源:HttpMethodOverrideMiddleware.php

示例13: fetchToken

 /**
  * Fetch token from request.
  *
  * @param ServerRequestInterface $request
  * @return string
  */
 protected function fetchToken(ServerRequestInterface $request)
 {
     if ($request->hasHeader(self::HEADER)) {
         return (string) $request->getHeaderLine(self::HEADER);
     }
     $data = $request->getParsedBody();
     if (is_array($data) && isset($data[self::PARAMETER])) {
         if (is_string($data[self::PARAMETER])) {
             return (string) $data[self::PARAMETER];
         }
     }
     return '';
 }
开发者ID:jwdeitch,项目名称:components,代码行数:19,代码来源:CsrfFilter.php

示例14: checkOrigin

 /**
  * Check if the provided origin is allowed to
  * access the api
  *
  * @return bool
  */
 protected function checkOrigin()
 {
     // Check if we allow all "*"
     if ($this->options['allowedOrigins'] === true) {
         return true;
     }
     // Make sure the origin header is set and that the value (domain) is
     // in the allowed origins list.
     if ($this->request->hasHeader('origin') && in_array($this->request->getHeaderLine('origin'), $this->options['allowedOrigins'])) {
         return true;
     }
     return false;
 }
开发者ID:phapi,项目名称:middleware-cors,代码行数:19,代码来源:Cors.php

示例15: isAcceptableServerRequest

 private function isAcceptableServerRequest(ServerRequestInterface $request) : bool
 {
     if (!$request->hasHeader("Accept-encoding")) {
         return false;
     }
     $accept = $request->getHeaderLine("Accept-encoding");
     if (strpos($accept, '*') !== false) {
         return true;
     }
     if (strpos($accept, 'gzip') !== false) {
         return true;
     }
     return false;
 }
开发者ID:ircmaxell,项目名称:tari-php,代码行数:14,代码来源:GZip.php


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