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


PHP RequestInterface::getHeader方法代码示例

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


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

示例1: getRequestId

 /**
  * @return string
  */
 public function getRequestId()
 {
     if ($this->request->hasHeader($this->headerName)) {
         return $this->request->getHeader($this->headerName);
     }
     return $this->fallback->getRequestId();
 }
开发者ID:arkitekto,项目名称:request-id,代码行数:10,代码来源:ExtractsRequestIdFromHeader.php

示例2: getHeader

 /**
  * {@inheritdoc}
  */
 public function getHeader($header)
 {
     if (!$this->request->hasHeader($header)) {
         if (strtolower($header) === 'host' && ($this->request->getUri() && $this->request->getUri()->getHost())) {
             return array($this->getHostFromUri());
         }
         return array();
     }
     return $this->request->getHeader($header);
 }
开发者ID:deepfreeze,项目名称:zend-diactoros,代码行数:13,代码来源:Request.php

示例3: verifyAll

 /**
  * Given an array of the headers this method will run through all verification methods
  * @param RequestInterface $request
  * @return bool TRUE if all headers are valid, FALSE if 1 or more were invalid
  */
 public function verifyAll(RequestInterface $request)
 {
     $passes = 0;
     $passes += (int) $this->verifyMethod($request->getMethod());
     $passes += (int) $this->verifyHTTPVersion($request->getProtocolVersion());
     $passes += (int) $this->verifyRequestURI($request->getUri()->getPath());
     $passes += (int) $this->verifyHost($request->getHeader('Host'));
     $passes += (int) $this->verifyUpgradeRequest($request->getHeader('Upgrade'));
     $passes += (int) $this->verifyConnection($request->getHeader('Connection'));
     $passes += (int) $this->verifyKey($request->getHeader('Sec-WebSocket-Key'));
     $passes += (int) $this->verifyVersion($request->getHeader('Sec-WebSocket-Version'));
     return 8 === $passes;
 }
开发者ID:RxPHP,项目名称:RxWebsocket,代码行数:18,代码来源:RequestVerifier.php

示例4: __invoke

 /**
  * Invoke middleware
  *
  * @param  RequestInterface $request PSR7 request object
  * @param  ResponseInterface $response PSR7 response object
  * @param  callable $next Next middleware callable
  *
  * @return ResponseInterface PSR7 response object
  */
 public function __invoke(RequestInterface $request, ResponseInterface $response, callable $next)
 {
     $uri = $request->getUri();
     if (false !== strpos($uri->getPath(), $this->route)) {
         $authUser = $request->getHeader('PHP_AUTH_USER') ? $request->getHeader('PHP_AUTH_USER')[0] : null;
         $authPass = $request->getHeader('PHP_AUTH_PW') ? $request->getHeader('PHP_AUTH_PW')[0] : null;
         if ($authUser && $authPass && $authUser === $this->username && $authPass === $this->password) {
             return $next($request, $response);
         } else {
             return $response->withStatus(401)->withHeader('WWW-Authenticate', sprintf('Basic realm="%s"', $this->realm));
         }
     }
     return $next($request, $response);
 }
开发者ID:julionc,项目名称:slim-basic-auth-middleware,代码行数:23,代码来源:Rule.php

示例5: requestContentTypeIsJson

 /**
  * @param RequestInterface $request
  * @return bool
  */
 protected function requestContentTypeIsJson(RequestInterface $request)
 {
     $contentTypes = $request->getHeader('Content-Type');
     if (empty($contentTypes)) {
         throw new InvalidArgumentException("Given request is missing Content-Type header");
     }
     $contentType = reset($contentTypes);
     return substr($contentType, 0, 16) === self::JSON_MIME;
 }
开发者ID:brzuchal,项目名称:webhook-integrations,代码行数:13,代码来源:ProviderBase.php

示例6: prepareHttpCUrl

 /**
  * Assigns options specific to handling HTTP requests.
  * NOTE: THIS METHOD SHOULD BE CALLED ONLY FROM prepareCUrl()!
  *
  * @throws UnsupportedFeatureException Thrown if POST method was requested.
  */
 private function prepareHttpCUrl()
 {
     if ($this->fetchRequest->getMethod() !== 'GET') {
         throw new UnsupportedFeatureException('Request other than GET are not supported');
     }
     $headers = [];
     foreach ($this->fetchRequest->getHeaders() as $name => $values) {
         $headers[] = $name . ": " . implode(", ", $values);
     }
     curl_setopt_array($this->cUrl, [CURLOPT_AUTOREFERER => 1, CURLOPT_FOLLOWLOCATION => 1, CURLOPT_FAILONERROR => 1, CURLOPT_HTTP_VERSION => $this->fetchRequest->getProtocolVersion() === '1.0' ? CURL_HTTP_VERSION_1_0 : CURL_HTTP_VERSION_1_1, CURLOPT_USERAGENT => $this->fetchRequest->getHeader('User-Agent') ?: $this->getDefaultUserAgent(), CURLOPT_HTTPHEADER => $headers]);
 }
