Debian Codegraph @

includes/libs/Message/MessageParam.php

raw symbols SCIP
1 <?php
2
3 namespace Wikimedia\Message;
4
5 use Wikimedia\JsonCodec\Hint;
6 use Wikimedia\JsonCodec\JsonCodecable;
7 use Wikimedia\JsonCodec\JsonCodecableTrait;
8
9 /**
10 * Value object representing a message parameter that consists of a list of values.
11 *
12 * Message parameter classes are pure value objects and are newable and (de)serializable.
13 */
14 abstract class MessageParam implements JsonCodecable {
15 use JsonCodecableTrait;
16
17 /** @var string */
18 protected $type;
19 /** @var mixed */
20 protected $value;
21
22 /**
23 * Get the type of the parameter.
24 *
25 * @return string One of the ParamType constants
26 */
27 public function getType() {
28 return $this->type;
29 }
30
31 /**
32 * Get the input value of the parameter
33 *
34 * @return mixed
35 */
36 public function getValue() {
37 return $this->value;
38 }
39
40 /**
41 * Dump the object for testing/debugging
42 *
43 * @return string
44 */
45 abstract public function dump();
46
47 /** @inheritDoc */
48 public static function jsonClassHintFor( string $keyName ) {
49 // Support Hint::INHERITED
50 if ( $keyName === ParamType::LIST ) {
51 return ListParam::jsonClassHintFor( $keyName );
52 }
53 return ScalarParam::jsonClassHintFor( $keyName );
54 }
55
56 /** @inheritDoc */
57 public static function newFromJsonArray( array $json ): MessageParam {
58 // WARNING: When changing how this class is serialized, follow the instructions
59 // at <https://www.mediawiki.org/wiki/Manual:Parser_cache/Serialization_compatibility>!
60 // Because of the use of Hint::INHERITED,
61 // MessageParam::newFromJsonArray() needs to know how to dispatch to
62 // an appropriate subclass constructor.
63 if ( isset( $json[ParamType::LIST] ) ) {
64 return ListParam::newFromJsonArray( $json );
65 }
66 return ScalarParam::newFromJsonArray( $json );
67 }
68
69 /**
70 * If you are serializing a MessageParam, use
71 * this JsonCodec hint to suppress unnecessary type information.
72 */
73 public static function hint(): Hint {
74 return Hint::build( self::class, Hint::INHERITED, Hint::ONLY_FOR_DECODE );
75 }
76 }