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 );
127 public function setCookie( $name, $value, $expire = 0, $options = [] ) {
128 if ( $this->disableForPostSend ) {
132 $cookieConfig = $this->getCookieConfig();
133 $cookiePath = $cookieConfig->get( MainConfigNames::CookiePath );
134 $cookiePrefix = $cookieConfig->get( MainConfigNames::CookiePrefix );
135 $cookieDomain = $cookieConfig->get( MainConfigNames::CookieDomain );
136 $cookieSecure = $cookieConfig->get( MainConfigNames::CookieSecure );
137 $cookieExpiration = $cookieConfig->get( MainConfigNames::CookieExpiration );
138 $cookieHttpOnly = $cookieConfig->get( MainConfigNames::CookieHttpOnly );
139 $options = array_filter( $options,
static function ( $a ) {
142 'prefix' => $cookiePrefix,
143 'domain' => $cookieDomain,
144 'path' => $cookiePath,
145 'secure' => $cookieSecure,
146 'httpOnly' => $cookieHttpOnly,
150 if ( $expire ===
null ) {
152 } elseif ( $expire == 0 && $cookieExpiration != 0 ) {
153 $expire = time() + $cookieExpiration;
156 $this->cookies[$options[
'prefix'] . $name] = [
157 'value' => (string)$value,
158 'expire' => (
int)$expire,
159 'path' => (string)$options[
'path'],
160 'domain' => (
string)$options[
'domain'],
161 'secure' => (bool)$options[
'secure'],
162 'httpOnly' => (
bool)$options[
'httpOnly'],
163 'raw' => (bool)$options[
'raw'],