本文整理汇总了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));
}
}
}
}
示例2: getProtocolVersion
/**
* {@inheritdoc}
*/
public function getProtocolVersion()
{
return $this->wrapped->getProtocolVersion();
}
示例3: getProtocolVersion
/**
* {@inheritDoc}
*/
public function getProtocolVersion()
{
return $this->psrRequest->getProtocolVersion();
}
示例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;
}