1 | <?php |
||
13 | class MonolingualTextValue extends DataValueObject { |
||
14 | |||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | private $languageCode; |
||
19 | |||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | private $text; |
||
24 | |||
25 | /** |
||
26 | * @since 0.1 |
||
27 | * |
||
28 | * @param string $languageCode |
||
29 | * @param string $text |
||
30 | * |
||
31 | * @throws IllegalValueException |
||
32 | */ |
||
33 | 20 | public function __construct( $languageCode, $text ) { |
|
34 | 20 | if ( !is_string( $languageCode ) || $languageCode === '' ) { |
|
35 | 6 | throw new IllegalValueException( '$languageCode must be a non-empty string' ); |
|
36 | } |
||
37 | 14 | if ( !is_string( $text ) ) { |
|
38 | 4 | throw new IllegalValueException( '$text must be a string' ); |
|
39 | } |
||
40 | |||
41 | 10 | $this->languageCode = $languageCode; |
|
42 | 10 | $this->text = $text; |
|
43 | 10 | } |
|
44 | |||
45 | /** |
||
46 | * @see Serializable::serialize |
||
47 | * |
||
48 | * @return string |
||
49 | */ |
||
50 | 6 | public function serialize() { |
|
53 | |||
54 | /** |
||
55 | * @see Serializable::unserialize |
||
56 | * |
||
57 | * @param string $value |
||
58 | */ |
||
59 | 6 | public function unserialize( $value ) { |
|
63 | |||
64 | /** |
||
65 | * @see DataValue::getType |
||
66 | * |
||
67 | * @return string |
||
68 | */ |
||
69 | 4 | public static function getType() { |
|
72 | |||
73 | /** |
||
74 | * @see DataValue::getSortKey |
||
75 | * |
||
76 | * @return string |
||
77 | */ |
||
78 | 1 | public function getSortKey() { |
|
79 | // TODO: we might want to re-think this key. Perhaps the language should simply be omitted. |
||
80 | 1 | return $this->languageCode . $this->text; |
|
81 | } |
||
82 | |||
83 | /** |
||
84 | * @see DataValue::getValue |
||
85 | * |
||
86 | * @return self |
||
87 | */ |
||
88 | 2 | public function getValue() { |
|
91 | |||
92 | /** |
||
93 | * @since 0.1 |
||
94 | * |
||
95 | * @return string |
||
96 | */ |
||
97 | 2 | public function getText() { |
|
100 | |||
101 | /** |
||
102 | * @since 0.1 |
||
103 | * |
||
104 | * @return string |
||
105 | */ |
||
106 | 2 | public function getLanguageCode() { |
|
109 | |||
110 | /** |
||
111 | * @see DataValue::getArrayValue |
||
112 | * |
||
113 | * @return string[] |
||
114 | */ |
||
115 | 5 | public function getArrayValue() { |
|
121 | |||
122 | /** |
||
123 | * Constructs a new instance of the DataValue from the provided data. |
||
124 | * This can round-trip with @see getArrayValue |
||
125 | * |
||
126 | * @since 0.1 |
||
127 | * |
||
128 | * @param string[] $data |
||
129 | * |
||
130 | * @return static |
||
131 | * @throws IllegalValueException |
||
132 | */ |
||
133 | 7 | public static function newFromArray( array $data ) { |
|
138 | |||
139 | } |
||
140 |