d550fec51a1f2fa333656ef8c20afec18561b7e0
3 namespace Wikimedia\Message
;
6 * Value object representing a message parameter that consists of a list of values.
8 * Message parameter classes are pure value objects and are safely newable.
10 class ListParam
extends MessageParam
{
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.
18 public function __construct( $listType, array $elements ) {
19 $this->type
= ParamType
::LIST;
20 $this->listType
= $listType;
22 foreach ( $elements as $element ) {
23 if ( $element instanceof MessageParam
) {
24 $this->value
[] = $element;
25 } elseif ( is_scalar( $element ) ) {
26 $this->value
[] = new ScalarParam( ParamType
::TEXT
, $element );
28 throw new \
InvalidArgumentException(
29 'ListParam elements must be MessageParam or scalar' );
35 * Get the type of the list
37 * @return string One of the ListType constants
39 public function getListType() {
40 return $this->listType
;
43 public function dump() {
45 foreach ( $this->value
as $element ) {
46 $contents .= $element->dump();
48 return "<{$this->type} listType=\"{$this->listType}\">$contents</{$this->type}>";