1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Wikibase\DataModel\Statement; |
4
|
|
|
|
5
|
|
|
use InvalidArgumentException; |
6
|
|
|
use Wikibase\DataModel\Entity\EntityId; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Immutable value object for a statement id. A statement id consists of the entity id serialization |
10
|
|
|
* of the entity it belongs to (e.g. "Q1") and a randomly generated global unique identifier (GUID), |
11
|
|
|
* separated by a dollar sign. |
12
|
|
|
* |
13
|
|
|
* @since 3.0 |
14
|
|
|
* |
15
|
|
|
* @license GPL-2.0-or-later |
16
|
|
|
* @author Addshore |
17
|
|
|
*/ |
18
|
|
|
class StatementGuid { |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* The separator for the prefix and suffix of the GUID. |
22
|
|
|
*/ |
23
|
|
|
public const SEPARATOR = '$'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var EntityId |
27
|
|
|
*/ |
28
|
|
|
private $entityId; |
29
|
|
|
|
30
|
|
|
/** |
31
|
11 |
|
* @var string |
32
|
11 |
|
*/ |
33
|
5 |
|
private $guidPart; |
34
|
|
|
|
35
|
6 |
|
/** |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
private $serialization; |
39
|
6 |
|
|
40
|
6 |
|
/** |
41
|
6 |
|
* @param EntityId $entityId |
42
|
|
|
* @param string $guid |
43
|
|
|
* |
44
|
|
|
* @throws InvalidArgumentException |
45
|
|
|
*/ |
46
|
3 |
|
public function __construct( EntityId $entityId, $guid ) { |
47
|
3 |
|
if ( !is_string( $guid ) ) { |
48
|
|
|
throw new InvalidArgumentException( '$guid must be a string' ); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$this->serialization = $entityId->getSerialization() . self::SEPARATOR . $guid; |
52
|
|
|
$this->entityId = $entityId; |
53
|
3 |
|
$this->guidPart = $guid; |
54
|
3 |
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return EntityId |
58
|
|
|
*/ |
59
|
|
|
public function getEntityId() { |
60
|
|
|
return $this->entityId; |
61
|
|
|
} |
62
|
6 |
|
|
63
|
6 |
|
/** |
64
|
|
|
* @since 9.4 |
65
|
|
|
* |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
6 |
|
public function getGuidPart() { |
69
|
|
|
return $this->guidPart; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return string |
74
|
|
|
* @deprecated The value returned by this method might differ in case from the original, unparsed statement GUID |
75
|
|
|
* (the entity ID part might have been lowercase originally, but is always normalized in the return value here), |
76
|
|
|
* which means that the value should not be compared to other statement GUID serializations, |
77
|
|
|
* e.g. to look up a statement in a StatementList. |
78
|
|
|
*/ |
79
|
|
|
public function getSerialization() { |
80
|
|
|
return $this->serialization; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param mixed $target |
85
|
|
|
* |
86
|
|
|
* @return bool |
87
|
|
|
*/ |
88
|
|
|
public function equals( $target ) { |
89
|
|
|
if ( $this === $target ) { |
90
|
|
|
return true; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
return $target instanceof self |
94
|
|
|
&& $target->serialization === $this->serialization; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function __toString() { |
98
|
|
|
return $this->serialization; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
} |
102
|
|
|
|