1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
4
|
|
|
|
5
|
|
|
namespace DataValues; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class representing a value of unknown type. |
9
|
|
|
* This is in essence a null-wrapper, useful for instance for null-parsers. |
10
|
|
|
*/ |
11
|
|
|
class UnknownValue extends DataValueObject { |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @var mixed |
15
|
|
|
*/ |
16
|
|
|
private $value; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @param mixed $value |
20
|
|
|
*/ |
21
|
16 |
|
public function __construct( $value ) { |
22
|
16 |
|
$this->value = $value; |
23
|
16 |
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @see Serializable::serialize |
27
|
|
|
* |
28
|
|
|
* @return string |
29
|
|
|
*/ |
30
|
16 |
|
public function serialize() { |
31
|
16 |
|
return serialize( $this->value ); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @see Serializable::unserialize |
36
|
|
|
* |
37
|
|
|
* @param string $value |
38
|
|
|
*/ |
39
|
8 |
|
public function unserialize( $value ) { |
40
|
8 |
|
$this->__construct( unserialize( $value ) ); |
41
|
8 |
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @see DataValue::getType |
45
|
|
|
* |
46
|
|
|
* @return string |
47
|
|
|
*/ |
48
|
16 |
|
public static function getType() { |
49
|
16 |
|
return 'unknown'; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Returns the value. |
54
|
|
|
* @see DataValue::getValue |
55
|
|
|
* |
56
|
|
|
* @return mixed |
57
|
|
|
*/ |
58
|
32 |
|
public function getValue() { |
59
|
32 |
|
return $this->value; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param mixed $target |
64
|
|
|
* |
65
|
|
|
* @return bool |
66
|
|
|
*/ |
67
|
16 |
|
public function equals( $target ) { |
68
|
16 |
|
if ( $this === $target ) { |
69
|
8 |
|
return true; |
70
|
|
|
} |
71
|
|
|
|
72
|
16 |
|
return $target instanceof self |
73
|
16 |
|
&& $this->value === $target->value; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Constructs a new instance from the provided data. Required for {@see DataValueDeserializer}. |
78
|
|
|
* This is expected to round-trip with {@see getArrayValue}. |
79
|
|
|
* |
80
|
|
|
* @deprecated since 1.1. Static DataValue::newFromArray constructors like this are |
81
|
|
|
* underspecified (not in the DataValue interface), and misleadingly named (should be named |
82
|
|
|
* newFromArrayValue). Instead, use DataValue builder callbacks in {@see DataValueDeserializer}. |
83
|
|
|
* |
84
|
|
|
* @param mixed $data |
85
|
|
|
* |
86
|
|
|
* @return self |
87
|
|
|
*/ |
88
|
|
|
public static function newFromArray( $data ) { |
89
|
|
|
return new static( $data ); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
} |
93
|
|
|
|