1 | <?php |
||
33 | class SerializerFactory { |
||
34 | |||
35 | const OPTION_DEFAULT = 0; |
||
36 | /** @since 1.2.0 */ |
||
37 | const OPTION_OBJECTS_FOR_MAPS = 1; |
||
38 | /** @since 1.7.0 */ |
||
39 | const OPTION_SERIALIZE_MAIN_SNAKS_WITHOUT_HASH = 2; |
||
40 | const OPTION_SERIALIZE_QUALIFIER_SNAKS_WITHOUT_HASH = 4; |
||
41 | const OPTION_SERIALIZE_REFERENCE_SNAKS_WITHOUT_HASH = 8; |
||
42 | |||
43 | /** |
||
44 | * @var int |
||
45 | */ |
||
46 | private $options; |
||
47 | |||
48 | /** |
||
49 | * @var Serializer |
||
50 | */ |
||
51 | private $dataValueSerializer; |
||
52 | |||
53 | /** |
||
54 | * @param Serializer $dataValueSerializer serializer for DataValue objects |
||
55 | * @param int $options set multiple with bitwise or |
||
56 | * |
||
57 | * @throws InvalidArgumentException |
||
58 | */ |
||
59 | public function __construct( Serializer $dataValueSerializer, $options = 0 ) { |
||
60 | if ( !is_int( $options ) ) { |
||
61 | throw new InvalidArgumentException( '$options must be an integer' ); |
||
62 | } |
||
63 | |||
64 | $this->dataValueSerializer = $dataValueSerializer; |
||
65 | $this->options = $options; |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * @return bool |
||
70 | */ |
||
71 | private function shouldUseObjectsForMaps() { |
||
72 | return (bool)( $this->options & self::OPTION_OBJECTS_FOR_MAPS ); |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * @return bool |
||
77 | */ |
||
78 | private function shouldSerializeMainSnaksWithHash() { |
||
81 | |||
82 | /** |
||
83 | * @return bool |
||
84 | */ |
||
85 | private function shouldSerializeQualifierSnaksWithHash() { |
||
88 | |||
89 | /** |
||
90 | * @return bool |
||
91 | */ |
||
92 | private function shouldSerializeReferenceSnaksWithHash() { |
||
95 | |||
96 | /** |
||
97 | * Returns a Serializer that can serialize Entity objects. |
||
98 | * |
||
99 | * @deprecated since 2.1, dispatching should happen when all entity types are known |
||
100 | * |
||
101 | * @return Serializer |
||
102 | */ |
||
103 | public function newEntitySerializer() { |
||
109 | |||
110 | /** |
||
111 | * Returns a Serializer that can serialize Item objects. |
||
112 | * |
||
113 | * @since 2.1 |
||
114 | * |
||
115 | * @return Serializer |
||
116 | */ |
||
117 | public function newItemSerializer() { |
||
126 | |||
127 | /** |
||
128 | * Returns a Serializer that can serialize Property objects. |
||
129 | * |
||
130 | * @since 2.1 |
||
131 | * |
||
132 | * @return Serializer |
||
133 | */ |
||
134 | public function newPropertySerializer() { |
||
141 | |||
142 | /** |
||
143 | * Returns a Serializer that can serialize SiteLink objects. |
||
144 | * |
||
145 | * @return Serializer |
||
146 | */ |
||
147 | public function newSiteLinkSerializer() { |
||
150 | |||
151 | /** |
||
152 | * Returns a Serializer that can serialize StatementList objects. |
||
153 | * |
||
154 | * @since 1.4 |
||
155 | * |
||
156 | * @return Serializer |
||
157 | */ |
||
158 | public function newStatementListSerializer() { |
||
164 | |||
165 | /** |
||
166 | * Returns a Serializer that can serialize Statement objects. |
||
167 | * |
||
168 | * @since 1.4 |
||
169 | * |
||
170 | * @return Serializer |
||
171 | */ |
||
172 | public function newStatementSerializer() { |
||
179 | |||
180 | /** |
||
181 | * Returns a Serializer that can serialize ReferenceList objects. |
||
182 | * |
||
183 | * @return Serializer |
||
184 | */ |
||
185 | public function newReferencesSerializer() { |
||
188 | |||
189 | /** |
||
190 | * Returns a Serializer that can serialize Reference objects. |
||
191 | * |
||
192 | * @return Serializer |
||
193 | */ |
||
194 | public function newReferenceSerializer() { |
||
201 | |||
202 | /** |
||
203 | * Returns a Serializer that can serialize SnakList objects. |
||
204 | * |
||
205 | * @param bool $serializeSnaksWithHash |
||
206 | * |
||
207 | * @since 1.4 |
||
208 | * |
||
209 | * @return Serializer |
||
210 | */ |
||
211 | public function newSnakListSerializer( $serializeSnaksWithHash = true ) { |
||
217 | |||
218 | /** |
||
219 | * Returns a Serializer that can serialize Snak objects. |
||
220 | * |
||
221 | * @param bool $serializeWithHash |
||
222 | * |
||
223 | * @return Serializer |
||
224 | */ |
||
225 | public function newSnakSerializer( $serializeWithHash = true ) { |
||
231 | |||
232 | /** |
||
233 | * Returns a Serializer that can serialize TypedSnak objects. |
||
234 | * |
||
235 | * @param bool $serializeWithHash |
||
236 | * |
||
237 | * @since 1.3 |
||
238 | * |
||
239 | * @return Serializer |
||
240 | */ |
||
241 | public function newTypedSnakSerializer( $serializeWithHash = true ) { |
||
244 | |||
245 | /** |
||
246 | * Returns a Serializer that can serialize Term objects. |
||
247 | * |
||
248 | * @since 1.5 |
||
249 | * |
||
250 | * @return Serializer |
||
251 | */ |
||
252 | public function newTermSerializer() { |
||
255 | |||
256 | /** |
||
257 | * Returns a Serializer that can serialize TermList objects. |
||
258 | * |
||
259 | * @since 1.5 |
||
260 | * |
||
261 | * @return Serializer |
||
262 | */ |
||
263 | public function newTermListSerializer() { |
||
266 | |||
267 | /** |
||
268 | * Returns a Serializer that can serialize AliasGroup objects. |
||
269 | * |
||
270 | * @since 1.6 |
||
271 | * |
||
272 | * @return Serializer |
||
273 | */ |
||
274 | public function newAliasGroupSerializer() { |
||
277 | |||
278 | /** |
||
279 | * Returns a Serializer that can serialize AliasGroupList objects. |
||
280 | * |
||
281 | * @since 1.5 |
||
282 | * |
||
283 | * @return Serializer |
||
284 | */ |
||
285 | public function newAliasGroupListSerializer() { |
||
288 | |||
289 | } |
||
290 |