MediaWiki REL1_35
MessageValue.php
Go to the documentation of this file.
1<?php
2
3namespace Wikimedia\Message;
4
18 private $key;
19
21 private $params;
22
30 public function __construct( $key, $params = [] ) {
31 $this->key = $key;
32 $this->params = [];
33 $this->params( ...$params );
34 }
35
42 public static function new( $key, $params = [] ) {
43 return new MessageValue( $key, $params );
44 }
45
51 public function getKey() {
52 return $this->key;
53 }
54
60 public function getParams() {
61 return $this->params;
62 }
63
70 public function params( ...$values ) {
71 foreach ( $values as $value ) {
72 if ( $value instanceof MessageParam ) {
73 $this->params[] = $value;
74 } else {
75 $this->params[] = new ScalarParam( ParamType::TEXT, $value );
76 }
77 }
78 return $this;
79 }
80
88 public function textParamsOfType( $type, ...$values ) {
89 foreach ( $values as $value ) {
90 $this->params[] = new ScalarParam( $type, $value );
91 }
92 return $this;
93 }
94
103 public function listParamsOfType( $listType, ...$values ) {
104 foreach ( $values as $value ) {
105 $this->params[] = new ListParam( $listType, $value );
106 }
107 return $this;
108 }
109
116 public function textParams( ...$values ) {
117 return $this->textParamsOfType( ParamType::TEXT, ...$values );
118 }
119
126 public function numParams( ...$values ) {
127 return $this->textParamsOfType( ParamType::NUM, ...$values );
128 }
129
140 public function longDurationParams( ...$values ) {
141 return $this->textParamsOfType( ParamType::DURATION_LONG, ...$values );
142 }
143
154 public function shortDurationParams( ...$values ) {
155 return $this->textParamsOfType( ParamType::DURATION_SHORT, ...$values );
156 }
157
165 public function expiryParams( ...$values ) {
166 return $this->textParamsOfType( ParamType::EXPIRY, ...$values );
167 }
168
175 public function sizeParams( ...$values ) {
176 return $this->textParamsOfType( ParamType::SIZE, ...$values );
177 }
178
186 public function bitrateParams( ...$values ) {
187 return $this->textParamsOfType( ParamType::BITRATE, ...$values );
188 }
189
200 public function rawParams( ...$values ) {
201 return $this->textParamsOfType( ParamType::RAW, ...$values );
202 }
203
214 public function plaintextParams( ...$values ) {
215 return $this->textParamsOfType( ParamType::PLAINTEXT, ...$values );
216 }
217
228 public function commaListParams( ...$values ) {
229 return $this->listParamsOfType( ListType::COMMA, ...$values );
230 }
231
242 public function semicolonListParams( ...$values ) {
243 return $this->listParamsOfType( ListType::SEMICOLON, ...$values );
244 }
245
256 public function pipeListParams( ...$values ) {
257 return $this->listParamsOfType( ListType::PIPE, ...$values );
258 }
259
270 public function textListParams( ...$values ) {
271 return $this->listParamsOfType( ListType::AND, ...$values );
272 }
273
279 public function dump() {
280 $contents = '';
281 foreach ( $this->params as $param ) {
282 $contents .= $param->dump();
283 }
284 return '<message key="' . htmlspecialchars( $this->key ) . '">' .
285 $contents . '</message>';
286 }
287}
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.
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.
commaListParams(... $values)
Chainable mutator which adds comma lists (ListType::COMMA).
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...
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=[])
Stable to call.
const DURATION_SHORT
A number of seconds, to be formatted as natural language text in an abbreviated way.
Definition ParamType.php:28
const EXPIRY
An expiry time.
Definition ParamType.php:39
const RAW
A text parameter which is substituted after formatter processing.
Definition ParamType.php:57
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:42
const NUM
A number, to be formatted using local digits and separators.
Definition ParamType.php:16
const DURATION_LONG
A number of seconds, to be formatted as natural language text.
Definition ParamType.php:22
const PLAINTEXT
A text parameter which is substituted after formatter processing.
Definition ParamType.php:64
const BITRATE
A number of bits per second.
Definition ParamType.php:45
Value object representing a message parameter holding a single value.