48 self::$disableForPostSend =
true;
57 public function header( $string, $replace =
true, $http_response_code =
null ) {
58 if ( self::$disableForPostSend ) {
59 wfDebugLog(
'header',
'ignored post-send header {header}',
'all', [
61 'replace' => $replace,
62 'http_response_code' => $http_response_code,
63 'exception' =>
new RuntimeException(
'Ignored post-send header' ),
69 if ( $http_response_code ) {
70 header( $string, $replace, $http_response_code );
72 header( $string, $replace );
83 foreach ( headers_list() as
$header ) {
84 list( $name, $val ) = explode(
':',
$header, 2 );
85 if ( !strcasecmp( $name, $key ) ) {
98 if ( self::$disableForPostSend ) {
99 wfDebugLog(
'header',
'ignored post-send status header {code}',
'all', [
101 'exception' =>
new RuntimeException(
'Ignored post-send status header' ),
115 return headers_sent();
133 public function setCookie( $name, $value, $expire = 0, $options = [] ) {
137 $options = array_filter( $options,
function ( $a ) {
148 if ( $expire ===
null ) {
154 if ( self::$disableForPostSend ) {
155 $cookie = $options[
'prefix'] . $name;
156 wfDebugLog(
'cookie',
'ignored post-send cookie {cookie}',
'all', [
159 'name' => (
string)$cookie,
160 'value' => (
string)$value,
161 'expire' => (
int)$expire,
162 'path' => (
string)$options[
'path'],
163 'domain' => (
string)$options[
'domain'],
164 'secure' => (
bool)$options[
'secure'],
165 'httpOnly' => (
bool)$options[
'httpOnly'],
167 'exception' =>
new RuntimeException(
'Ignored post-send cookie' ),
172 $func = $options[
'raw'] ?
'setrawcookie' :
'setcookie';
174 if (
Hooks::run(
'WebResponseSetCookie', [ &$name, &$value, &$expire, &$options ] ) ) {
177 $cookie = $options[
'prefix'] . $name;
179 'name' => (string)$cookie,
180 'value' => (
string)$value,
181 'expire' => (int)$expire,
182 'path' => (
string)$options[
'path'],
183 'domain' => (string)$options[
'domain'],
184 'secure' => (
bool)$options[
'secure'],
185 'httpOnly' => (bool)$options[
'httpOnly'],
189 $key =
"{$data['name']}\n{$data['domain']}\n{$data['path']}";
193 if ( isset( $_COOKIE[$cookie] ) && !array_key_exists( $key, self::$setCookies ) ) {
194 self::$setCookies[$key] = [];
198 $deleting = ( $data[
'value'] ===
'' || $data[
'expire'] > 0 && $data[
'expire'] <= time() );
200 if ( $deleting && !isset( self::$setCookies[$key] ) ) {
201 wfDebugLog(
'cookie',
'already deleted ' . $func .
': "' . implode(
'", "', $data ) .
'"' );
202 } elseif ( !$deleting && isset( self::$setCookies[$key] ) &&
203 self::$setCookies[$key] === [ $func, $data ]
205 wfDebugLog(
'cookie',
'already set ' . $func .
': "' . implode(
'", "', $data ) .
'"' );
207 wfDebugLog(
'cookie', $func .
': "' . implode(
'", "', $data ) .
'"' );
208 if ( $func( ...array_values( $data ) ) ) {
209 self::$setCookies[$key] = $deleting ? null : [ $func, $data ];
225 $this->
setCookie( $name,
'', time() - 31536000 , $options );