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