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


PHP ServerRequestInterface::getHeaders方法代碼示例

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


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

示例1: getData

 /**
  * {@inheritdoc}
  */
 public function getData()
 {
     $headers = [];
     foreach ($this->request->getHeaders() as $name => $values) {
         $headers[$name] = implode(', ', $values);
     }
     $data = ['SERVER' => $this->request->getServerParams(), 'QUERY' => $this->request->getQueryParams(), 'COOKIES' => $this->request->getCookieParams(), 'HEADERS' => $headers, 'ATTRIBUTES' => $this->request->getAttributes()];
     return $data;
 }
開發者ID:weierophinney,項目名稱:prophiler-psr7-middleware,代碼行數:12,代碼來源:Request.php

示例2: toZend

 /**
  * Convert a PSR-7 ServerRequest to a Zend\Http server-side request.
  *
  * @param ServerRequestInterface $psr7Request
  * @param bool $shallow Whether or not to convert without body/file
  *     parameters; defaults to false, meaning a fully populated request
  *     is returned.
  * @return Zend\Request
  */
 public static function toZend(ServerRequestInterface $psr7Request, $shallow = false)
 {
     if ($shallow) {
         return new Zend\Request($psr7Request->getMethod(), $psr7Request->getUri(), $psr7Request->getHeaders(), $psr7Request->getCookieParams(), $psr7Request->getQueryParams(), [], [], $psr7Request->getServerParams());
     }
     $zendRequest = new Zend\Request($psr7Request->getMethod(), $psr7Request->getUri(), $psr7Request->getHeaders(), $psr7Request->getCookieParams(), $psr7Request->getQueryParams(), $psr7Request->getParsedBody() ?: [], self::convertUploadedFiles($psr7Request->getUploadedFiles()), $psr7Request->getServerParams());
     $zendRequest->setContent($psr7Request->getBody());
     return $zendRequest;
 }
開發者ID:MidnightDesign,項目名稱:zend-psr7bridge,代碼行數:18,代碼來源:Psr7ServerRequest.php

示例3: getHeaders

 public function getHeaders()
 {
     if (!isset($this->headers)) {
         $this->headers = array();
         foreach ($this->request->getHeaders() as $header => $values) {
             $this->headers[strtolower($header)] = end($values);
         }
     }
     return $this->headers;
 }
開發者ID:vectorface,項目名稱:whip,代碼行數:10,代碼來源:Psr7RequestAdapter.php

示例4: createRequest

 /**
  * {@inheritdoc}
  */
 public function createRequest(ServerRequestInterface $psrRequest)
 {
     $parsedBody = $psrRequest->getParsedBody();
     $parsedBody = is_array($parsedBody) ? $parsedBody : array();
     $request = new Request($psrRequest->getQueryParams(), $parsedBody, $psrRequest->getAttributes(), $psrRequest->getCookieParams(), $this->getFiles($psrRequest->getUploadedFiles()), $psrRequest->getServerParams(), $psrRequest->getBody()->__toString());
     $request->headers->replace($psrRequest->getHeaders());
     return $request;
 }
開發者ID:papillon-cendre,項目名稱:d8,代碼行數:11,代碼來源:HttpFoundationFactory.php

示例5: convertRequestFromPsr7

 /**
  * Converts a PSR-7 request into an OAuth2 request.
  *
  * @param ServerRequestInterface $psrRequest
  * @return Request
  */
 public static function convertRequestFromPsr7(ServerRequestInterface $psrRequest)
 {
     $headers = [];
     foreach ($psrRequest->getHeaders() as $header => $value) {
         $headers[$header] = implode(';', $value);
     }
     return new Request($psrRequest->getQueryParams(), is_array($psrRequest->getParsedBody()) ? $psrRequest->getParsedBody() : [], $psrRequest->getAttributes(), $psrRequest->getCookieParams(), self::getFiles($psrRequest->getUploadedFiles()), $psrRequest->getServerParams(), $psrRequest->getBody()->__toString(), $headers);
 }
開發者ID:tonis-io,項目名稱:oauth2,代碼行數:14,代碼來源:Util.php

示例6: headers

 /**
  * Headers
  * @return \PHPixie\HTTP\Data\Headers
  */
 public function headers()
 {
     if ($this->headers === null) {
         $data = $this->serverRequest->getHeaders();
         $this->headers = $this->builder->headers($data);
     }
     return $this->headers;
 }
開發者ID:phpixie,項目名稱:http,代碼行數:12,代碼來源:Request.php

示例7: createRequest

 public static function createRequest(PsrServerRequestInterface $psrRequest)
 {
     $request = new Request(new Uri($psrRequest->getUri()), $psrRequest->getMethod(), $psrRequest->getHeaders(), $psrRequest->getBody());
     $attributes = $psrRequest->getAttributes();
     foreach ($attributes as $name => $value) {
         $request->setAttribute($name, $value);
     }
     return $request;
 }
開發者ID:seytar,項目名稱:psx,代碼行數:9,代碼來源:NativeFactory.php

