MediaWiki master
Wikimedia\Message\MessageValue Class Reference

Value object representing a message for i18n. More...

Inherits Wikimedia\Message\MessageSpecifier, and JsonCodecable.

Inherited by Wikimedia\Message\DataMessageValue.

Collaboration diagram for Wikimedia\Message\MessageValue:

Public Member Functions

 __construct (string $key, array $params=[])
 bitrateParams (... $values)
 Chainable mutator which adds parameters which are a number of bits per second (ParamType::BITRATE).
 commaListParams (... $values)
 Chainable mutator which adds comma lists (ListType::COMMA).
 dateParams (... $values)
 Chainable mutator which adds parameters which are a date timestamp (ParamType::DATE).
 dateTimeParams (... $values)
 Chainable mutator which adds parameters which are a date-time timestamp (ParamType::DATETIME).
 dump ()
 Dump the object for testing/debugging.
 expiryParams (... $values)
 Chainable mutator which adds parameters which are an expiry timestamp (ParamType::EXPIRY).
 getKey ()
 Get the message key.
 getParams ()
 Get the parameter array.
 isSameAs (MessageValue $mv)
 listParamsOfType (string|ListType $listType,... $values)
 Chainable mutator which adds list parameters with a common type.
 longDurationParams (... $values)
 Chainable mutator which adds parameters which are a duration specified in seconds (ParamType::DURATION_LONG).
 numParams (... $values)
 Chainable mutator which adds numeric parameters (ParamType::NUM).
 params (... $values)
 Chainable mutator which adds text parameters and MessageParam parameters.
 pipeListParams (... $values)
 Chainable mutator which adds pipe lists (ListType::PIPE).
 plaintextParams (... $values)
 Chainable mutator which adds plaintext parameters (ParamType::PLAINTEXT).
 rawParams (... $values)
 Chainable mutator which adds "raw" parameters (ParamType::RAW).
 semicolonListParams (... $values)
 Chainable mutator which adds semicolon lists (ListType::SEMICOLON).
 shortDurationParams (... $values)
 Chainable mutator which adds parameters which are a duration specified in seconds (ParamType::DURATION_SHORT).
 sizeParams (... $values)
 Chainable mutator which adds parameters which are a number of bytes (ParamType::SIZE).
 textListParams (... $values)
 Chainable mutator which adds natural-language lists (ListType::AND).
 textParams (... $values)
 Chainable mutator which adds parameters of type text (ParamType::TEXT).
 textParamsOfType (string|ParamType $type,... $values)
 Chainable mutator which adds text parameters with a common type.
 timeParams (... $values)
 Chainable mutator which adds parameters which are a time timestamp (ParamType::TIME).
 toJsonArray ()
 userGroupParams (... $values)
 Chainable mutator which adds parameters which are a user group (ParamType::GROUP).

Static Public Member Functions

static hint ()
 If you are serializing a MessageValue (or a DataMessageValue), use this JsonCodec hint to suppress unnecessary type information.
static jsonClassHintFor (string $keyName)
static new (string $key, array $params=[])
 Static constructor for easier chaining of ->params() methods.
static newFromJsonArray (array $json)
static newFromSpecifier (MessageSpecifier $spec)
 Convert from any MessageSpecifier to a MessageValue.

Detailed Description

Value object representing a message for i18n.

A MessageValue holds a key and an array of parameters. It can be converted to a string in a particular language using formatters obtained from an IMessageFormatterFactory.

MessageValues are pure value objects and are newable and (de)serializable.

Stability: newable

Definition at line 21 of file MessageValue.php.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\Message\MessageValue::__construct ( string $key,
array $params = [] )
Stability: stable
to call
Parameters
string$key
(MessageParam|MessageSpecifier|string|int|float)[]$params Values that are not instances of MessageParam are wrapped using ParamType::TEXT.

Definition at line 36 of file MessageValue.php.

References params().

Member Function Documentation

◆ bitrateParams()

Wikimedia\Message\MessageValue::bitrateParams ( ...)

Chainable mutator which adds parameters which are a number of bits per second (ParamType::BITRATE).

Parameters
int|float...$values
Returns
$this

Definition at line 258 of file MessageValue.php.

References return, and textParamsOfType().

◆ commaListParams()

Wikimedia\Message\MessageValue::commaListParams ( ...)

Chainable mutator which adds comma lists (ListType::COMMA).

The list parameters thus created are formatted as a comma-separated list, or some local equivalent.

Parameters
(MessageParam|MessageSpecifier|string|int|float)[]...$values Each value is an array of items suitable to pass as $params to ListParam::__construct()
Returns
$this

Definition at line 300 of file MessageValue.php.

References listParamsOfType(), and return.

◆ dateParams()

Wikimedia\Message\MessageValue::dateParams ( ...)

Chainable mutator which adds parameters which are a date timestamp (ParamType::DATE).

Since
1.36
Parameters
string...$values Timestamp as accepted by the Wikimedia\Timestamp library.
Returns
$this

Definition at line 215 of file MessageValue.php.

References return, and textParamsOfType().

