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