MediaWiki  master
ScalarParam.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Wikimedia\Message;
4 
12 class ScalarParam extends MessageParam {
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 }
Wikimedia\Message\ScalarParam\__construct
__construct( $type, $value)
Construct a text parameter.
Definition: ScalarParam.php:21
Wikimedia\Message\MessageParam\$type
$type
Definition: MessageParam.php:11
Wikimedia\Message\ScalarParam
Value object representing a message parameter holding a single value.
Definition: ScalarParam.php:12
Wikimedia\Message\MessageValue
Value object representing a message for i18n.
Definition: MessageValue.php:16
Wikimedia\Message
Definition: DataMessageValue.php:3
Wikimedia\Message\ScalarParam\dump
dump()
Dump the object for testing/debugging.
Definition: ScalarParam.php:38
Wikimedia\Message\ParamType\LIST
const LIST
A list of values.
Definition: ParamType.php:48
Wikimedia\Message\MessageParam\$value
$value
Definition: MessageParam.php:12
Wikimedia\Message\MessageParam
Value object representing a message parameter that consists of a list of values.
Definition: MessageParam.php:10