Permalink
Browse files

Remove Lib Serialization #winning ~=[,,_,,]:3

Bug: T64188
Change-Id: I244e3c51c694651feb0d1d0f0b822a56b1024872
  • Loading branch information...
addshore committed Jul 28, 2015
1 parent db47973 commit bba422de73ebbc37332bb6b34d925bd07115dedb
Showing with 0 additions and 6,035 deletions.
  1. +0 βˆ’128 lib/includes/serializers/AliasSerializer.php
  2. +0 βˆ’94 lib/includes/serializers/ByPropertyListSerializer.php
  3. +0 βˆ’70 lib/includes/serializers/ByPropertyListUnserializer.php
  4. +0 βˆ’257 lib/includes/serializers/ClaimSerializer.php
  5. +0 βˆ’84 lib/includes/serializers/ClaimsSerializer.php
  6. +0 βˆ’117 lib/includes/serializers/DescriptionSerializer.php
  7. +0 βˆ’240 lib/includes/serializers/EntitySerializer.php
  8. +0 βˆ’108 lib/includes/serializers/ItemSerializer.php
  9. +0 βˆ’118 lib/includes/serializers/LabelSerializer.php
  10. +0 βˆ’193 lib/includes/serializers/LibSerializerFactory.php
  11. +0 βˆ’66 lib/includes/serializers/ListSerializer.php
  12. +0 βˆ’47 lib/includes/serializers/ListUnserializer.php
  13. +0 βˆ’100 lib/includes/serializers/MultilingualSerializer.php
  14. +0 βˆ’70 lib/includes/serializers/PropertySerializer.php
  15. +0 βˆ’121 lib/includes/serializers/ReferenceSerializer.php
  16. +0 βˆ’369 lib/includes/serializers/SerializationOptions.php
  17. +0 βˆ’53 lib/includes/serializers/Serializer.php
  18. +0 βˆ’86 lib/includes/serializers/SerializerObject.php
  19. +0 βˆ’215 lib/includes/serializers/SiteLinkSerializer.php
  20. +0 βˆ’153 lib/includes/serializers/SnakSerializer.php
  21. +0 βˆ’26 lib/includes/serializers/Unserializer.php
  22. +0 βˆ’131 lib/tests/phpunit/serializers/AliasSerializerTest.php
  23. +0 βˆ’88 lib/tests/phpunit/serializers/ByPropertyListSerializerTest.php
  24. +0 βˆ’179 lib/tests/phpunit/serializers/ByPropertyListUnserializerTest.php
  25. +0 βˆ’127 lib/tests/phpunit/serializers/ClaimSerializerTest.php
  26. +0 βˆ’88 lib/tests/phpunit/serializers/ClaimsSerializerTest.php
  27. +0 βˆ’328 lib/tests/phpunit/serializers/DataModelSerializationRoundtripTest.php
  28. +0 βˆ’294 lib/tests/phpunit/serializers/DescriptionSerializerTest.php
  29. +0 βˆ’28 lib/tests/phpunit/serializers/EntitySerializerBaseTest.php
  30. +0 βˆ’233 lib/tests/phpunit/serializers/ItemSerializerTest.php
  31. +0 βˆ’294 lib/tests/phpunit/serializers/LabelSerializerTest.php
  32. +0 βˆ’122 lib/tests/phpunit/serializers/LibSerializerFactoryTest.php
  33. +0 βˆ’83 lib/tests/phpunit/serializers/ListSerializerTest.php
  34. +0 βˆ’113 lib/tests/phpunit/serializers/ListUnserializerTest.php
  35. +0 βˆ’282 lib/tests/phpunit/serializers/MultilingualSerializerTest.php
  36. +0 βˆ’68 lib/tests/phpunit/serializers/PropertySerializerTest.php
  37. +0 βˆ’114 lib/tests/phpunit/serializers/ReferenceSerializerTest.php
  38. +0 βˆ’326 lib/tests/phpunit/serializers/SerializationOptionsTest.php
  39. +0 βˆ’134 lib/tests/phpunit/serializers/SerializerBaseTest.php
  40. +0 βˆ’44 lib/tests/phpunit/serializers/SerializerTest.php
  41. +0 βˆ’142 lib/tests/phpunit/serializers/SiteLinkSerializerTest.php
  42. +0 βˆ’102 lib/tests/phpunit/serializers/SnakSerializerTest.php
