Fix use of GenderCache in ApiPageSet::processTitlesArray
[lhc/web/wiklou.git] / includes / libs / Message / ListParam.php
1 <?php
2
3 namespace Wikimedia\Message;
4
5 /**
6 * The class for list parameters
7 */
8 class ListParam extends MessageParam {
9 private $listType;
10
11 /**
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
17 * the word "and".
18 * @param (MessageParam|string)[] $elements An array of parameters
19 */
20 public function __construct( $listType, array $elements ) {
21 $this->type = ParamType::LIST;
22 $this->listType = $listType;
23 $this->value = [];
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 );
29 } else {
30 throw new \InvalidArgumentException(
31 'ListParam elements must be MessageParam or scalar' );
32 }
33 }
34 }
35
36 /**
37 * Get the type of the list
38 *
39 * @return string One of the ListType constants
40 */
41 public function getListType() {
42 return $this->listType;
43 }
44
45 public function dump() {
46 $contents = '';
47 foreach ( $this->value as $element ) {
48 $contents .= $element->dump();
49 }
50 return "<{$this->type} listType=\"{$this->listType}\">$contents</{$this->type}>";
51 }
52 }