47 public function header( $string, $replace =
true, $http_response_code =
null ) {
52 if ( str_starts_with( $string,
'HTTP/' ) ) {
53 $parts = explode(
' ', $string, 3 );
54 $this->code = intval( $parts[1] );
56 [ $key, $val ] = array_map(
'trim', explode(
":", $string, 2 ) );
58 $key = strtoupper( $key );
60 if ( $replace || !isset( $this->headers[$key] ) ) {
61 $this->headers[$key] = $val;
65 if ( $http_response_code ) {
66 $this->code = intval( $http_response_code );
124 public function setCookie( $name, $value, $expire = 0, $options = [] ) {
125 if ( $this->disableForPostSend ) {
129 $cookieConfig = $this->getCookieConfig();
130 $cookiePath = $cookieConfig->get( MainConfigNames::CookiePath );
131 $cookiePrefix = $cookieConfig->get( MainConfigNames::CookiePrefix );
132 $cookieDomain = $cookieConfig->get( MainConfigNames::CookieDomain );
133 $cookieSecure = $cookieConfig->get( MainConfigNames::CookieSecure );
134 $cookieExpiration = $cookieConfig->get( MainConfigNames::CookieExpiration );
135 $cookieHttpOnly = $cookieConfig->get( MainConfigNames::CookieHttpOnly );
136 $options = array_filter( $options,
static function ( $a ) {
139 'prefix' => $cookiePrefix,
140 'domain' => $cookieDomain,
141 'path' => $cookiePath,
142 'secure' => $cookieSecure,
143 'httpOnly' => $cookieHttpOnly,
147 if ( $expire ===
null ) {
149 } elseif ( $expire == 0 && $cookieExpiration != 0 ) {
150 $expire = time() + $cookieExpiration;
153 $this->cookies[$options[
'prefix'] . $name] = [
154 'value' => (string)$value,
155 'expire' => (
int)$expire,
156 'path' => (string)$options[
'path'],
157 'domain' => (
string)$options[
'domain'],
158 'secure' => (bool)$options[
'secure'],
159 'httpOnly' => (
bool)$options[
'httpOnly'],
160 'raw' => (bool)$options[
'raw'],