◆ dateTimeParams()

Wikimedia\Message\MessageValue::dateTimeParams ( ...)

Chainable mutator which adds parameters which are a date-time timestamp (ParamType::DATETIME).

Since
1.36
Parameters
string...$values Timestamp as accepted by the Wikimedia\Timestamp library.
Returns
$this

Definition at line 204 of file MessageValue.php.

References return, and textParamsOfType().

◆ dump()

Wikimedia\Message\MessageValue::dump ( )

Dump the object for testing/debugging.

Returns
string

Reimplemented in Wikimedia\Message\DataMessageValue.

Definition at line 351 of file MessageValue.php.

References params().

◆ expiryParams()

Wikimedia\Message\MessageValue::expiryParams ( ...)

Chainable mutator which adds parameters which are an expiry timestamp (ParamType::EXPIRY).

Parameters
string...$values Timestamp as accepted by the Wikimedia\Timestamp library, or "infinity"
Returns
$this

Definition at line 193 of file MessageValue.php.

References return, and textParamsOfType().

◆ getKey()

Wikimedia\Message\MessageValue::getKey ( )

Get the message key.

Implements Wikimedia\Message\MessageSpecifier.

Definition at line 71 of file MessageValue.php.

References return.

Referenced by MediaWiki\Api\Validator\ApiParamValidatorCallbacks\recordCondition().

◆ getParams()

Wikimedia\Message\MessageValue::getParams ( )

Get the parameter array.

Returns
MessageParam[]

Implements Wikimedia\Message\MessageSpecifier.

Definition at line 80 of file MessageValue.php.

References params(), and return.

Referenced by Wikimedia\Message\DataMessageValue\dump(), and MediaWiki\Api\Validator\ApiParamValidatorCallbacks\recordCondition().

◆ hint()

Wikimedia\Message\MessageValue::hint ( )
static

If you are serializing a MessageValue (or a DataMessageValue), use this JsonCodec hint to suppress unnecessary type information.

Definition at line 416 of file MessageValue.php.

References return.

Referenced by Wikimedia\Message\ScalarParam\jsonClassHintFor().

◆ isSameAs()

Wikimedia\Message\MessageValue::isSameAs ( MessageValue $mv)

Reimplemented in Wikimedia\Message\DataMessageValue.

Definition at line 360 of file MessageValue.php.

References isSameAs(), params(), and return.

Referenced by isSameAs().

◆ jsonClassHintFor()

Wikimedia\Message\MessageValue::jsonClassHintFor ( string $keyName)
static

Reimplemented in Wikimedia\Message\DataMessageValue.

Definition at line 389 of file MessageValue.php.

◆ listParamsOfType()

Wikimedia\Message\MessageValue::listParamsOfType ( string|ListType $listType,
... )

Chainable mutator which adds list parameters with a common type.

Parameters
string | ListType$listTypeOne of the ListType constants
(MessageParam|MessageSpecifier|string|int|float)[]...$values Each value is an array of items suitable to pass as $params to ListParam::__construct()
Returns
$this

Definition at line 127 of file MessageValue.php.

References if, and wfDeprecated().

Referenced by commaListParams(), pipeListParams(), semicolonListParams(), and textListParams().

◆ longDurationParams()

Wikimedia\Message\MessageValue::longDurationParams ( ...)

Chainable mutator which adds parameters which are a duration specified in seconds (ParamType::DURATION_LONG).

This is similar to shorDurationParams() except that the result will be more verbose.

Parameters
int|float...$values
Returns
$this

Definition at line 168 of file MessageValue.php.

References return, and textParamsOfType().

◆ new()

Wikimedia\Message\MessageValue::new ( string $key,
array $params = [] )
static

Static constructor for easier chaining of ->params() methods.

Parameters
string$key
(MessageParam|MessageSpecifier|string|int|float)[]$params
Returns
MessageValue

Definition at line 48 of file MessageValue.php.

References new(), and return.

Referenced by new().

◆ newFromJsonArray()

Wikimedia\Message\MessageValue::newFromJsonArray ( array $json)
static

◆ newFromSpecifier()

Wikimedia\Message\MessageValue::newFromSpecifier ( MessageSpecifier $spec)
static

Convert from any MessageSpecifier to a MessageValue.

When the given object is an instance of MessageValue, the same object is returned.

Since
1.43
Parameters
MessageSpecifier$spec
Returns
MessageValue

Definition at line 61 of file MessageValue.php.

References if.

Referenced by Wikimedia\Message\ScalarParam\__construct(), and StatusValue\toJsonArray().

◆ numParams()

Wikimedia\Message\MessageValue::numParams ( ...)

Chainable mutator which adds numeric parameters (ParamType::NUM).

Parameters
int|float...$values
Returns
$this

Definition at line 154 of file MessageValue.php.

References return, and textParamsOfType().

◆ params()

Wikimedia\Message\MessageValue::params ( ...)

Chainable mutator which adds text parameters and MessageParam parameters.

Parameters
MessageParam|MessageSpecifier|string|int|float...$values
Returns
$this

