MediaWiki REL1_39
MessageValue.php
Go to the documentation of this file.
1<?php
2
3namespace Wikimedia\Message;
4
5use Stringable;
6
20 private $key;
21
23 private $params;
24
32 public function __construct( $key, $params = [] ) {
33 $this->key = $key;
34 $this->params = [];
35 $this->params( ...$params );
36 }
37
44 public static function new( $key, $params = [] ) {
45 return new MessageValue( $key, $params );
46 }
47
53 public function getKey() {
54 return $this->key;
55 }
56
62 public function getParams() {
63 return $this->params;
64 }
65
72 public function params( ...$values ) {
73 foreach ( $values as $value ) {
74 if ( $value instanceof MessageParam ) {
75 $this->params[] = $value;
76 } else {
77 $this->params[] = new ScalarParam( ParamType::TEXT, $value );
78 }
79 }
80 return $this;
81 }
82
90 public function textParamsOfType( $type, ...$values ) {
91 foreach ( $values as $value ) {
92 $this->params[] = new ScalarParam( $type, $value );
93 }
94 return $this;
95 }
96
103 public function objectParams( ...$values ) {
104 foreach ( $values as $value ) {
105 $this->params[] = new ScalarParam( ParamType::OBJECT, $value );
106 }
107 return $this;
108 }
109
118 public function listParamsOfType( $listType, ...$values ) {
119 foreach ( $values as $value ) {
120 $this->params[] = new ListParam( $listType, $value );
121 }
122 return $this;
123 }
124
131 public function textParams( ...$values ) {
132 return $this->textParamsOfType( ParamType::TEXT, ...$values );
133 }
134
141 public function numParams( ...$values ) {
142 return $this->textParamsOfType( ParamType::NUM, ...$values );
143 }
144
155 public function longDurationParams( ...$values ) {
156 return $this->textParamsOfType( ParamType::DURATION_LONG, ...$values );
157 }
158
169 public function shortDurationParams( ...$values ) {
170 return $this->textParamsOfType( ParamType::DURATION_SHORT, ...$values );
171 }
172
180 public function expiryParams( ...$values ) {
181 return $this->textParamsOfType( ParamType::EXPIRY, ...$values );
182 }
183
191 public function dateTimeParams( ...$values ) {
192 return $this->textParamsOfType( ParamType::DATETIME, ...$values );
193 }
194
202 public function dateParams( ...$values ) {
203 return $this->textParamsOfType( ParamType::DATE, ...$values );
204 }
205
213 public function timeParams( ...$values ) {
214 return $this->textParamsOfType( ParamType::TIME, ...$values );
215 }
216
224 public function userGroupParams( ...$values ) {
225 return $this->textParamsOfType( ParamType::GROUP, ...$values );
226 }
227
234 public function sizeParams( ...$values ) {
235 return $this->textParamsOfType( ParamType::SIZE, ...$values );
236 }
237
245 public function bitrateParams( ...$values ) {
246 return $this->textParamsOfType( ParamType::BITRATE, ...$values );
247 }
248
259 public function rawParams( ...$values ) {
260 return $this->textParamsOfType( ParamType::RAW, ...$values );
261 }
262
273 public function plaintextParams( ...$values ) {
274 return $this->textParamsOfType( ParamType::PLAINTEXT, ...$values );
275 }
276
287 public function commaListParams( ...$values ) {
288 return $this->listParamsOfType( ListType::COMMA, ...$values );
289 }
290
301 public function semicolonListParams( ...$values ) {
302 return $this->listParamsOfType( ListType::SEMICOLON, ...$values );
303 }
304
315 public function pipeListParams( ...$values ) {
316 return $this->listParamsOfType( ListType::PIPE, ...$values );
317 }
318
329 public function textListParams( ...$values ) {
330 return $this->listParamsOfType( ListType::AND, ...$values );
331 }
332
338 public function dump() {
339 $contents = '';
340 foreach ( $this->params as $param ) {
341 $contents .= $param->dump();
342 }
343 return '<message key="' . htmlspecialchars( $this->key ) . '">' .
344 $contents . '</message>';
345 }
346}
Value object representing a message parameter that consists of a list of values.
Definition ListParam.php:12
const COMMA
A comma-separated list.
Definition ListType.php:11
const PIPE
A pipe-separated list.
Definition ListType.php:17
const AND
A natural-language list separated by "and".
Definition ListType.php:20
const SEMICOLON
A semicolon-separated list.
Definition ListType.php:14
Value object representing a message parameter that consists of a list of values.
Value object representing a message for i18n.
objectParams(... $values)
Chainable mutator which adds object parameters.
longDurationParams(... $values)
Chainable mutator which adds parameters which are a duration specified in seconds (ParamType::DURATIO...
textParams(... $values)
Chainable mutator which adds parameters of type text (ParamType::TEXT).
getKey()
Get the message key.
listParamsOfType( $listType,... $values)
Chainable mutator which adds list parameters with a common type.
params(... $values)
Chainable mutator which adds text parameters and MessageParam parameters.
dateTimeParams(... $values)
Chainable mutator which adds parameters which are a date-time timestamp (ParamType::DATETIME).
userGroupParams(... $values)
Chainable mutator which adds parameters which are a user group (ParamType::GROUP).
commaListParams(... $values)
Chainable mutator which adds comma lists (ListType::COMMA).
timeParams(... $values)
Chainable mutator which adds parameters which are a time timestamp (ParamType::TIME).
semicolonListParams(... $values)
Chainable mutator which adds semicolon lists (ListType::SEMICOLON).
numParams(... $values)
Chainable mutator which adds numeric parameters (ParamType::NUM).
bitrateParams(... $values)
Chainable mutator which adds parameters which are a number of bits per second (ParamType::BITRATE).
shortDurationParams(... $values)
Chainable mutator which adds parameters which are a duration specified in seconds (ParamType::DURATIO...
dateParams(... $values)
Chainable mutator which adds parameters which are a date timestamp (ParamType::DATE).
getParams()
Get the parameter array.
sizeParams(... $values)
Chainable mutator which adds parameters which are a number of bytes (ParamType::SIZE).
textListParams(... $values)
Chainable mutator which adds natural-language lists (ListType::AND).
expiryParams(... $values)
Chainable mutator which adds parameters which are an expiry timestamp (ParamType::EXPIRY).
textParamsOfType( $type,... $values)
Chainable mutator which adds text parameters with a common type.
dump()
Dump the object for testing/debugging.
pipeListParams(... $values)
Chainable mutator which adds pipe lists (ListType::PIPE).
rawParams(... $values)
Chainable mutator which adds "raw" parameters (ParamType::RAW).
plaintextParams(... $values)
Chainable mutator which adds plaintext parameters (ParamType::PLAINTEXT).
__construct( $key, $params=[])
const DURATION_SHORT
A number of seconds, to be formatted as natural language text in an abbreviated way.
Definition ParamType.php:28
const DATETIME
A date time in one of the formats accepted by the Wikimedia\Timestamp library.
Definition ParamType.php:46
const TIME
A time in one of the formats accepted by the Wikimedia\Timestamp library.
Definition ParamType.php:60
const EXPIRY
An expiry time.
Definition ParamType.php:39
const RAW
A text parameter which is substituted after formatter processing.
Definition ParamType.php:90
const TEXT
A simple text string or another MessageValue, not otherwise formatted.
Definition ParamType.php:13
const SIZE
A number of bytes.
Definition ParamType.php:75
const NUM
A number, to be formatted using local digits and separators.
Definition ParamType.php:16
const GROUP
User Group.
Definition ParamType.php:66
const DURATION_LONG
A number of seconds, to be formatted as natural language text.
Definition ParamType.php:22
const DATE
A date in one of the formats accepted by the Wikimedia\Timestamp library.
Definition ParamType.php:53
const PLAINTEXT
A text parameter which is substituted after formatter processing.
Definition ParamType.php:97
const BITRATE
A number of bits per second.
Definition ParamType.php:78
const OBJECT
For arbitrary stringable objects.
Definition ParamType.php:72
Value object representing a message parameter holding a single value.