示例8: __invoke

 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
 {
     $tokenHeader = $request->getHeader('X-Auth-Token');
     if (count($tokenHeader) > 0) {
         $tokenHeaderValue = $tokenHeader[0];
     } else {
         $tokenHeaderValue = null;
     }
     $data = array('requestMethod' => $request->getMethod(), 'requestUri' => $request->getRequestTarget(), 'queryParams' => $request->getQueryParams(), 'formParams' => $request->getParsedBody(), 'rawBody' => (string) $request->getBody(), 'headers' => $request->getHeaders(), 'X-Auth-Token' => $tokenHeaderValue);
     return new JsonResponse($data);
 }
開發者ID:Naktibalda,項目名稱:codeception-zend-expressive-tests,代碼行數:11,代碼來源:RestAction.php

示例9: prettifyRequest

 /**
  * @param \Psr\Http\Message\ServerRequestInterface $request
  * @return string
  */
 protected function prettifyRequest(ServerRequestInterface $request)
 {
     $contents = "{$request->getMethod()} : {$request->getUri()->__toString()}\n";
     $contents .= "HEADERS\n";
     foreach ($request->getHeaders() as $name => $value) {
         $contents .= "    {$name} : {$request->getHeaderLine($name)}\n";
     }
     if ($body = $request->getBody()) {
         $contents .= "BODY\n";
         $contents .= "\"{$body->__toString()}\"\n";
     }
     return $contents;
 }
開發者ID:wandu,項目名稱:framework,代碼行數:17,代碼來源:DefaultHttpErrorHandler.php

示例10: __construct

 /**
  * Construct action request.
  *
  * @param \Psr\Http\Message\ServerRequestInterface $request Request to wrap.
  */
 public function __construct(\Psr\Http\Message\ServerRequestInterface $request)
 {
     parent::__construct($request->getBody());
     foreach ($request->getHeaders() as $name => $value) {
         $this->setHeader($name, $value);
     }
     $this->protocolVersion = $request->getProtocolVersion();
     $this->method = $request->getMethod();
     $this->requestTarget = $request->getRequestTarget();
     $this->uri = $request->getUri();
     $this->attributes = $request->getAttributes();
     $this->cookies = $request->getCookieParams();
     $this->data = $request->getParsedBody();
     $this->query = $request->getQueryParams();
     $this->server = $request->getServerParams();
     $this->files = $request->getUploadedFiles();
     if (isset($this->server['SCRIPT_NAME'])) {
         $this->attributes['basePath'] = dirname($this->server['SCRIPT_NAME']);
         $this->attributes['scriptName'] = basename($this->server['SCRIPT_NAME']);
     } else {
         $this->attributes['basePath'] = '/';
         $this->attributes['scriptName'] = 'index.php';
     }
     if (!isset($this->attributes['path'])) {
         $this->attributes['path'] = self::findPath($this);
     }
     if (!isset($this->attributes['rewrite'])) {
         $this->attributes['rewrite'] = false;
     }
     if (!isset($this->attributes['accepts'])) {
         $this->attributes['accepts'] = [];
         if (isset($this->server['HTTP_ACCEPT'])) {
             $contentTypes = explode(',', $this->server['HTTP_ACCEPT']);
             foreach ($contentTypes as $contentType) {
                 $contentType = explode(';', $contentType);
                 $this->attributes['accepts'][] = trim(strtolower($contentType[0]));
             }
         }
     }
     if (!isset($this->attributes['encodings'])) {
         $this->attributes['encodings'] = [];
         if (isset($this->server['HTTP_ACCEPT_ENCODING'])) {
             $acceptEncodings = explode(',', $this->server['HTTP_ACCEPT_ENCODING']);
             foreach ($acceptEncodings as $encoding) {
                 $this->attributes['encodings'][] = trim(strtolower($encoding));
             }
         }
     }
 }
開發者ID:jivoo,項目名稱:http,代碼行數:54,代碼來源:ActionRequest.php

示例11: send

 /**
  * @param  ServerRequestInterface $request
  */
 public function send(ServerRequestInterface $request)
 {
     $this->currentUri = $request->getUri();
     $this->setBase($this->currentUri);
     if (empty($this->currentUri->getHost())) {
         $this->currentUri = new Uri($this->getBase() . $this->currentUri);
     }
     $curl = curl_init();
     $options = [CURLOPT_URL => (string) $this->currentUri, CURLOPT_FOLLOWLOCATION => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_CUSTOMREQUEST => $request->getMethod(), CURLOPT_USERAGENT => Loader::USER_AGENT, CURLOPT_HEADER => true, CURLOPT_HTTPHEADER => $this->getConvertedHeaders($request->getHeaders())];
     if ($request->getBody()->getSize()) {
         $options[CURLOPT_POSTFIELDS] = (string) $request->getBody();
     }
     curl_setopt_array($curl, $options);
     $response = curl_exec($curl);
     $this->currentUri = new Uri(curl_getinfo($curl, CURLINFO_EFFECTIVE_URL));
     return \GuzzleHttp\Psr7\parse_response($response);
 }
