MediaWiki master
MediaWiki\Html\HtmlJsCode Class Reference

A wrapper class which causes Html::encodeJsVar() and Html::encodeJsCall() (as well as their Xml::* counterparts) to interpret a given string as being a JavaScript expression, instead of string data. More...

Public Member Functions

 __construct ( $value)
 

Static Public Member Functions

static encodeObject ( $obj, $pretty=false)
 Encode an object containing HtmlJsCode objects.
 

Public Attributes

string $value
 

Detailed Description

A wrapper class which causes Html::encodeJsVar() and Html::encodeJsCall() (as well as their Xml::* counterparts) to interpret a given string as being a JavaScript expression, instead of string data.

Example:
Html::encodeJsVar( new HtmlJsCode( 'a + b' ) );
A wrapper class which causes Html::encodeJsVar() and Html::encodeJsCall() (as well as their Xml::* co...

This returns "a + b".

Note
As of 1.21, HtmlJsCode objects cannot be nested inside objects or arrays. The sole exception is the $args argument to Html::encodeJsCall() because Html::encodeJsVar() is called for each individual element in that array. If you need to encode an object or array containing HtmlJsCode objects, use HtmlJsCode::encodeObject() to re-encode it first.
Since
1.41 (renamed from XmlJsCode, which existed since 1.17)

Definition at line 42 of file HtmlJsCode.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Html\HtmlJsCode::__construct ( $value)

Definition at line 46 of file HtmlJsCode.php.

References MediaWiki\Html\HtmlJsCode\$value.

Member Function Documentation

◆ encodeObject()

static MediaWiki\Html\HtmlJsCode::encodeObject ( $obj,
$pretty = false )
static

Encode an object containing HtmlJsCode objects.

This takes an object or associative array where (some of) the values are HtmlJsCode objects, and re-encodes it as a single HtmlJsCode object.

Since
1.33 @phpcs:ignore MediaWiki.Commenting.FunctionComment.ObjectTypeHintParam
Parameters
object | array$objObject or associative array to encode
bool$prettyIf true, add non-significant whitespace to improve readability.
Returns
HtmlJsCode

Definition at line 62 of file HtmlJsCode.php.

References MediaWiki\Html\HtmlJsCode\$value, and MediaWiki\Html\Html\encodeJsVar().

Member Data Documentation

◆ $value

string MediaWiki\Html\HtmlJsCode::$value

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