當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。