35 private $cookies = [];
39 private $cookieConfig =
null;
47 public function header( $string, $replace =
true, $http_response_code =
null ) {
48 if ( substr( $string, 0, 5 ) ==
'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 );
71 $this->code = intval( $code );
83 $key = strtoupper( $key );
85 return $this->headers[$key] ??
null;
100 private function getCookieConfig():
Config {
101 if ( !$this->cookieConfig ) {
104 return $this->cookieConfig;
111 $this->cookieConfig = $cookieConfig;
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'],
161 if ( isset( $this->cookies[$name] ) ) {
162 return $this->cookies[$name][
'value'];
172 return $this->cookies[$name] ??
null;
179 return $this->cookies;
186 return count( $this->cookies ) > 0;
191class_alias( FauxResponse::class,
'FauxResponse' );
if(!defined('MW_SETUP_CALLBACK'))
The persistent session ID (if any) loaded at startup.
A class containing constants representing the names of configuration variables.
Interface for configuration instances.
get( $name)
Get a configuration variable such as "Sitename" or "UploadMaintenance.".