MediaWiki  master
XmlJsCode.php
Go to the documentation of this file.
1 <?php
40 class XmlJsCode {
41  public $value;
42 
43  public function __construct( $value ) {
44  $this->value = $value;
45  }
46 
59  public static function encodeObject( $obj, $pretty = false ) {
60  $parts = [];
61  foreach ( $obj as $key => $value ) {
62  $parts[] =
63  ( $pretty ? ' ' : '' ) .
64  Xml::encodeJsVar( $key, $pretty ) .
65  ( $pretty ? ': ' : ':' ) .
66  Xml::encodeJsVar( $value, $pretty );
67  }
68  return new self(
69  '{' .
70  ( $pretty ? "\n" : '' ) .
71  implode( $pretty ? ",\n" : ',', $parts ) .
72  ( $pretty ? "\n" : '' ) .
73  '}'
74  );
75  }
76 }
Xml\encodeJsVar
static encodeJsVar( $value, $pretty=false)
Encode a variable of arbitrary type to JavaScript.
Definition: Xml.php:674
XmlJsCode
A wrapper class which causes Xml::encodeJsVar() and Xml::encodeJsCall() to interpret a given string a...
Definition: XmlJsCode.php:40
XmlJsCode\$value
$value
Definition: XmlJsCode.php:41
XmlJsCode\encodeObject
static encodeObject( $obj, $pretty=false)
Encode an object containing XmlJsCode objects.
Definition: XmlJsCode.php:59
XmlJsCode\__construct
__construct( $value)
Definition: XmlJsCode.php:43