开发者ID:kiler129,项目名称:TorrentGhost,代码行数:17,代码来源:FetchJob.php

示例7: __invoke

 public function __invoke(RequestInterface $request) : Data
 {
     $tokens = array_filter(array_map([$this, 'parseToken'], $request->getHeader('Cookie')), function (Token $token) use($request) {
         return $this->tokenValidator->__invoke($token, $request);
     });
     /* @var $token Token|bool */
     $token = reset($tokens);
     $session = $token ? $this->tokenSerializer->deSerialize($token) : Data::newEmptySession();
     if (!$this->sessionValidator->__invoke($session, $request)) {
         // if all validation fails, simply reset the session (scrap it)
         return Data::newEmptySession();
     }
     return $session;
 }
开发者ID:stof,项目名称:StorageLessSession,代码行数:14,代码来源:RequestSessionFactory.php

示例8: processResponse

 /**
  * @param RequestInterface                   $request
  * @param array                              $options
  * @param ResponseInterface|PromiseInterface $response
  *
  * @return ResponseInterface|PromiseInterface
  */
 public function processResponse(RequestInterface $request, array $options, ResponseInterface $response)
 {
     $response = $response->withHeader('X-Blackfire-Profile-Uuid', $request->getHeader('X-Blackfire-Profile-Uuid'));
     if (!$response->hasHeader('X-Blackfire-Response')) {
         return $response;
     }
     parse_str($response->getHeader('X-Blackfire-Response')[0], $values);
     if (!isset($values['continue']) || 'true' !== $values['continue']) {
         return $response;
     }
     Psr7\rewind_body($request);
     /* @var PromiseInterface|ResponseInterface $promise */
     return $this($request, $options);
 }
开发者ID:stof,项目名称:php-sdk,代码行数:21,代码来源:Middleware.php

示例9: __invoke

 /**
  * @param RequestInterface $request
  * @param callable $next
  * @return mixed
  */
 public function __invoke(RequestInterface $request, callable $next)
 {
     $isXHR = in_array('XMLHttpRequest', $request->getHeader('X-Requested-With'), true);
     switch ($this->state) {
         case self::ONLY_XHR:
             if (!$isXHR) {
                 return null;
             }
             break;
         case self::ONLY_NO_XHR:
             if ($isXHR) {
                 return null;
             }
             break;
     }
     return $next($request);
 }
开发者ID:alexpts,项目名称:php-routing,代码行数:22,代码来源:CheckXHR.php

示例10: getPayloadFromRequest

 /**
  * Get request payload from request object.
  *
  * @todo check $request->getHeaderLine('content-type') ??
  *
  * @param RequestInterface $request
  * @return array
  *
  * @throws \Exception
  */
 private function getPayloadFromRequest(RequestInterface $request)
 {
     $contentType = $request->getHeader('Content-Type');
     $expected = 'application/json; charset=UTF-8';
     if (empty($contentType) || $expected != $contentType[0]) {
         throw new \Exception('Expected Content-Type: ' . $expected);
     }
     $payload = json_decode($request->getBody(), true);
     switch (json_last_error()) {
         case JSON_ERROR_DEPTH:
             throw new \Exception('Invalid JSON, maximum stack depth exceeded.', 400);
         case JSON_ERROR_UTF8:
             throw new \Exception('Malformed UTF-8 characters, possibly incorrectly encoded.', 400);
         case JSON_ERROR_SYNTAX:
         case JSON_ERROR_CTRL_CHAR:
         case JSON_ERROR_STATE_MISMATCH:
             throw new \Exception('Invalid JSON.', 400);
     }
     return is_null($payload) ? [] : $payload;
 }
开发者ID:Huertix,项目名称:proophessor-do,代码行数:30,代码来源:API.php

