当前位置: 首页>>代码示例>>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;未经允许,请勿转载。