37 public function header( $string, $replace =
true, $http_response_code =
null ) {
38 if ( substr( $string, 0, 5 ) ==
'HTTP/' ) {
39 $parts = explode(
' ', $string, 3 );
40 $this->code = intval( $parts[1] );
42 list( $key, $val ) = array_map(
'trim', explode(
":", $string, 2 ) );
44 $key = strtoupper( $key );
46 if ( $replace || !isset( $this->headers[$key] ) ) {
47 $this->headers[$key] = $val;
51 if ( $http_response_code !==
null ) {
52 $this->code = intval( $http_response_code );
61 $this->code = intval(
$code );
73 $key = strtoupper( $key );
75 return $this->headers[$key] ??
null;
93 public function setCookie( $name, $value, $expire = 0, $options = [] ) {
97 $options = array_filter( $options,
function ( $a ) {
108 if ( $expire ===
null ) {
114 $this->cookies[$options[
'prefix'] . $name] = [
115 'value' => (string)$value,
116 'expire' => (
int)$expire,
117 'path' => (string)$options[
'path'],
118 'domain' => (
string)$options[
'domain'],
119 'secure' => (bool)$options[
'secure'],
120 'httpOnly' => (
bool)$options[
'httpOnly'],
121 'raw' => (bool)$options[
'raw'],
130 if ( isset( $this->cookies[$name] ) ) {
131 return $this->cookies[$name][
'value'];
141 return $this->cookies[$name] ??
null;