示例11: handshake

 /**
  * {@inheritdoc}
  */
 public function handshake(RequestInterface $request)
 {
     if (true !== $this->verifier->verifyMethod($request->getMethod())) {
         return new Response(405);
     }
     if (true !== $this->verifier->verifyHTTPVersion($request->getProtocolVersion())) {
         return new Response(505);
     }
     if (true !== $this->verifier->verifyRequestURI($request->getUri()->getPath())) {
         return new Response(400);
     }
     if (true !== $this->verifier->verifyHost($request->getHeader('Host'))) {
         return new Response(400);
     }
     if (true !== $this->verifier->verifyUpgradeRequest($request->getHeader('Upgrade'))) {
         return new Response(400, [], '1.1', null, 'Upgrade header MUST be provided');
     }
     if (true !== $this->verifier->verifyConnection($request->getHeader('Connection'))) {
         return new Response(400, [], '1.1', null, 'Connection header MUST be provided');
     }
     if (true !== $this->verifier->verifyKey($request->getHeader('Sec-WebSocket-Key'))) {
         return new Response(400, [], '1.1', null, 'Invalid Sec-WebSocket-Key');
     }
     if (true !== $this->verifier->verifyVersion($request->getHeader('Sec-WebSocket-Version'))) {
         return new Response(426, ['Sec-WebSocket-Version' => $this->getVersionNumber()]);
     }
     $headers = [];
     $subProtocols = $request->getHeader('Sec-WebSocket-Protocol');
     if (count($subProtocols) > 0 || count($this->_supportedSubProtocols) > 0 && $this->_strictSubProtocols) {
         $subProtocols = array_map('trim', explode(',', implode(',', $subProtocols)));
         $match = array_reduce($subProtocols, function ($accumulator, $protocol) {
             return $accumulator ?: (isset($this->_supportedSubProtocols[$protocol]) ? $protocol : null);
         }, null);
         if ($this->_strictSubProtocols && null === $match) {
             return new Response(400, [], '1.1', null, 'No Sec-WebSocket-Protocols requested supported');
         }
         if (null !== $match) {
             $headers['Sec-WebSocket-Protocol'] = $match;
         }
     }
     return new Response(101, array_merge($headers, ['Upgrade' => 'websocket', 'Connection' => 'Upgrade', 'Sec-WebSocket-Accept' => $this->sign((string) $request->getHeader('Sec-WebSocket-Key')[0]), 'X-Powered-By' => 'RxPHPWebsocket']));
 }
开发者ID:RxPHP,项目名称:RxWebsocket,代码行数:45,代码来源:Negotiator.php

示例12: adapt

 public function adapt(array $tokens = [], $status = 200, array $headers = [])
 {
     list($contentType, $body) = $this->encoder->encode($this->request->getHeader('Accept'), $tokens);
     return new Response($this->asStream($body), $status, $this->getHeadersForResponse($contentType, $headers));
 }
开发者ID:Radweb,项目名称:OAuthTokenEncoding,代码行数:5,代码来源:OAuthTokenPsrAdaptor.php

示例13: getRequestHostHeader

 /**
  * @param RequestInterface $request
  *
  * @return null|string
  */
 private function getRequestHostHeader(RequestInterface $request)
 {
     $hostHeaderValue = $request->getHeader(CorsRequestHeaders::HOST);
     $host = empty($hostHeaderValue) === true ? null : $hostHeaderValue[0];
     return $host;
 }
开发者ID:neomerx,项目名称:cors-psr7,代码行数:11,代码来源:Analyzer.php

示例14: fetchToken

 /**
  * Fetch the access token
  *
  * @return string|null Base64 encoded JSON Web Token or null if not found.
  */
 public function fetchToken(RequestInterface $request)
 {
     /* If using PHP in CGI mode and non standard environment */
     $server_params = $request->getServerParams();
     if (isset($server_params[$this->options["environment"]])) {
         $message = "Using token from environent";
         $header = $server_params[$this->options["environment"]];
     } else {
         $message = "Using token from request header";
         $header = $request->getHeader("Authorization");
         $header = isset($header[0]) ? $header[0] : "";
     }
     if (preg_match("/Bearer\\s+(.*)\$/i", $header, $matches)) {
         $this->log(LogLevel::DEBUG, $message);
         return $matches[1];
     }
     /* Bearer not found, try a cookie. */
     $cookie_params = $request->getCookieParams();
     if (isset($cookie_params[$this->options["cookie"]])) {
         $this->log(LogLevel::DEBUG, "Using token from cookie");
         $this->log(LogLevel::DEBUG, $cookie_params[$this->options["cookie"]]);
         return $cookie_params[$this->options["cookie"]];
     }
     /* If everything fails log and return false. */
     $this->message = "Token not found";
     $this->log(LogLevel::WARNING, $this->message);
     return false;
 }
开发者ID:djbakerman,项目名称:botjack,代码行数:33,代码来源:JwtAuthentication.php

示例15: remove

 /**
  * @param Request $request
  * @param Response $response
  * @param $args
  * @return Response
  * @throws \Doctrine\ORM\EntityNotFoundException
  */
 public function remove(Request $request, Response $response, $args)
 {
     foreach (explode(',', $request->getHeader('id')[0]) as $id) {
         $ticket = $this->em->find('App\\Entity\\Ticket', $id);
         if ($ticket) {
             $this->em->remove($ticket);
         } else {
             throw new EntityNotFoundException();
         }
     }
     $this->em->flush();
     return $response;
 }
开发者ID:Chamchungue,项目名称:ToDoList,代码行数:20,代码来源:TicketAction.php


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