Addshore has uploaded a new change for review. https://gerrit.wikimedia.org/r/227224
Change subject: Remove SerializationOptions ID_KEY_MODE ...................................................................... Remove SerializationOptions ID_KEY_MODE This was only used in one place and this one place used the default anyway... SO it has been removed and the default is now used everywhere... Change-Id: I39cccb54b2b7bb3227aadaf70fefe365a6e4fac1 --- M client/includes/DataAccess/Scribunto/EntityAccessor.php M lib/includes/serializers/ByPropertyListSerializer.php M lib/includes/serializers/SerializationOptions.php M lib/tests/phpunit/serializers/ByPropertyListSerializerTest.php M lib/tests/phpunit/serializers/SerializationOptionsTest.php 5 files changed, 2 insertions(+), 216 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/24/227224/1 diff --git a/client/includes/DataAccess/Scribunto/EntityAccessor.php b/client/includes/DataAccess/Scribunto/EntityAccessor.php index b4b6e29..d537056 100644 --- a/client/includes/DataAccess/Scribunto/EntityAccessor.php +++ b/client/includes/DataAccess/Scribunto/EntityAccessor.php @@ -181,8 +181,6 @@ // SerializationOptions accepts mixed types of keys happily. $options->setLanguages( $languages ); - $options->setIdKeyMode( SerializationOptions::ID_KEYS_UPPER ); - return $options; } diff --git a/lib/includes/serializers/ByPropertyListSerializer.php b/lib/includes/serializers/ByPropertyListSerializer.php index 1b585d3..aa10258 100644 --- a/lib/includes/serializers/ByPropertyListSerializer.php +++ b/lib/includes/serializers/ByPropertyListSerializer.php @@ -81,17 +81,8 @@ $serializedObjects['id'] = $propertyId->getSerialization(); $serialization[] = $serializedObjects; } else { - $key = $propertyId->getSerialization(); - - if ( $this->getOptions()->shouldUseUpperCaseIdsAsKeys() ) { - $key = strtoupper( $key ); - $serialization[$key] = $serializedObjects; - } - - if ( $this->getOptions()->shouldUseLowerCaseIdsAsKeys() ) { - $key = strtolower( $key ); - $serialization[$key] = $serializedObjects; - } + $key = strtoupper( $propertyId->getSerialization() ); + $serialization[$key] = $serializedObjects; } } diff --git a/lib/includes/serializers/SerializationOptions.php b/lib/includes/serializers/SerializationOptions.php index 24383c0..43841f6 100644 --- a/lib/includes/serializers/SerializationOptions.php +++ b/lib/includes/serializers/SerializationOptions.php @@ -21,18 +21,6 @@ /** * @since 0.5 - * @const key for the entityIdKeyMode option, a bit field determining whether to use - * upper case entities IDs as keys in the serialized structure, or lower case - * IDs, or both. - */ - const OPT_ID_KEY_MODE = 'entityIdKeyMode'; - - const ID_KEYS_UPPER = 1; - const ID_KEYS_LOWER = 2; - const ID_KEYS_BOTH = 3; - - /** - * @since 0.5 * @const key for the indexTags option, a boolean indicating whether associative or indexed * arrays should be used for output. This allows indexed mode to be forced for used * with ApiResults in XML model. @@ -82,7 +70,6 @@ public function __construct( array $options = array() ) { $this->setOptions( $options ); - $this->initOption( self::OPT_ID_KEY_MODE, self::ID_KEYS_UPPER ); $this->initOption( self::OPT_INDEX_TAGS, false ); $this->initOption( self::OPT_GROUP_BY_PROPERTIES, array( 'claims', 'qualifiers', 'references' ) ); $this->initOption( self::OPT_SERIALIZE_SNAKS_WITH_HASH, false ); @@ -287,62 +274,6 @@ */ public function shouldIndexTags() { return $this->getOption( self::OPT_INDEX_TAGS ); - } - - /** - * Returns whether lower case entities IDs should be used as keys in the serialized data structure. - * - * @see setIdKeyMode() - * - * @since 0.5 - * - * @return boolean - */ - public function shouldUseLowerCaseIdsAsKeys() { - $idKeyMode = $this->getOption( self::OPT_ID_KEY_MODE ); - return ( $idKeyMode & self::ID_KEYS_LOWER ) > 0; - } - - /** - * Returns whether upper case entities IDs should be used as keys in the serialized data structure. - * - * @see setIdKeyMode() - * - * @since 0.5 - * - * @return boolean - */ - public function shouldUseUpperCaseIdsAsKeys() { - $idKeyMode = $this->getOption( self::OPT_ID_KEY_MODE ); - return ( $idKeyMode & self::ID_KEYS_UPPER ) > 0; - } - - /** - * Sets whether upper case entities IDs should be used as keys in the serialized data structure, - * or lower case, or both. - * - * Allowing for different forms of IDs to be used as keys is needed for backwards - * compatibility while we change from lower case to upper case IDs in version 0.5. - * - * @see shouldUseLowerCaseIdsAsKeys() - * @see shouldUseUpperCaseIdsAsKeys() - * - * @since 0.5 - * - * @param int $mode a bit field using the ID_KEYS_XXX constants. - * - * @throws InvalidArgumentException - */ - public function setIdKeyMode( $mode ) { - if ( ( $mode & self::ID_KEYS_BOTH ) === 0 ) { - throw new InvalidArgumentException( "At least one ID key mode must be set in the bit field." ); - } - - if ( ( $mode & ~self::ID_KEYS_BOTH ) !== 0 ) { - throw new InvalidArgumentException( "Unknown bits set in ID key mode, use the ID_KEYS_XXX constants." ); - } - - $this->setOption( self::OPT_ID_KEY_MODE, $mode ); } /** diff --git a/lib/tests/phpunit/serializers/ByPropertyListSerializerTest.php b/lib/tests/phpunit/serializers/ByPropertyListSerializerTest.php index 2e86c4c..bdd4af6 100644 --- a/lib/tests/phpunit/serializers/ByPropertyListSerializerTest.php +++ b/lib/tests/phpunit/serializers/ByPropertyListSerializerTest.php @@ -82,104 +82,6 @@ ), ); - $options = new SerializationOptions(); - $options->setIdKeyMode( SerializationOptions::ID_KEYS_LOWER ); - - $validArgs[ 'ID_KEYS_LOWER' ] = array( - new SnakList( array( $snak0, $snak1, $snak2 ) ), - array( - 'p42' => array( - 0 => array( - 'snaktype' => 'novalue', - 'property' => 'P42', - ), - ), - 'p2' => array( - 0 => array( - 'snaktype' => 'somevalue', - 'property' => 'P2', - ), - 1 => array( - 'snaktype' => 'value', - 'property' => 'P2', - 'datavalue' => $dataValue0->toArray(), - ), - ), - ), - $options - ); - - $options = new SerializationOptions(); - $options->setIdKeyMode( SerializationOptions::ID_KEYS_UPPER ); - - $validArgs[ 'ID_KEYS_UPPER' ] = array( - new SnakList( array( $snak0, $snak1, $snak2 ) ), - array( - 'P42' => array( - 0 => array( - 'snaktype' => 'novalue', - 'property' => 'P42', - ), - ), - 'P2' => array( - 0 => array( - 'snaktype' => 'somevalue', - 'property' => 'P2', - ), - 1 => array( - 'snaktype' => 'value', - 'property' => 'P2', - 'datavalue' => $dataValue0->toArray(), - ), - ), - ), - $options - ); - - $options = new SerializationOptions(); - $options->setIdKeyMode( SerializationOptions::ID_KEYS_BOTH ); - - $validArgs[ 'ID_KEYS_BOTH' ] = array( - new SnakList( array( $snak0, $snak1, $snak2 ) ), - array( - 'P42' => array( - 0 => array( - 'snaktype' => 'novalue', - 'property' => 'P42', - ), - ), - 'P2' => array( - 0 => array( - 'snaktype' => 'somevalue', - 'property' => 'P2', - ), - 1 => array( - 'snaktype' => 'value', - 'property' => 'P2', - 'datavalue' => $dataValue0->toArray(), - ), - ), - 'p42' => array( - 0 => array( - 'snaktype' => 'novalue', - 'property' => 'P42', - ), - ), - 'p2' => array( - 0 => array( - 'snaktype' => 'somevalue', - 'property' => 'P2', - ), - 1 => array( - 'snaktype' => 'value', - 'property' => 'P2', - 'datavalue' => $dataValue0->toArray(), - ), - ), - ), - $options - ); - return $validArgs; } diff --git a/lib/tests/phpunit/serializers/SerializationOptionsTest.php b/lib/tests/phpunit/serializers/SerializationOptionsTest.php index 876ce07..beb6013 100644 --- a/lib/tests/phpunit/serializers/SerializationOptionsTest.php +++ b/lib/tests/phpunit/serializers/SerializationOptionsTest.php @@ -323,40 +323,4 @@ ); } - /** - * @dataProvider provideIdKeyMode - */ - public function testSetIdKeyMode( $mode ) { - $options = new SerializationOptions(); - $options->setIdKeyMode( $mode ); - - $this->assertEquals( $mode & SerializationOptions::ID_KEYS_LOWER, $options->shouldUseLowerCaseIdsAsKeys() ); - $this->assertEquals( $mode & SerializationOptions::ID_KEYS_UPPER, $options->shouldUseUpperCaseIdsAsKeys() ); - } - - public function provideIdKeyMode() { - return array( - 'lower' => array( SerializationOptions::ID_KEYS_LOWER ), - 'upper' => array( SerializationOptions::ID_KEYS_UPPER ), - 'both' => array( SerializationOptions::ID_KEYS_BOTH ), - ); - } - - /** - * @dataProvider provideBadIdKeyMode - */ - public function testBadSetIdKeyMode( $mode ) { - $this->setExpectedException( '\InvalidArgumentException' ); - - $options = new SerializationOptions(); - $options->setIdKeyMode( $mode ); - } - - public function provideBadIdKeyMode() { - return array( - 'none' => array( 0 ), - 'badr' => array( 17 ), - ); - } - } -- To view, visit https://gerrit.wikimedia.org/r/227224 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I39cccb54b2b7bb3227aadaf70fefe365a6e4fac1 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Addshore <addshorew...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits