1 | <?php |
||
17 | abstract class EntityId implements Comparable, Serializable { |
||
18 | |||
19 | protected $serialization; |
||
20 | |||
21 | const PATTERN = '/^:?(\w+:)*[^:]+\z/'; |
||
22 | |||
23 | /** |
||
24 | * @since 6.2 |
||
25 | * |
||
26 | * @param string $serialization |
||
27 | */ |
||
28 | 31 | public function __construct( $serialization ) { |
|
32 | |||
33 | private static function assertValidSerialization( $serialization ) { |
||
46 | |||
47 | /** |
||
48 | * @return string |
||
49 | */ |
||
50 | public abstract function getEntityType(); |
||
51 | |||
52 | 5 | /** |
|
53 | 5 | * @return string |
|
54 | 5 | */ |
|
55 | public function getSerialization() { |
||
58 | 5 | ||
59 | /** |
||
60 | * Returns an array with 3 elements: the foreign repository name as the first element, the local ID as the last |
||
61 | * element and everything that is in between as the second element. |
||
62 | * |
||
63 | * EntityId::joinSerialization can be used to restore the original serialization from the parts returned. |
||
64 | * |
||
65 | * @since 6.2 |
||
66 | * |
||
67 | * @param string $serialization |
||
68 | * @return string[] Array containing the serialization split into 3 parts. |
||
69 | */ |
||
70 | public static function splitSerialization( $serialization ) { |
||
84 | |||
85 | /** |
||
86 | * Builds an ID serialization from the parts returned by EntityId::splitSerialization. |
||
87 | * |
||
88 | * @since 6.2 |
||
89 | * |
||
90 | * @param string[] $parts |
||
91 | * @return string |
||
92 | * |
||
93 | * @throws InvalidArgumentException |
||
94 | */ |
||
95 | public static function joinSerialization( array $parts ) { |
||
107 | |||
108 | /** |
||
109 | * Returns '' for local IDs and the foreign repository name for foreign IDs. For chained IDs (e.g. foo:bar:Q42) it |
||
110 | * will return only the first part. |
||
111 | * |
||
112 | * @since 6.2 |
||
113 | * |
||
114 | * @return string |
||
115 | */ |
||
116 | public function getRepositoryName() { |
||
121 | |||
122 | /** |
||
123 | * Returns the serialization without the first repository prefix. |
||
124 | * |
||
125 | * @since 6.2 |
||
126 | * |
||
127 | * @return string |
||
128 | */ |
||
129 | public function getLocalPart() { |
||
134 | |||
135 | /** |
||
136 | * Returns true iff EntityId::getRepoName returns a non-empty string. |
||
137 | * |
||
138 | * @since 6.2 |
||
139 | * |
||
140 | * @return bool |
||
141 | */ |
||
142 | public function isForeign() { |
||
146 | |||
147 | /** |
||
148 | * @param string $id |
||
149 | * @return string |
||
150 | */ |
||
151 | private static function normalizeIdSerialization( $id ) { |
||
154 | |||
155 | /** |
||
156 | * This is a human readable representation of the EntityId. |
||
157 | * This format is allowed to change and should therefore not |
||
158 | * be relied upon to be stable. |
||
159 | * |
||
160 | * @return string |
||
161 | */ |
||
162 | public function __toString() { |
||
165 | |||
166 | /** |
||
167 | * @see Comparable::equals |
||
168 | * |
||
169 | * @since 0.5 |
||
170 | * |
||
171 | * @param mixed $target |
||
172 | * |
||
173 | * @return bool |
||
174 | */ |
||
175 | public function equals( $target ) { |
||
183 | |||
184 | } |
||
185 |