MediaWiki  1.34.0
XmlJsCode Class Reference

A wrapper class which causes Xml::encodeJsVar() and Xml::encodeJsCall() 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 XmlJsCode objects. More...
 

Public Attributes

 $value
 

Detailed Description

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

Example:
Xml::encodeJsVar( new XmlJsCode( 'a + b' ) );

This returns "a + b".

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

Definition at line 40 of file XmlJsCode.php.

Constructor & Destructor Documentation

◆ __construct()

XmlJsCode::__construct (   $value)

Definition at line 43 of file XmlJsCode.php.

References $value, and value.

Member Function Documentation

◆ encodeObject()

static XmlJsCode::encodeObject (   $obj,
  $pretty = false 
)
static

Encode an object containing XmlJsCode objects.

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

Since
1.33
Parameters
object | array$objObject or associative array to encode
bool$prettyIf true, add non-significant whitespace to improve readability.
Returns
XmlJsCode

Definition at line 58 of file XmlJsCode.php.

References $value, and Xml\encodeJsVar().

Member Data Documentation

◆ $value

XmlJsCode::$value

Definition at line 41 of file XmlJsCode.php.

Referenced by __construct(), and encodeObject().


The documentation for this class was generated from the following file:
Xml\encodeJsVar
static encodeJsVar( $value, $pretty=false)
Encode a variable of arbitrary type to JavaScript.
Definition: Xml.php:659
XmlJsCode
A wrapper class which causes Xml::encodeJsVar() and Xml::encodeJsCall() to interpret a given string a...
Definition: XmlJsCode.php:40