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


PHP ServerRequestInterface::getProtocolVersion方法代码示例

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


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

示例1: __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

示例2: getProtocolVersion

 /**
  * {@inheritdoc}
  */
 public function getProtocolVersion()
 {
     return $this->wrapped->getProtocolVersion();
 }
开发者ID:Mosaic,项目名称:Mosaic,代码行数:7,代码来源:Request.php

示例3: getProtocolVersion

 /**
  * {@inheritDoc}
  */
 public function getProtocolVersion()
 {
     return $this->psrRequest->getProtocolVersion();
 }
开发者ID:tonis-io,项目名称:tonis,代码行数:7,代码来源:Request.php

示例4: prepare

 /**
  * https://github.com/symfony/http-foundation/blob/master/Response.php#L250
  * @param  PsrServerRequest $request [description]
  * @return self
  */
 public function prepare(PsrServerRequest $request)
 {
     $response = clone $this;
     if ($response->status->isInformational() || in_array($response->getStatusCode(), [204, 304])) {
         $response = $respone->withBody(new Stream('php://temp'))->withoutHeader('Content-Type')->withoutHeader('Content-Length');
     } else {
         // set content type based on request, if we haven't provided one
         if (!$response->hasHeader('Content-Type')) {
         }
         // fix content type
         $charset = $response->charset ?: 'UTF-8';
         if (!$response->hasHeader('Content-Type')) {
             $response = $response->withHeader('Content-Type', sprintf('text/html; charset=%s', $charset));
         } elseif (stripos($response->getHeaderLine('Content-Type'), 'text/') === 0 && stripos($response->getHeaderLine('Content-Type'), 'charset') === false) {
             $value = sprintf('%s; charset=%s', $response->getHeaderLine('Content-Type'), $charset);
             $response = $response->withHeader('Content-Type', $value);
         }
         // fix content length
         if ($response->hasHeader('Transfer-Encoding')) {
             $response = $response->withoutHeader('Content-Length');
         }
         if (!$response->hasHeader('Content-Length')) {
             $response->withHeader('Content-Length', (string) $this->getBody()->getSize());
         }
         // fix HEAD requests
         if ($request->getMethod() === 'HEAD') {
             // make sure content length is specified
             if (!$response->hasHeader('Content-Length')) {
                 $response = $response->withHeader('Content-Length', $response->getBody()->getSize());
             }
             // body should be empty
             $response = $respone->withBody(new Stream('php://temp'));
         }
     }
     // fix protocol
     if ($request->getProtocolVersion() !== '1.0') {
         $response = $response->withProtocolVersion('1.1');
     }
     // check if we need to send extra expire info headers
     if ($response->getProtocolVersion() === '1.0' && in_array('no-cache', $response->getHeader('Cache-Control'))) {
         $response = $response->withAddedHeader('Pragma', 'no-cache')->withAddedHeader('Expires', -1);
     }
     return $response;
 }
开发者ID:nbish11,项目名称:meek-http,代码行数:49,代码来源:Response.php


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