MediaWiki REL1_37
Wikimedia\Http\SetCookieCompat Class Reference

Public Member Functions

 setCookieEmulated ( $urlEncode, $name, $value, $options=[])
 Temporary emulation for setcookie() or setrawcookie() to match PHP 7.4.3.
 
 setCookieInternal ( $urlEncode, $name, $value, $options=[])
 

Static Public Member Functions

static setcookie ( $name, $value, $options=[])
 Temporary emulation for setcookie() with a SameSite option and encoding spaces in values as "%20" rather than "+".
 
static setrawcookie ( $name, $value, $options=[])
 Temporary emulation for setrawcookie() with a SameSite option.
 

Protected Member Functions

 error ( $message)
 
 header ( $header)
 
 headers_sent ()
 
 time ()
 

Detailed Description

Access: internal
Since
1.35

Definition at line 9 of file SetCookieCompat.php.

Member Function Documentation

◆ error()

Wikimedia\Http\SetCookieCompat::error (   $message)
protected

◆ header()

Wikimedia\Http\SetCookieCompat::header (   $header)
protected

◆ headers_sent()

Wikimedia\Http\SetCookieCompat::headers_sent ( )
protected

◆ setcookie()

static Wikimedia\Http\SetCookieCompat::setcookie (   $name,
  $value,
  $options = [] 
)
static

Temporary emulation for setcookie() with a SameSite option and encoding spaces in values as "%20" rather than "+".

Prior to PHP 7.4.3, setcookie() encoded spaces in cookie values as plus signs. PHP 7.4.2 and later no longer decode plus signs as spaces, which is a backward incompatible change that poses a problem when upgrading a live site, especially if not all servers are to be upgraded at once.

Once MediaWiki requires PHP 7.4.3, this can be replaced with a setcookie() call in the caller.

See also
https://phabricator.wikimedia.org/T291127
https://bugs.php.net/bug.php?id=79174
Parameters
string$nameThe full cookie name
string$valueThe cookie value
array$optionsThe options as passed to setcookie() in PHP 7.3+
Returns
bool

Definition at line 29 of file SetCookieCompat.php.

Referenced by Wikimedia\Http\SetCookieCompat\setCookieInternal().

◆ setCookieEmulated()

Wikimedia\Http\SetCookieCompat::setCookieEmulated (   $urlEncode,
  $name,
  $value,
  $options = [] 
)

Temporary emulation for setcookie() or setrawcookie() to match PHP 7.4.3.

This function corresponds to php_head_parse_cookie_options_array() and php_setcookie() in the PHP source code:

https://github.com/php/php-src/blob/PHP-7.4.3/ext/standard/head.c#L189-L226 https://github.com/php/php-src/blob/PHP-7.4.3/ext/standard/head.c#L79-L187

Access: internal
Parameters
bool$urlEncodeTrue for setcookie(), false for setrawcookie()
string$nameThe full cookie name
string | null$valueThe cookie value
array$optionsThe options as passed to setcookie() in PHP 7.3+
Returns
bool

Definition at line 99 of file SetCookieCompat.php.

References $path, Wikimedia\Http\SetCookieCompat\error(), Wikimedia\Http\SetCookieCompat\header(), Wikimedia\Http\SetCookieCompat\headers_sent(), and Wikimedia\Http\SetCookieCompat\time().

Referenced by Wikimedia\Http\SetCookieCompat\setCookieInternal().

◆ setCookieInternal()

Wikimedia\Http\SetCookieCompat::setCookieInternal (   $urlEncode,
  $name,
  $value,
  $options = [] 
)
Access: internal
Parameters
bool$urlEncodeTrue for setcookie(), false for setrawcookie()
string$nameThe full cookie name
string$valueThe cookie value
array$optionsThe options as passed to setcookie() in PHP 7.3+
Returns
bool

Definition at line 56 of file SetCookieCompat.php.

References Wikimedia\Http\SetCookieCompat\setcookie(), Wikimedia\Http\SetCookieCompat\setCookieEmulated(), and Wikimedia\Http\SetCookieCompat\setrawcookie().

◆ setrawcookie()

static Wikimedia\Http\SetCookieCompat::setrawcookie (   $name,
  $value,
  $options = [] 
)
static

Temporary emulation for setrawcookie() with a SameSite option.

Once MediaWiki requires PHP 7.3, this can be replaced with a setrawcookie() call in the caller.

Parameters
string$nameThe full cookie name
string$valueThe cookie value
array$optionsThe options as passed to setrawcookie() in PHP 7.3+
Returns
bool

Definition at line 44 of file SetCookieCompat.php.

Referenced by Wikimedia\Http\SetCookieCompat\setCookieInternal().

◆ time()

Wikimedia\Http\SetCookieCompat::time ( )
protected

The documentation for this class was generated from the following file: