Skip to content

Commit

Permalink
Merge options to use snak hashes into one (#233)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
lucaswerkmeister authored and manicki committed Aug 30, 2017
1 parent 747eee0 commit 4f558c9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
8 changes: 8 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Wikibase DataModel Serialization release notes

## 2.5.0 (dev)

* Deprecated `SerializerFactory` options
`OPTION_SERIALIZE_MAIN_SNAKS_WITHOUT_HASH`,
`OPTION_SERIALIZE_QUALIFIER_SNAKS_WITHOUT_HASH` and
`OPTION_SERIALIZE_REFERENCE_SNAKS_WITHOUT_HASH`,
and added `OPTION_SERIALIZE_SNAKS_WITHOUT_HASH` instead

## 2.4.0 (2017-03-16)

* Added compatibility with Wikibase DataModel 7.x
Expand Down
21 changes: 20 additions & 1 deletion src/SerializerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,29 @@ class SerializerFactory {
const OPTION_DEFAULT = 0;
/** @since 1.2.0 */
const OPTION_OBJECTS_FOR_MAPS = 1;
/** @since 1.7.0 */
/**
* @since 1.7.0
* @deprecated since 2.5 use OPTION_SERIALIZE_SNAKS_WITHOUT_HASH
*/
const OPTION_SERIALIZE_MAIN_SNAKS_WITHOUT_HASH = 2;
/**
* @since 1.7.0
* @deprecated since 2.5 use OPTION_SERIALIZE_SNAKS_WITHOUT_HASH
*/
const OPTION_SERIALIZE_QUALIFIER_SNAKS_WITHOUT_HASH = 4;
/**
* @since 1.7.0
* @deprecated since 2.5 use OPTION_SERIALIZE_SNAKS_WITHOUT_HASH
*/
const OPTION_SERIALIZE_REFERENCE_SNAKS_WITHOUT_HASH = 8;
/**
* Omit hashes when serializing snaks.
* @since 2.5.0
*/
const OPTION_SERIALIZE_SNAKS_WITHOUT_HASH = 14; /* =
self::OPTION_SERIALIZE_MAIN_SNAKS_WITHOUT_HASH |
self::OPTION_SERIALIZE_QUALIFIER_SNAKS_WITHOUT_HASH |
self::OPTION_SERIALIZE_REFERENCE_SNAKS_WITHOUT_HASH; */

/**
* @var int
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/SerializerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,15 @@ public function testNewAliasGroupListSerializer() {
);
}

public function testSerializeSnaksWithoutHashConstant() {
$this->assertSame(
// expected:
SerializerFactory::OPTION_SERIALIZE_MAIN_SNAKS_WITHOUT_HASH |
SerializerFactory::OPTION_SERIALIZE_QUALIFIER_SNAKS_WITHOUT_HASH |
SerializerFactory::OPTION_SERIALIZE_REFERENCE_SNAKS_WITHOUT_HASH,
// actual:
SerializerFactory::OPTION_SERIALIZE_SNAKS_WITHOUT_HASH
);
}

}

0 comments on commit 4f558c9

Please sign in to comment.