MediaWiki  master
ScalarParam.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Wikimedia\Message;
4 
10 class ScalarParam extends MessageParam {
17  public function __construct( $type, $value ) {
18  if ( $type === ParamType::LIST ) {
19  throw new \InvalidArgumentException(
20  'ParamType::LIST cannot be used with ScalarParam; use ListParam instead'
21  );
22  }
23  if ( !is_string( $value ) && !is_numeric( $value ) && !$value instanceof MessageValue ) {
24  $type = is_object( $value ) ? get_class( $value ) : gettype( $value );
25  throw new \InvalidArgumentException(
26  "Scalar parameter must be a string, number, or MessageValue; got $type"
27  );
28  }
29 
30  $this->type = $type;
31  $this->value = $value;
32  }
33 
34  public function dump() {
35  if ( $this->value instanceof MessageValue ) {
36  $contents = $this->value->dump();
37  } else {
38  $contents = htmlspecialchars( $this->value );
39  }
40  return "<{$this->type}>" . $contents . "</{$this->type}>";
41  }
42 }
Wikimedia\Message\ScalarParam\__construct
__construct( $type, $value)
Construct a text parameter.
Definition: ScalarParam.php:17
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:10
Wikimedia\Message\MessageValue
Value object representing a message for i18n.
Definition: MessageValue.php:14
Wikimedia\Message
Definition: DataMessageValue.php:3
Wikimedia\Message\ScalarParam\dump
dump()
Dump the object for testing/debugging.
Definition: ScalarParam.php:34
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