開發者ID:spiderling-php,項目名稱:curl-driver,代碼行數:20,代碼來源:Loader.php

示例12: createRequest

 /**
  * {@inheritdoc}
  */
 public function createRequest(ServerRequestInterface $psrRequest)
 {
     $server = array();
     $uri = $psrRequest->getUri();
     if ($uri instanceof UriInterface) {
         $server['SERVER_NAME'] = $uri->getHost();
         $server['SERVER_PORT'] = $uri->getPort();
         $server['REQUEST_URI'] = $uri->getPath();
         $server['QUERY_STRING'] = $uri->getQuery();
     }
     $server['REQUEST_METHOD'] = $psrRequest->getMethod();
     $server = array_replace($server, $psrRequest->getServerParams());
     $parsedBody = $psrRequest->getParsedBody();
     $parsedBody = is_array($parsedBody) ? $parsedBody : array();
     $request = new Request($psrRequest->getQueryParams(), $parsedBody, $psrRequest->getAttributes(), $psrRequest->getCookieParams(), $this->getFiles($psrRequest->getUploadedFiles()), $server, $psrRequest->getBody()->__toString());
     $request->headers->replace($psrRequest->getHeaders());
     return $request;
 }
開發者ID:symfony,項目名稱:psr-http-message-bridge,代碼行數:21,代碼來源:HttpFoundationFactory.php

示例13: responseRaidsAdd

 public function responseRaidsAdd(Request $request, Response $response)
 {
     $aRequest = $request->getParsedBody();
     $aHeader = $request->getHeaders();
     // @todo: validation of input params
     $sUserName = $aHeader['HTTP_X_AUTH_USER'];
     $sToken = $aHeader['HTTP_X_AUTH_TOKEN'];
     if (!$this->oUser->checkUserToken($sToken)) {
         return $response->withStatus(401);
     }
     /**
      * @var Raid
      */
     $oRaid = new Raid();
     $bSuccess = $oRaid->generateUuid()->setTitle($aRequest['title'])->setStart($aRequest['raidDate'], $aRequest['startTime'])->setEnd($aRequest['raidDate'], $aRequest['endTime'])->setMaxAttendees($aRequest['maxAttendees'])->save();
     $aResponse = [self::RESPONSE_SUCCESS => $bSuccess, 'uuid' => $oRaid->getUuid()];
     $response->getBody()->write(json_encode($aResponse));
     return $response;
 }
開發者ID:mroswald,項目名稱:invme,代碼行數:19,代碼來源:Raids.php

示例14: render

 /**
  * Render an exception into an HTTP or JSON response.
  *
  * @param Request $request
  * @param Response $response
  * @param \Exception $exception
  * @return mixed
  */
 public function render(Request $request, Response $response, \Exception $exception)
 {
     $statusCode = method_exists($exception, 'getStatusCode') ? $exception->getStatusCode() : 400;
     $response->withStatus($statusCode);
     $debug = $this->settings['displayErrorDetails'] == 'true' ? true : false;
     $title = $debug ? 'The application could not run because of the following error:' : 'A website error has occurred. Sorry for the temporary inconvenience.';
     $header = $request->getHeaders();
     $message = $exception->getMessage();
     $json = isset($header['HTTP_CONTENT_TYPE'][0]) && $header['HTTP_CONTENT_TYPE'][0] == 'application/json';
     // Check content-type is application/json
     if ($json) {
         // Define content-type to json
         $response->withHeader('Content-Type', 'application/json');
         $error = ['status' => 'error', 'error' => $title, 'statusCode' => $statusCode];
         // Check debug
         if ($debug) {
             $error['details'] = ['message' => $message, 'file' => $exception->getFile(), 'line' => $exception->getLine(), 'code' => $exception->getCode()];
         }
         $view = $this->json->render($response, $error, $statusCode);
     } else {
         // Define content-type to html
         $response->withHeader('Content-Type', 'text/html');
         $message = sprintf('<span>%s</span>', htmlentities($message));
         $error = ['type' => get_class($exception), 'message' => $message];
         // Check debug
         if ($debug) {
             $trace = $exception->getTraceAsString();
             $trace = sprintf('<pre>%s</pre>', htmlentities($trace));
             $error['file'] = $exception->getFile();
             $error['line'] = $exception->getLine();
             $error['code'] = $exception->getCode();
             $error['trace'] = $trace;
         }
         $error['debug'] = $debug;
         $error['title'] = $title;
         $view = $this->view->render($response, 'error/error.twig', $error);
     }
     // Send error to log
     $this->log->addError($exception->getMessage());
     return $view;
 }
開發者ID:arcostasi,項目名稱:slimantic-skeleton,代碼行數:49,代碼來源:Handler.php

示例15: getHeaders

 /**
  * {@inheritdoc}
  */
 public function getHeaders()
 {
     return $this->wrapped->getHeaders();
 }
開發者ID:Mosaic,項目名稱:Mosaic,代碼行數:7,代碼來源:Request.php


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