3 namespace Wikimedia\Message
;
6 * The class for list parameters
8 class ListParam
extends MessageParam
{
12 * @param string $listType One of the ListType constants:
13 * - ListType::COMMA: A comma-separated list
14 * - ListType::SEMICOLON: A semicolon-separated list
15 * - ListType::PIPE: A pipe-separated list
16 * - ListType::TEXT: A natural language list, separated by commas and
18 * @param (MessageParam|string)[] $elements An array of parameters
20 public function __construct( $listType, array $elements ) {
21 $this->type
= ParamType
::LIST;
22 $this->listType
= $listType;
24 foreach ( $elements as $element ) {
25 if ( $element instanceof MessageParam
) {
26 $this->value
[] = $element;
27 } elseif ( is_scalar( $element ) ) {
28 $this->value
[] = new TextParam( ParamType
::TEXT
, $element );
30 throw new \
InvalidArgumentException(
31 'ListParam elements must be MessageParam or scalar' );
37 * Get the type of the list
39 * @return string One of the ListType constants
41 public function getListType() {
42 return $this->listType
;
45 public function dump() {
47 foreach ( $this->value
as $element ) {
48 $contents .= $element->dump();
50 return "<{$this->type} listType=\"{$this->listType}\">$contents</{$this->type}>";