MediaWiki  master
DataMessageValue.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Wikimedia\Message;
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 }
Wikimedia\Message\DataMessageValue\getCode
getCode()
Get the message code.
Definition: DataMessageValue.php:63
Wikimedia\Message\DataMessageValue\__construct
__construct( $key, $params=[], $code=null, array $data=null)
Stable to call.
Definition: DataMessageValue.php:40
Wikimedia\Message\MessageValue\getKey
getKey()
Get the message key.
Definition: MessageValue.php:51
Wikimedia\Message\DataMessageValue\getData
getData()
Get the message's structured data.
Definition: DataMessageValue.php:71
Wikimedia\Message\DataMessageValue\$data
array null $data
Definition: DataMessageValue.php:28
Wikimedia\Message\MessageValue
Value object representing a message for i18n.
Definition: MessageValue.php:16
Wikimedia\Message
Definition: DataMessageValue.php:3
Wikimedia\Message\MessageValue\getParams
getParams()
Get the parameter array.
Definition: MessageValue.php:60
Wikimedia\Message\DataMessageValue\dump
dump()
Dump the object for testing/debugging.
Definition: DataMessageValue.php:75
Wikimedia\Message\MessageValue\$params
MessageParam[] $params
Definition: MessageValue.php:21
Wikimedia\Message\DataMessageValue
Value object representing a message for i18n with alternative machine-readable data.
Definition: DataMessageValue.php:23
Wikimedia\Message\DataMessageValue\$code
string $code
Definition: DataMessageValue.php:25
Wikimedia\Message\MessageValue\$key
string $key
Definition: MessageValue.php:18