MediaWiki master
HtmlJsCode.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Html;
8
29 public string $value;
30
31 public function __construct( string $value ) {
32 $this->value = $value;
33 }
34
47 public static function encodeObject( $obj, $pretty = false ) {
48 $parts = [];
49 foreach ( $obj as $key => $value ) {
50 $parts[] =
51 ( $pretty ? ' ' : '' ) .
52 Html::encodeJsVar( $key, $pretty ) .
53 ( $pretty ? ': ' : ':' ) .
54 Html::encodeJsVar( $value, $pretty );
55 }
56 return new self(
57 '{' .
58 ( $pretty ? "\n" : '' ) .
59 implode( $pretty ? ",\n" : ',', $parts ) .
60 ( $pretty ? "\n" : '' ) .
61 '}'
62 );
63 }
64}
65
67class_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.
__construct(string $value)
static encodeJsVar( $value, $pretty=false)
Encode a variable of arbitrary type to JavaScript.
Definition Html.php:1143