|
@@ -11,12 +11,14 @@
|
|
|
}
|
|
|
public function clear(){
|
|
|
if($this->open){
|
|
|
+ $this->fire('clear');
|
|
|
$this->body = '';
|
|
|
}
|
|
|
return $this;
|
|
|
}
|
|
|
public function clear_headers(){
|
|
|
if($this->open){
|
|
|
+ $this->fire('clear_headers');
|
|
|
$this->headers = [];
|
|
|
}
|
|
|
return $this;
|
|
@@ -24,12 +26,14 @@
|
|
|
public function clear_header(string $name){
|
|
|
foreach($this->headers as $key => $header){
|
|
|
if($header[0] == $name){
|
|
|
+ $this->fire('clear_header', $name);
|
|
|
array_splice($this->headers, $key, 1);
|
|
|
}
|
|
|
}
|
|
|
return $this;
|
|
|
}
|
|
|
public function write(string $chunk){
|
|
|
+ $this->fire('write', $chunk);
|
|
|
if($this->open){
|
|
|
$this->body .= $chunk;
|
|
|
}
|
|
@@ -43,6 +47,7 @@
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+ $this->fire('json', $json);
|
|
|
$this->write(json_encode($json));
|
|
|
if(json_last_error() != JSON_ERROR_NONE){
|
|
|
throw new Exception(json_last_error_msg());
|
|
@@ -51,6 +56,7 @@
|
|
|
}
|
|
|
public function header(string $name, string $value){
|
|
|
if($this->open){
|
|
|
+ $this->fire('header', $name, $value);
|
|
|
array_push(
|
|
|
$this->headers,
|
|
|
[
|
|
@@ -62,12 +68,14 @@
|
|
|
return $this;
|
|
|
}
|
|
|
public function redirect(string $url){
|
|
|
+ $this->fire('redirect', $url);
|
|
|
$this->header('Location',Router::url($url));
|
|
|
return $this;
|
|
|
}
|
|
|
public function end(string $chunk=''){
|
|
|
if($this->open){
|
|
|
$this->write($chunk);
|
|
|
+ $this->fire('end');
|
|
|
$this->open = false;
|
|
|
}
|
|
|
return $this;
|
|
@@ -76,6 +84,7 @@
|
|
|
if(!$type){
|
|
|
$type = $img->type;
|
|
|
}
|
|
|
+ $this->fire('image', $img, $type);
|
|
|
$this->clear_header('Content-Type')
|
|
|
->header('Content-Type', 'image/'.$type);
|
|
|
if(!is_a($img, 'Image')){
|
|
@@ -92,19 +101,23 @@
|
|
|
if(is_null($code)){
|
|
|
return $this->code;
|
|
|
}
|
|
|
+ $this->fire('code', $code);
|
|
|
$this->code = $code;
|
|
|
return $this;
|
|
|
}
|
|
|
public function shutdown(){
|
|
|
+ $this->fire('beforeshutdown');
|
|
|
if($this->open){
|
|
|
$this->end();
|
|
|
}
|
|
|
+ $this->fire('shutdown');
|
|
|
http_response_code($this->code);
|
|
|
foreach($this->headers as $k => $header){
|
|
|
header("{$header[0]}: $header[1]");
|
|
|
}
|
|
|
echo $this->body;
|
|
|
flush();
|
|
|
+ $this->fire('aftershutdown');
|
|
|
}
|
|
|
}
|
|
|
?>
|