MediaWiki REL1_35
ScalarParam.php
Go to the documentation of this file.
1<?php
2
3namespace Wikimedia\Message;
4
21 public function __construct( $type, $value ) {
22 if ( $type === ParamType::LIST ) {
23 throw new \InvalidArgumentException(
24 'ParamType::LIST cannot be used with ScalarParam; use ListParam instead'
25 );
26 }
27 if ( !is_string( $value ) && !is_numeric( $value ) && !$value instanceof MessageValue ) {
28 $type = is_object( $value ) ? get_class( $value ) : gettype( $value );
29 throw new \InvalidArgumentException(
30 "Scalar parameter must be a string, number, or MessageValue; got $type"
31 );
32 }
33
34 $this->type = $type;
35 $this->value = $value;
36 }
37
38 public function dump() {
39 if ( $this->value instanceof MessageValue ) {
40 $contents = $this->value->dump();
41 } else {
42 $contents = htmlspecialchars( $this->value );
43 }
44 return "<{$this->type}>" . $contents . "</{$this->type}>";
45 }
46}
Value object representing a message parameter that consists of a list of values.
Value object representing a message for i18n.
const LIST
A list of values.
Definition ParamType.php:48
Value object representing a message parameter holding a single value.
__construct( $type, $value)
Construct a text parameter.
dump()
Dump the object for testing/debugging.