Definition at line 90 of file MessageValue.php.

References params().

Referenced by __construct(), dump(), getParams(), isSameAs(), params(), and toJsonArray().

◆ pipeListParams()

Wikimedia\Message\MessageValue::pipeListParams ( ...)

Chainable mutator which adds pipe lists (ListType::PIPE).

The list parameters thus created are formatted as a pipe ("|") -separated list, or some local equivalent.

Parameters
(MessageParam|MessageSpecifier|string|int|float)[]...$values Each value is an array of items suitable to pass as $params to ListParam::__construct()
Returns
$this

Definition at line 328 of file MessageValue.php.

References listParamsOfType(), and return.

◆ plaintextParams()

Wikimedia\Message\MessageValue::plaintextParams ( ...)

Chainable mutator which adds plaintext parameters (ParamType::PLAINTEXT).

Plaintext parameters are substituted after formatter processing. The value will be escaped by the formatter as appropriate for the target output format so as to be represented as plain text rather than as any sort of markup.

Parameters
string...$values
Returns
$this

Definition at line 286 of file MessageValue.php.

References return, and textParamsOfType().

◆ rawParams()

Wikimedia\Message\MessageValue::rawParams ( ...)

Chainable mutator which adds "raw" parameters (ParamType::RAW).

Raw parameters are substituted after formatter processing. The caller is responsible for ensuring that the value will be safe for the intended output format, and documenting what that intended output format is.

Parameters
string...$values
Returns
$this

Definition at line 272 of file MessageValue.php.

References return, and textParamsOfType().

◆ semicolonListParams()

Wikimedia\Message\MessageValue::semicolonListParams ( ...)

Chainable mutator which adds semicolon lists (ListType::SEMICOLON).

The list parameters thus created are formatted as a semicolon-separated list, or some local equivalent.

Parameters
(MessageParam|MessageSpecifier|string|int|float)[]...$values Each value is an array of items suitable to pass as $params to ListParam::__construct()
Returns
$this

Definition at line 314 of file MessageValue.php.

References listParamsOfType(), and return.

◆ shortDurationParams()

Wikimedia\Message\MessageValue::shortDurationParams ( ...)

Chainable mutator which adds parameters which are a duration specified in seconds (ParamType::DURATION_SHORT).

This is similar to longDurationParams() except that the result will be more compact.

Parameters
int|float...$values
Returns
$this

Definition at line 182 of file MessageValue.php.

References return, and textParamsOfType().

◆ sizeParams()

Wikimedia\Message\MessageValue::sizeParams ( ...)

Chainable mutator which adds parameters which are a number of bytes (ParamType::SIZE).

Parameters
int...$values
Returns
$this

Definition at line 247 of file MessageValue.php.

References return, and textParamsOfType().

◆ textListParams()

Wikimedia\Message\MessageValue::textListParams ( ...)

Chainable mutator which adds natural-language lists (ListType::AND).

The list parameters thus created, when formatted, are joined as in natural language. In English, this means a comma-separated list, with the last two elements joined with "and".

Parameters
(MessageParam|string)[]...$values
Returns
$this

Definition at line 342 of file MessageValue.php.

References listParamsOfType(), and return.

◆ textParams()

Wikimedia\Message\MessageValue::textParams ( ...)

Chainable mutator which adds parameters of type text (ParamType::TEXT).

Parameters
MessageSpecifier|string|int|float...$values
Returns
$this

Definition at line 144 of file MessageValue.php.

References return, and textParamsOfType().

◆ textParamsOfType()

Wikimedia\Message\MessageValue::textParamsOfType ( string|ParamType $type,
... )

Chainable mutator which adds text parameters with a common type.

Parameters
string | ParamType$typeOne of the ParamType constants
MessageSpecifier|string|int|float...$values Scalar values
Returns
$this

Definition at line 108 of file MessageValue.php.

References if, and wfDeprecated().

Referenced by bitrateParams(), dateParams(), dateTimeParams(), expiryParams(), longDurationParams(), numParams(), plaintextParams(), rawParams(), shortDurationParams(), sizeParams(), textParams(), timeParams(), and userGroupParams().

◆ timeParams()

Wikimedia\Message\MessageValue::timeParams ( ...)

Chainable mutator which adds parameters which are a time timestamp (ParamType::TIME).

Since
1.36
Parameters
string...$values Timestamp as accepted by the Wikimedia\Timestamp library.
Returns
$this

Definition at line 226 of file MessageValue.php.

References return, and textParamsOfType().

◆ toJsonArray()

Wikimedia\Message\MessageValue::toJsonArray ( )

Reimplemented in Wikimedia\Message\DataMessageValue.

Definition at line 369 of file MessageValue.php.

References params(), and return.

◆ userGroupParams()

Wikimedia\Message\MessageValue::userGroupParams ( ...)

Chainable mutator which adds parameters which are a user group (ParamType::GROUP).

Since
1.38
Parameters
string...$values User Groups
Returns
$this

Definition at line 237 of file MessageValue.php.

References return, and textParamsOfType().


The documentation for this class was generated from the following file: