50 public function header( $string, $replace =
true, $http_response_code =
null ) {
55 if ( str_starts_with( $string,
'HTTP/' ) ) {
56 $parts = explode(
' ', $string, 3 );
57 $this->code = intval( $parts[1] );
59 [ $key, $val ] = array_map(
'trim', explode(
":", $string, 2 ) );
61 $key = strtoupper( $key );
63 if ( $replace || !isset( $this->headers[$key] ) ) {
64 $this->headers[$key] = $val;
68 if ( $http_response_code ) {
69 $this->code = intval( $http_response_code );
121 public function setCookie( $name, $value, $expire = 0, $options = [] ) {
122 if ( $this->disableForPostSend ) {
126 $cookieConfig = $this->getCookieConfig();
127 $cookiePath = $cookieConfig->get( MainConfigNames::CookiePath );
128 $cookiePrefix = $cookieConfig->get( MainConfigNames::CookiePrefix );
129 $cookieDomain = $cookieConfig->get( MainConfigNames::CookieDomain );
130 $cookieSecure = $cookieConfig->get( MainConfigNames::CookieSecure );
131 $cookieExpiration = $cookieConfig->get( MainConfigNames::CookieExpiration );
132 $cookieHttpOnly = $cookieConfig->get( MainConfigNames::CookieHttpOnly );
133 $options = array_filter( $options,
static function ( $a ) {
136 'prefix' => $cookiePrefix,
137 'domain' => $cookieDomain,
138 'path' => $cookiePath,
139 'secure' => $cookieSecure,
140 'httpOnly' => $cookieHttpOnly,
144 if ( $expire ===
null ) {
146 } elseif ( $expire == 0 && $cookieExpiration != 0 ) {
147 $expire = time() + $cookieExpiration;
150 $this->cookies[$options[
'prefix'] . $name] = [
151 'value' => (string)$value,
152 'expire' => (
int)$expire,
153 'path' => (string)$options[
'path'],
154 'domain' => (
string)$options[
'domain'],
155 'secure' => (bool)$options[
'secure'],
156 'httpOnly' => (
bool)$options[
'httpOnly'],
157 'raw' => (bool)$options[
'raw'],