MediaWiki  1.34.4
ListParam.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Wikimedia\Message;
4 
10 class ListParam extends MessageParam {
11  private $listType;
12 
18  public function __construct( $listType, array $elements ) {
19  $this->type = ParamType::LIST;
20  $this->listType = $listType;
21  $this->value = [];
22  foreach ( $elements as $element ) {
23  if ( $element instanceof MessageParam ) {
24  $this->value[] = $element;
25  } elseif ( is_scalar( $element ) || $element instanceof MessageValue ) {
26  $this->value[] = new ScalarParam( ParamType::TEXT, $element );
27  } else {
28  throw new \InvalidArgumentException(
29  'ListParam elements must be MessageParam or scalar' );
30  }
31  }
32  }
33 
39  public function getListType() {
40  return $this->listType;
41  }
42 
43  public function dump() {
44  $contents = '';
45  foreach ( $this->value as $element ) {
46  $contents .= $element->dump();
47  }
48  return "<{$this->type} listType=\"{$this->listType}\">$contents</{$this->type}>";
49  }
50 }
Wikimedia\Message\ListParam\getListType
getListType()
Get the type of the list.
Definition: ListParam.php:39
Wikimedia\Message\ScalarParam
Value object representing a message parameter holding a single value.
Definition: ScalarParam.php:10
Wikimedia\Message\ListParam\__construct
__construct( $listType, array $elements)
Definition: ListParam.php:18
Wikimedia\Message\MessageValue
Value object representing a message for i18n.
Definition: MessageValue.php:14
Wikimedia\Message
Definition: IMessageFormatterFactory.php:3
Wikimedia\Message\ListParam
Value object representing a message parameter that consists of a list of values.
Definition: ListParam.php:10
Wikimedia\Message\ParamType\LIST
const LIST
A list of values.
Definition: ParamType.php:48
Wikimedia\Message\ListParam\dump
dump()
Dump the object for testing/debugging.
Definition: ListParam.php:43
Wikimedia\Message\ParamType\TEXT
const TEXT
A simple text string or another MessageValue, not otherwise formatted.
Definition: ParamType.php:13
Wikimedia\Message\ListParam\$listType
$listType
Definition: ListParam.php:11
Wikimedia\Message\MessageParam
Value object representing a message parameter that consists of a list of values.
Definition: MessageParam.php:10