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 | * @return Serializer |
||
100 | */ |
||
101 | public function newEntitySerializer() { |
||
107 | |||
108 | /** |
||
109 | * Returns a Serializer that can serialize Item objects. |
||
110 | * |
||
111 | * @since 2.1 |
||
112 | * |
||
113 | * @return Serializer |
||
114 | */ |
||
115 | public function newItemSerializer() { |
||
124 | |||
125 | /** |
||
126 | * Returns a Serializer that can serialize Property objects. |
||
127 | * |
||
128 | * @since 2.1 |
||
129 | * |
||
130 | * @return Serializer |
||
131 | */ |
||
132 | public function newPropertySerializer() { |
||
139 | |||
140 | /** |
||
141 | * Returns a Serializer that can serialize SiteLink objects. |
||
142 | * |
||
143 | * @return Serializer |
||
144 | */ |
||
145 | public function newSiteLinkSerializer() { |
||
148 | |||
149 | /** |
||
150 | * Returns a Serializer that can serialize StatementList objects. |
||
151 | * |
||
152 | * @since 1.4 |
||
153 | * |
||
154 | * @return Serializer |
||
155 | */ |
||
156 | public function newStatementListSerializer() { |
||
162 | |||
163 | /** |
||
164 | * Returns a Serializer that can serialize Statement objects. |
||
165 | * |
||
166 | * @since 1.4 |
||
167 | * |
||
168 | * @return Serializer |
||
169 | */ |
||
170 | public function newStatementSerializer() { |
||
177 | |||
178 | /** |
||
179 | * Returns a Serializer that can serialize ReferenceList objects. |
||
180 | * |
||
181 | * @return Serializer |
||
182 | */ |
||
183 | public function newReferencesSerializer() { |
||
186 | |||
187 | /** |
||
188 | * Returns a Serializer that can serialize Reference objects. |
||
189 | * |
||
190 | * @return Serializer |
||
191 | */ |
||
192 | public function newReferenceSerializer() { |
||
199 | |||
200 | /** |
||
201 | * Returns a Serializer that can serialize SnakList objects. |
||
202 | * |
||
203 | * @param bool $serializeSnaksWithHash |
||
204 | * |
||
205 | * @since 1.4 |
||
206 | * |
||
207 | * @return Serializer |
||
208 | */ |
||
209 | public function newSnakListSerializer( $serializeSnaksWithHash = true ) { |
||
215 | |||
216 | /** |
||
217 | * Returns a Serializer that can serialize Snak objects. |
||
218 | * |
||
219 | * @param bool $serializeWithHash |
||
220 | * |
||
221 | * @return Serializer |
||
222 | */ |
||
223 | public function newSnakSerializer( $serializeWithHash = true ) { |
||
229 | |||
230 | /** |
||
231 | * Returns a Serializer that can serialize TypedSnak objects. |
||
232 | * |
||
233 | * @param bool $serializeWithHash |
||
234 | * |
||
235 | * @since 1.3 |
||
236 | * |
||
237 | * @return Serializer |
||
238 | */ |
||
239 | public function newTypedSnakSerializer( $serializeWithHash = true ) { |
||
242 | |||
243 | /** |
||
244 | * Returns a Serializer that can serialize Term objects. |
||
245 | * |
||
246 | * @since 1.5 |
||
247 | * |
||
248 | * @return Serializer |
||
249 | */ |
||
250 | public function newTermSerializer() { |
||
253 | |||
254 | /** |
||
255 | * Returns a Serializer that can serialize TermList objects. |
||
256 | * |
||
257 | * @since 1.5 |
||
258 | * |
||
259 | * @return Serializer |
||
260 | */ |
||
261 | public function newTermListSerializer() { |
||
264 | |||
265 | /** |
||
266 | * Returns a Serializer that can serialize AliasGroup objects. |
||
267 | * |
||
268 | * @since 1.6 |
||
269 | * |
||
270 | * @return Serializer |
||
271 | */ |
||
272 | public function newAliasGroupSerializer() { |
||
275 | |||
276 | /** |
||
277 | * Returns a Serializer that can serialize AliasGroupList objects. |
||
278 | * |
||
279 | * @since 1.5 |
||
280 | * |
||
281 | * @return Serializer |
||
282 | */ |
||
283 | public function newAliasGroupListSerializer() { |
||
286 | |||
287 | } |
||
288 |