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 }
A wrapper class which causes Xml::encodeJsVar() and Xml::encodeJsCall() to interpret a given string a...
Definition: XmlJsCode.php:40
static encodeObject( $obj, $pretty=false)
Encode an object containing XmlJsCode objects.
Definition: XmlJsCode.php:59
__construct( $value)
Definition: XmlJsCode.php:43
static encodeJsVar( $value, $pretty=false)
Encode a variable of arbitrary type to JavaScript.
Definition: Xml.php:676