Merge "Add .pipeline/ with dev image variant"
[lhc/web/wiklou.git] / includes / libs / Message / ListParam.php
1 <?php
2
3 namespace Wikimedia\Message;
4
5 /**
6 * Value object representing a message parameter that consists of a list of values.
7 *
8 * Message parameter classes are pure value objects and are safely newable.
9 */
10 class ListParam extends MessageParam {
11 private $listType;
12
13 /**
14 * @param string $listType One of the ListType constants.
15 * @param (MessageParam|MessageValue|string|int|float)[] $elements Values in the list.
16 * Values that are not instances of MessageParam are wrapped using ParamType::TEXT.
17 */
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
34 /**
35 * Get the type of the list
36 *
37 * @return string One of the ListType constants
38 */
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 }