MediaWiki REL1_37
DataMessageValue.php
Go to the documentation of this file.
1<?php
2
4
25 private $code;
26
28 private $data;
29
40 public function __construct( $key, $params = [], $code = null, array $data = null ) {
41 parent::__construct( $key, $params );
42
43 $this->code = $code ?? $key;
44 $this->data = $data;
45 }
46
55 public static function new( $key, $params = [], $code = null, array $data = null ) {
56 return new DataMessageValue( $key, $params, $code, $data );
57 }
58
63 public function getCode() {
64 return $this->code;
65 }
66
71 public function getData() {
72 return $this->data;
73 }
74
75 public function dump() {
76 $contents = '';
77 if ( $this->getParams() ) {
78 $contents = '<params>';
79 foreach ( $this->getParams() as $param ) {
80 $contents .= $param->dump();
81 }
82 $contents .= '</params>';
83 }
84
85 if ( $this->data !== null ) {
86 $contents .= '<data>' . htmlspecialchars( json_encode( $this->data ), ENT_NOQUOTES ) . '</data>';
87 }
88
89 return '<datamessage key="' . htmlspecialchars( $this->getKey() ) . '"'
90 . ' code="' . htmlspecialchars( $this->code ) . '">'
91 . $contents
92 . '</datamessage>';
93 }
94}
Value object representing a message for i18n with alternative machine-readable data.
getData()
Get the message's structured data.
__construct( $key, $params=[], $code=null, array $data=null)
dump()
Dump the object for testing/debugging.
Value object representing a message for i18n.
getKey()
Get the message key.
getParams()
Get the parameter array.