1 | <?php |
||
15 | abstract class EntityId implements Comparable, Serializable { |
||
16 | |||
17 | protected $serialization; |
||
18 | |||
19 | /** |
||
20 | * @since 7.3 |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $repositoryName; |
||
25 | |||
26 | /** |
||
27 | * @since 7.3 |
||
28 | 31 | * |
|
29 | 31 | * @var string |
|
30 | */ |
||
31 | protected $localPart; |
||
32 | |||
33 | const PATTERN = '/^:?(\w+:)*[^:]+\z/'; |
||
34 | |||
35 | /** |
||
36 | * @since 6.2 |
||
37 | * |
||
38 | * @param string $serialization |
||
39 | 5 | * |
|
40 | 5 | * @throws InvalidArgumentException |
|
41 | */ |
||
42 | public function __construct( $serialization ) { |
||
48 | |||
49 | private static function assertValidSerialization( $serialization ) { |
||
62 | |||
63 | /** |
||
64 | * @return string |
||
65 | */ |
||
66 | public abstract function getEntityType(); |
||
67 | |||
68 | /** |
||
69 | * @return string |
||
70 | */ |
||
71 | public function getSerialization() { |
||
74 | |||
75 | /** |
||
76 | * Returns an array with 3 elements: the foreign repository name as the first element, the local ID as the last |
||
77 | * element and everything that is in between as the second element. |
||
78 | * |
||
79 | * EntityId::joinSerialization can be used to restore the original serialization from the parts returned. |
||
80 | * |
||
81 | * @since 6.2 |
||
82 | * |
||
83 | * @param string $serialization |
||
84 | * |
||
85 | * @throws InvalidArgumentException |
||
86 | * @return string[] Array containing the serialization split into 3 parts. |
||
87 | */ |
||
88 | public static function splitSerialization( $serialization ) { |
||
93 | |||
94 | /** |
||
95 | * Splits the given ID serialization into an array with the following three elements: |
||
96 | * - the repository name as the first element (empty string for local repository) |
||
97 | * - any parts of the ID serialization but the repository name and the local ID (if any, empty string |
||
98 | * if nothing else present) |
||
99 | * - the local ID |
||
100 | * Note: this method does not perform any validation of the given input. Calling code should take |
||
101 | * care of this! |
||
102 | * |
||
103 | * @param string $serialization |
||
104 | * |
||
105 | * @return string[] |
||
106 | */ |
||
107 | private static function extractSerializationParts( $serialization ) { |
||
119 | |||
120 | /** |
||
121 | * Builds an ID serialization from the parts returned by EntityId::splitSerialization. |
||
122 | * |
||
123 | * @since 6.2 |
||
124 | * |
||
125 | * @param string[] $parts |
||
126 | * |
||
127 | * @throws InvalidArgumentException |
||
128 | * @return string |
||
129 | */ |
||
130 | public static function joinSerialization( array $parts ) { |
||
142 | |||
143 | /** |
||
144 | * Returns '' for local IDs and the foreign repository name for foreign IDs. For chained IDs (e.g. foo:bar:Q42) it |
||
145 | * will return only the first part. |
||
146 | * |
||
147 | * @since 6.2 |
||
148 | * |
||
149 | * @return string |
||
150 | */ |
||
151 | public function getRepositoryName() { |
||
154 | |||
155 | /** |
||
156 | * Returns the serialization without the first repository prefix. |
||
157 | * |
||
158 | * @since 6.2 |
||
159 | * |
||
160 | * @return string |
||
161 | */ |
||
162 | public function getLocalPart() { |
||
165 | |||
166 | /** |
||
167 | * Returns true iff EntityId::getRepoName returns a non-empty string. |
||
168 | * |
||
169 | * @since 6.2 |
||
170 | * |
||
171 | * @return bool |
||
172 | */ |
||
173 | public function isForeign() { |
||
177 | |||
178 | /** |
||
179 | * @param string $id |
||
180 | * |
||
181 | * @return string |
||
182 | */ |
||
183 | private static function normalizeIdSerialization( $id ) { |
||
186 | |||
187 | /** |
||
188 | * This is a human readable representation of the EntityId. |
||
189 | * This format is allowed to change and should therefore not |
||
190 | * be relied upon to be stable. |
||
191 | * |
||
192 | * @return string |
||
193 | */ |
||
194 | public function __toString() { |
||
197 | |||
198 | /** |
||
199 | * @see Comparable::equals |
||
200 | * |
||
201 | * @since 0.5 |
||
202 | * |
||
203 | * @param mixed $target |
||
204 | * |
||
205 | * @return bool |
||
206 | */ |
||
207 | public function equals( $target ) { |
||
215 | |||
216 | /** |
||
217 | * Returns a pair (repository name, local part of ID) from the given ID serialization. |
||
218 | * Note: this does not perform any validation of the given input. Calling code should take |
||
219 | * care of this! |
||
220 | * |
||
221 | * @since 7.3 |
||
222 | * |
||
223 | * @param string $serialization |
||
224 | * |
||
225 | * @return string[] Array of form [ string $repositoryName, string $localPart ] |
||
226 | */ |
||
227 | protected static function extractRepositoryNameAndLocalPart( $serialization ) { |
||
231 | |||
232 | } |
||
233 |