MediaWiki master
HtmlJsCode.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Html;
22
44 public $value;
45
46 public function __construct( $value ) {
47 $this->value = $value;
48 }
49
62 public static function encodeObject( $obj, $pretty = false ) {
63 $parts = [];
64 foreach ( $obj as $key => $value ) {
65 $parts[] =
66 ( $pretty ? ' ' : '' ) .
67 Html::encodeJsVar( $key, $pretty ) .
68 ( $pretty ? ': ' : ':' ) .
69 Html::encodeJsVar( $value, $pretty );
70 }
71 return new self(
72 '{' .
73 ( $pretty ? "\n" : '' ) .
74 implode( $pretty ? ",\n" : ',', $parts ) .
75 ( $pretty ? "\n" : '' ) .
76 '}'
77 );
78 }
79}
80
82class_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:1126