@@ -1,128 +0,0 @@
<?php
namespace Wikibase\Lib\Serializers;
use InvalidArgumentException;
/**
* Serializer for aliases.
*
* See docs/json.wiki for details of the format.
*
* @since 0.4
*
* @licence GNU GPL v2+
* @author Tobias Gritschacher < tobias.gritschacher@wikimedia.de >
* @author Katie Filbert < aude.wiki@gmail.com >
*/
class AliasSerializer extends SerializerObject implements Unserializer {
/**
* Returns a serialized array of aliases.
*
* @since 0.4
*
* @param array $aliases
*
* @return array
* @throws InvalidArgumentException
*/
final public function getSerialized( $aliases ) {
if ( !is_array( $aliases ) ) {
throw new InvalidArgumentException( 'AliasSerializer can only serialize an array of aliases' );
}
//NOTE: when changing the serialization structure, update docs/json.wiki too!
$value = array();
if ( !$this->options->shouldIndexTags() ) {
foreach ( $aliases as $languageCode => $alarr ) {
$arr = array();
foreach ( $alarr as $alias ) {
if ( $alias === '' ) {
continue; // skip empty aliases
}
$arr[] = array(
'language' => $languageCode,
'value' => $alias,
);
}
$value[$languageCode] = $arr;
}
} else {
foreach ( $aliases as $languageCode => $alarr ) {
foreach ( $alarr as $alias ) {
if ( $alias === '' ) {
continue; // skip empty aliases
}
$value[] = array(
'language' => $languageCode,
'value' => $alias,
);
}
}
}
if ( $this->options->shouldIndexTags() ) {
$this->setIndexedTagName( $value, 'alias' );
}
return $value;
}
/**
* @see Unserializer::newFromSerialization
*
* @since 0.4
*
* @param array $data
*
* @throws InvalidArgumentException
* @return array
*/
public function newFromSerialization( array $data ) {
$aliases = array();
foreach ( $data as $key => $aliasSet ) {
if ( $key === '_element' ) {
continue;
}
if ( !is_array( $aliasSet ) ) {
throw new InvalidArgumentException( 'Alias data is invalid.' );
}
$lang = array_key_exists( 'language', $aliasSet ) ? $aliasSet['language'] : $key;
if ( array_key_exists( 'value', $aliasSet ) ) {
$aliases[$lang][] = $aliasSet['value'];
} else {
$aliases[$lang] = $this->extractAliasValues( $aliasSet );
}
}
return $aliases;
}
/**
* @param array $aliasSet
*
* @throws InvalidArgumentException
* @return string[]
*/
protected function extractAliasValues( array $aliasSet ) {
$aliases = array();
foreach ( $aliasSet as $alias ) {
if ( is_array( $alias ) && array_key_exists( 'value', $alias ) && is_string( $alias['value'] ) ) {
$aliases[] = $alias['value'];
} else {
throw new InvalidArgumentException( 'Alias value is invalid' );
}
}
return $aliases;
}
}
@@ -1,94 +0,0 @@
<?php
namespace Wikibase\Lib\Serializers;
use InvalidArgumentException;
use Traversable;
use Wikibase\DataModel\ByPropertyIdGrouper;
/**
* Serializer for Traversable objects that need to be grouped
* per property id. Each element needs to have a getPropertyId method.
*
* @since 0.2
*
* @licence GNU GPL v2+
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
class ByPropertyListSerializer extends SerializerObject {
const OPT_ADD_LOWER_CASE_KEYS = 'addLowerCaseKeys';
/**
* @var string
*/
private $elementName;
/**
* @var Serializer
*/
private $elementSerializer;
/**
* @since 0.2
*
* @param string $elementName
* @param Serializer $elementSerializer
* @param SerializationOptions|null $options
*/
public function __construct(
$elementName,
Serializer $elementSerializer,
SerializationOptions $options = null
) {
parent::__construct( $options );
$this->elementName = $elementName;
$this->elementSerializer = $elementSerializer;
}
/**
* @see ApiSerializer::getSerialized
*
* @since 0.2
*
* @param mixed $objects
*
* @return array
* @throws InvalidArgumentException
*/
public function getSerialized( $objects ) {
if ( !( $objects instanceof Traversable ) ) {
throw new InvalidArgumentException( 'ByPropertyListSerializer can only serialize Traversable objects' );
}
//NOTE: when changing the serialization structure, update docs/json.wiki too!
$serialization = array();
$byPropertyIdGrouper = new ByPropertyIdGrouper( $objects );
foreach ( $byPropertyIdGrouper->getPropertyIds() as $propertyId ) {
$serializedObjects = array();
foreach ( $byPropertyIdGrouper->getByPropertyId( $propertyId ) as $object ) {
$serializedObjects[] = $this->elementSerializer->getSerialized( $object );
}
$this->setIndexedTagName( $serializedObjects, $this->elementName );
if ( $this->options->shouldIndexTags() ) {
$serializedObjects['id'] = $propertyId->getSerialization();
$serialization[] = $serializedObjects;
} else {
$key = strtoupper( $propertyId->getSerialization() );
$serialization[$key] = $serializedObjects;
}
}
$this->setIndexedTagName( $serialization, 'property' );
return $serialization;
}
}
@@ -1,70 +0,0 @@
<?php
namespace Wikibase\Lib\Serializers;
use InvalidArgumentException;
use OutOfBoundsException;
/**
* Serializer for Traversable objects that need to be grouped
* per property id. Each element needs to have a getPropertyId method.
*
* @since 0.4
*
* @licence GNU GPL v2+
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
* @author Daniel Kinzler
*/
class ByPropertyListUnserializer implements Unserializer {
/**
* @var Serializer
*/
private $elementUnserializer;
/**
* @since 0.2
*
* @param Unserializer $elementUnserializer
*/
public function __construct( Unserializer $elementUnserializer ) {
$this->elementUnserializer = $elementUnserializer;
}
/**
* @see Unserializer::newFromSerialization
*
* @since 0.4
*
* @param array $serialization
*
* @return array
* @throws InvalidArgumentException
* @throws OutOfBoundsException
*/
public function newFromSerialization( array $serialization ) {
$elements = array();
foreach ( $serialization as $propertyId => $byPropId ) {
if ( !is_array( $byPropId ) ) {
throw new InvalidArgumentException( "Element with key '$propertyId' should be an array, found " . gettype( $byPropId ) );
}
foreach ( $byPropId as $serializedElement ) {
$element = $this->elementUnserializer->newFromSerialization( $serializedElement );
$elementPropertyId = $element->getPropertyId()->getSerialization();
if ( strtoupper( $elementPropertyId ) !== strtoupper( $propertyId ) ) {
throw new OutOfBoundsException( "Element with id '" . $elementPropertyId .
"' found in list with id '" . $propertyId . "'" );
}
$elements[] = $element;
}
}
return $elements;
}
}
Oops, something went wrong.

0 comments on commit bba422d

Please sign in to comment.