for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace nebula\request\attribute;
/**
* HTTP请求协议属性
*
*/
trait SchemeAttribute
{
protected $host;
protected $port;
protected $scheme;
public function getScheme()
$server = $this->getServer();
if (!isset($this->scheme)) {
if (array_key_exists('HTTPS', $server) && strcasecmp($server['HTTPS'], 'off') != 0) {
$scheme = 'https';
} elseif (array_key_exists('REQUEST_SCHEME', $server)) {
$scheme = $server['REQUEST_SCHEME'];
} else {
$scheme = 'http';
}
return $this->scheme = $scheme;
$scheme
public function getHost()
if (isset($this->host)) {
return $this->host;
return $this->host = $this->getServer()['HTTP_HOST'] ?? 'localhost';
public function getPort()
if (isset($this->port)) {
return $this->port;
return $this->port = $this->getServer()['SERVER_PORT'] ?? 80;
* 获取服务器基础URI
* @return string
public function getServerURI()
return $this->getScheme().'://'.$this->getHost();
* Get 服务器属性
* @return array
abstract public function getServer();