|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Wikibase\DataModel\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use Comparable; |
|
6
|
|
|
use Serializable; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @since 0.5 |
|
10
|
|
|
* Constructor non-public since 1.0 |
|
11
|
|
|
* Abstract since 2.0 |
|
12
|
|
|
* |
|
13
|
|
|
* @license GPL-2.0+ |
|
14
|
|
|
* @author Jeroen De Dauw < [email protected] > |
|
15
|
|
|
*/ |
|
16
|
|
|
abstract class EntityId implements Comparable, Serializable { |
|
17
|
|
|
|
|
18
|
|
|
protected $serialization; |
|
19
|
|
|
protected $repositoryName; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @return string |
|
23
|
|
|
*/ |
|
24
|
|
|
public abstract function getEntityType(); |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @return string |
|
28
|
|
|
*/ |
|
29
|
|
|
public function getSerialization() { |
|
30
|
|
|
if ( $this->isForeign() ) { |
|
31
|
|
|
return $this->repositoryName . ':' . $this->serialization; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
return $this->serialization; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Returns the serialization without the first repository prefix. |
|
39
|
|
|
* |
|
40
|
|
|
* @return string |
|
41
|
|
|
*/ |
|
42
|
|
|
public function getLocalPart() { |
|
43
|
|
|
return $this->serialization; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Returns '' for local IDs and the foreign repository name for foreign IDs. For chained IDs (e.g. foo:bar:Q42) it |
|
48
|
|
|
* will return only the first part. |
|
49
|
|
|
* |
|
50
|
|
|
* @return string |
|
51
|
|
|
*/ |
|
52
|
|
|
public function getRepoName() { |
|
53
|
|
|
return $this->repositoryName; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @return bool |
|
58
|
|
|
*/ |
|
59
|
|
|
public function isForeign() { |
|
60
|
|
|
return $this->repositoryName !== ''; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* This is a human readable representation of the EntityId. |
|
65
|
|
|
* This format is allowed to change and should therefore not |
|
66
|
|
|
* be relied upon to be stable. |
|
67
|
|
|
* |
|
68
|
|
|
* @return string |
|
69
|
|
|
*/ |
|
70
|
|
|
public function __toString() { |
|
71
|
|
|
return $this->getSerialization(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @see Comparable::equals |
|
76
|
|
|
* |
|
77
|
|
|
* @since 0.5 |
|
78
|
|
|
* |
|
79
|
|
|
* @param mixed $target |
|
80
|
|
|
* |
|
81
|
|
|
* @return bool |
|
82
|
|
|
*/ |
|
83
|
|
|
public function equals( $target ) { |
|
84
|
|
|
if ( $this === $target ) { |
|
85
|
|
|
return true; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
return $target instanceof self |
|
89
|
|
|
&& $target->serialization === $this->serialization |
|
90
|
|
|
&& $target->repositoryName === $this->repositoryName; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
} |
|
94
|
|
|
|