47 public function header( $string, $replace =
true, $http_response_code =
null ) {
48 if ( str_starts_with( $string,
'HTTP/' ) ) {
49 $parts = explode(
' ', $string, 3 );
50 $this->code = intval( $parts[1] );
52 [ $key, $val ] = array_map(
'trim', explode(
":", $string, 2 ) );
54 $key = strtoupper( $key );
56 if ( $replace || !isset( $this->headers[$key] ) ) {
57 $this->headers[$key] = $val;
61 if ( $http_response_code !==
null ) {
62 $this->code = intval( $http_response_code );
120 public function setCookie( $name, $value, $expire = 0, $options = [] ) {
121 $cookieConfig = $this->getCookieConfig();
122 $cookiePath = $cookieConfig->get( MainConfigNames::CookiePath );
123 $cookiePrefix = $cookieConfig->get( MainConfigNames::CookiePrefix );
124 $cookieDomain = $cookieConfig->get( MainConfigNames::CookieDomain );
125 $cookieSecure = $cookieConfig->get( MainConfigNames::CookieSecure );
126 $cookieExpiration = $cookieConfig->get( MainConfigNames::CookieExpiration );
127 $cookieHttpOnly = $cookieConfig->get( MainConfigNames::CookieHttpOnly );
128 $options = array_filter( $options,
static function ( $a ) {
131 'prefix' => $cookiePrefix,
132 'domain' => $cookieDomain,
133 'path' => $cookiePath,
134 'secure' => $cookieSecure,
135 'httpOnly' => $cookieHttpOnly,
139 if ( $expire ===
null ) {
141 } elseif ( $expire == 0 && $cookieExpiration != 0 ) {
142 $expire = time() + $cookieExpiration;
145 $this->cookies[$options[
'prefix'] . $name] = [
146 'value' => (string)$value,
147 'expire' => (
int)$expire,
148 'path' => (string)$options[
'path'],
149 'domain' => (
string)$options[
'domain'],
150 'secure' => (bool)$options[
'secure'],
151 'httpOnly' => (
bool)$options[
'httpOnly'],
152 'raw' => (bool)$options[
'raw'],