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