Skip to content

Commit 4f558c9

Browse files
lucaswerkmeistermanicki
authored andcommitted
Merge options to use snak hashes into one (#233)
* Merge options to use snak hashes into one Suppressing snak hashes was initially added as a single option in 6563985, but then split up into three options in 679774d, since the previous lib serializer included qualifier hashes but not main snak or reference hashes, and the goal was to migrate from that serializer to this one with absolutely no change in the output. Now that this migration is done, we can merge the three options into one again, since it’s hardly useful to have snak hashes for some snaks but not others: either include all hashes, or omit all of them. This is implemented as an extra constant, which is the bitwise union of the three existing ones, for backwards compatibility. With the next major release, the three old options should be removed and the single option made functional instead (with a single method shouldSerializeSnaksWithHash()). Since we still need to support PHP 5.5, the constant can’t be computed from the other constant. Instead, a test checks that it is the bitwise union of the other constants, as intended.
1 parent 747eee0 commit 4f558c9

3 files changed

Lines changed: 39 additions & 1 deletion

File tree

RELEASE-NOTES.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Wikibase DataModel Serialization release notes
22

3+
## 2.5.0 (dev)
4+
5+
* Deprecated `SerializerFactory` options
6+
`OPTION_SERIALIZE_MAIN_SNAKS_WITHOUT_HASH`,
7+
`OPTION_SERIALIZE_QUALIFIER_SNAKS_WITHOUT_HASH` and
8+
`OPTION_SERIALIZE_REFERENCE_SNAKS_WITHOUT_HASH`,
9+
and added `OPTION_SERIALIZE_SNAKS_WITHOUT_HASH` instead
10+
311
## 2.4.0 (2017-03-16)
412

513
* Added compatibility with Wikibase DataModel 7.x

src/SerializerFactory.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,29 @@ class SerializerFactory {
3535
const OPTION_DEFAULT = 0;
3636
/** @since 1.2.0 */
3737
const OPTION_OBJECTS_FOR_MAPS = 1;
38-
/** @since 1.7.0 */
38+
/**
39+
* @since 1.7.0
40+
* @deprecated since 2.5 use OPTION_SERIALIZE_SNAKS_WITHOUT_HASH
41+
*/
3942
const OPTION_SERIALIZE_MAIN_SNAKS_WITHOUT_HASH = 2;
43+
/**
44+
* @since 1.7.0
45+
* @deprecated since 2.5 use OPTION_SERIALIZE_SNAKS_WITHOUT_HASH
46+
*/
4047
const OPTION_SERIALIZE_QUALIFIER_SNAKS_WITHOUT_HASH = 4;
48+
/**
49+
* @since 1.7.0
50+
* @deprecated since 2.5 use OPTION_SERIALIZE_SNAKS_WITHOUT_HASH
51+
*/
4152
const OPTION_SERIALIZE_REFERENCE_SNAKS_WITHOUT_HASH = 8;
53+
/**
54+
* Omit hashes when serializing snaks.
55+
* @since 2.5.0
56+
*/
57+
const OPTION_SERIALIZE_SNAKS_WITHOUT_HASH = 14; /* =
58+
self::OPTION_SERIALIZE_MAIN_SNAKS_WITHOUT_HASH |
59+
self::OPTION_SERIALIZE_QUALIFIER_SNAKS_WITHOUT_HASH |
60+
self::OPTION_SERIALIZE_REFERENCE_SNAKS_WITHOUT_HASH; */
4261

4362
/**
4463
* @var int

tests/unit/SerializerFactoryTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,15 @@ public function testNewAliasGroupListSerializer() {
158158
);
159159
}
160160

161+
public function testSerializeSnaksWithoutHashConstant() {
162+
$this->assertSame(
163+
// expected:
164+
SerializerFactory::OPTION_SERIALIZE_MAIN_SNAKS_WITHOUT_HASH |
165+
SerializerFactory::OPTION_SERIALIZE_QUALIFIER_SNAKS_WITHOUT_HASH |
166+
SerializerFactory::OPTION_SERIALIZE_REFERENCE_SNAKS_WITHOUT_HASH,
167+
// actual:
168+
SerializerFactory::OPTION_SERIALIZE_SNAKS_WITHOUT_HASH
169+
);
170+
}
171+
161172
}

0 commit comments

Comments
 (0)