44 public function header( $string, $replace =
true, $http_response_code =
null ) {
45 if ( substr( $string, 0, 5 ) ==
'HTTP/' ) {
46 $parts = explode(
' ', $string, 3 );
47 $this->code = intval( $parts[1] );
49 [ $key, $val ] = array_map(
'trim', explode(
":", $string, 2 ) );
51 $key = strtoupper( $key );
53 if ( $replace || !isset( $this->headers[$key] ) ) {
54 $this->headers[$key] = $val;
58 if ( $http_response_code !==
null ) {
59 $this->code = intval( $http_response_code );
117 public function setCookie( $name, $value, $expire = 0, $options = [] ) {
118 $cookieConfig = $this->getCookieConfig();
119 $cookiePath = $cookieConfig->get( MainConfigNames::CookiePath );
120 $cookiePrefix = $cookieConfig->get( MainConfigNames::CookiePrefix );
121 $cookieDomain = $cookieConfig->get( MainConfigNames::CookieDomain );
122 $cookieSecure = $cookieConfig->get( MainConfigNames::CookieSecure );
123 $cookieExpiration = $cookieConfig->get( MainConfigNames::CookieExpiration );
124 $cookieHttpOnly = $cookieConfig->get( MainConfigNames::CookieHttpOnly );
125 $options = array_filter( $options,
static function ( $a ) {
128 'prefix' => $cookiePrefix,
129 'domain' => $cookieDomain,
130 'path' => $cookiePath,
131 'secure' => $cookieSecure,
132 'httpOnly' => $cookieHttpOnly,
136 if ( $expire ===
null ) {
138 } elseif ( $expire == 0 && $cookieExpiration != 0 ) {
139 $expire = time() + $cookieExpiration;
142 $this->cookies[$options[
'prefix'] . $name] = [
143 'value' => (string)$value,
144 'expire' => (
int)$expire,
145 'path' => (string)$options[
'path'],
146 'domain' => (
string)$options[
'domain'],
147 'secure' => (bool)$options[
'secure'],
148 'httpOnly' => (
bool)$options[
'httpOnly'],
149 'raw' => (bool)$options[
'raw'],