for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace nebula\application\response\provider;
/**
* 响应头提供器
*/
class Header
{
* 静态实例
*
* @var self
protected static $instance;
protected function __construct()
}
* 返回实例
* @return self
public static function instance()
if (isset(static::$instance)) {
return static::$instance;
return static::$instance = new static;
* 头部信息
* @var array
protected $header = [];
* 添加头部值
* @param string $name
* @param string $content
* @return void
public function addHeader(string $name, string $content)
$this->addHeaderRaw(trim($name).': '.trim($content));
* 添加头部
public function addHeaderRaw(string $content)
$this->header[] = trim($content);
* 直接发送头部信息
* @param boolean $replace
* @return boolean
public function sendHeader(string $name, string $content, bool $replace = true)
return $this->sendHeaderRaw(trim($name).': '.trim($content), $replace);
* 发送原始头部
* @return bool
public function sendHeaderRaw(string $content, bool $replace = true)
if (!$this->sended()) {
header($content, $replace);
return true;
return false;
* 发送头部信息
public function send():bool
if ($this->sended()) {
foreach ($this->header as $value) {
$this->sendHeaderRaw($value);
public function sended():bool {
return headers_sent();