MediaWiki master
HtmlJsCode.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Html;
22
43 public $value;
44
45 public function __construct( $value ) {
46 $this->value = $value;
47 }
48
61 public static function encodeObject( $obj, $pretty = false ) {
62 $parts = [];
63 foreach ( $obj as $key => $value ) {
64 $parts[] =
65 ( $pretty ? ' ' : '' ) .
66 Html::encodeJsVar( $key, $pretty ) .
67 ( $pretty ? ': ' : ':' ) .
68 Html::encodeJsVar( $value, $pretty );
69 }
70 return new self(
71 '{' .
72 ( $pretty ? "\n" : '' ) .
73 implode( $pretty ? ",\n" : ',', $parts ) .
74 ( $pretty ? "\n" : '' ) .
75 '}'
76 );
77 }
78}
79
81class_alias( HtmlJsCode::class, 'XmlJsCode' );
A wrapper class which causes Html::encodeJsVar() and Html::encodeJsCall() (as well as their Xml::* co...
static encodeObject( $obj, $pretty=false)
Encode an object containing HtmlJsCode objects.
static encodeJsVar( $value, $pretty=false)
Encode a variable of arbitrary type to JavaScript.
Definition Html.php:1105