MediaWiki  1.33.0
FauxResponse.php
Go to the documentation of this file.
1 <?php
26 class FauxResponse extends WebResponse {
27  private $headers;
28  private $cookies = [];
29  private $code;
30 
37  public function header( $string, $replace = true, $http_response_code = null ) {
38  if ( substr( $string, 0, 5 ) == 'HTTP/' ) {
39  $parts = explode( ' ', $string, 3 );
40  $this->code = intval( $parts[1] );
41  } else {
42  list( $key, $val ) = array_map( 'trim', explode( ":", $string, 2 ) );
43 
44  $key = strtoupper( $key );
45 
46  if ( $replace || !isset( $this->headers[$key] ) ) {
47  $this->headers[$key] = $val;
48  }
49  }
50 
51  if ( $http_response_code !== null ) {
52  $this->code = intval( $http_response_code );
53  }
54  }
55 
60  public function statusHeader( $code ) {
61  $this->code = intval( $code );
62  }
63 
64  public function headersSent() {
65  return false;
66  }
67 
72  public function getHeader( $key ) {
73  $key = strtoupper( $key );
74 
75  return $this->headers[$key] ?? null;
76  }
77 
83  public function getStatusCode() {
84  return $this->code;
85  }
86 
93  public function setCookie( $name, $value, $expire = 0, $options = [] ) {
96 
97  $options = array_filter( $options, function ( $a ) {
98  return $a !== null;
99  } ) + [
100  'prefix' => $wgCookiePrefix,
101  'domain' => $wgCookieDomain,
102  'path' => $wgCookiePath,
103  'secure' => $wgCookieSecure,
104  'httpOnly' => $wgCookieHttpOnly,
105  'raw' => false,
106  ];
107 
108  if ( $expire === null ) {
109  $expire = 0; // Session cookie
110  } elseif ( $expire == 0 && $wgCookieExpiration != 0 ) {
111  $expire = time() + $wgCookieExpiration;
112  }
113 
114  $this->cookies[$options['prefix'] . $name] = [
115  'value' => (string)$value,
116  'expire' => (int)$expire,
117  'path' => (string)$options['path'],
118  'domain' => (string)$options['domain'],
119  'secure' => (bool)$options['secure'],
120  'httpOnly' => (bool)$options['httpOnly'],
121  'raw' => (bool)$options['raw'],
122  ];
123  }
124 
129  public function getCookie( $name ) {
130  if ( isset( $this->cookies[$name] ) ) {
131  return $this->cookies[$name]['value'];
132  }
133  return null;
134  }
135 
140  public function getCookieData( $name ) {
141  return $this->cookies[$name] ?? null;
142  }
143 
147  public function getCookies() {
148  return $this->cookies;
149  }
150 }
FauxResponse\getCookieData
getCookieData( $name)
Definition: FauxResponse.php:140
FauxResponse\getCookies
getCookies()
Definition: FauxResponse.php:147
FauxResponse\$code
$code
Definition: FauxResponse.php:29
$wgCookiePath
$wgCookiePath
Set this variable if you want to restrict cookies to a certain path within the domain specified by $w...
Definition: DefaultSettings.php:6003
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
FauxResponse\getHeader
getHeader( $key)
Definition: FauxResponse.php:72
FauxResponse\$headers
$headers
Definition: FauxResponse.php:27
FauxResponse\header
header( $string, $replace=true, $http_response_code=null)
Stores a HTTP header.
Definition: FauxResponse.php:37
$wgCookieHttpOnly
$wgCookieHttpOnly
Set authentication cookies to HttpOnly to prevent access by JavaScript, in browsers that support this...
Definition: DefaultSettings.php:6033
string
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible true was required This is the default since MediaWiki *some string
Definition: hooks.txt:175
list
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
FauxResponse\getCookie
getCookie( $name)
Definition: FauxResponse.php:129
$wgCookieExpiration
$wgCookieExpiration
Default cookie lifetime, in seconds.
Definition: DefaultSettings.php:5983
FauxResponse\statusHeader
statusHeader( $code)
Definition: FauxResponse.php:60
code
and how to run hooks for an and one after Each event has a preferably in CamelCase For ArticleDelete hook A clump of code and data that should be run when an event happens This can be either a function and a chunk of or an object and a method hook function The function part of a third party developers and administrators to define code that will be run at certain points in the mainline code
Definition: hooks.txt:23
$value
$value
Definition: styleTest.css.php:49
$wgCookieDomain
$wgCookieDomain
Set to set an explicit domain on the login cookies eg, "justthis.domain.org" or "....
Definition: DefaultSettings.php:5997
FauxResponse\setCookie
setCookie( $name, $value, $expire=0, $options=[])
Definition: FauxResponse.php:93
FauxResponse
Definition: FauxResponse.php:26
$options
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition: hooks.txt:1985
FauxResponse\headersSent
headersSent()
Test if headers have been sent.
Definition: FauxResponse.php:64
FauxResponse\getStatusCode
getStatusCode()
Get the HTTP response code, null if not set.
Definition: FauxResponse.php:83
$wgCookieSecure
$wgCookieSecure
Whether the "secure" flag should be set on the cookie.
Definition: DefaultSettings.php:6011
WebResponse
Allow programs to request this object from WebRequest::response() and handle all outputting (or lack ...
Definition: WebResponse.php:28
FauxResponse\$cookies
$cookies
Definition: FauxResponse.php:28
$wgCookiePrefix
$wgCookiePrefix
Cookies generated by MediaWiki have names starting with this prefix.
Definition: DefaultSettings.php:6026