Skip to content

Commit 6ebaf85

Browse files
Merge pull request #222 from wmde/deprecations25
Improve documentation of confusing newEntity(De)Serializer methods
2 parents 022c336 + a8feef9 commit 6ebaf85

4 files changed

Lines changed: 24 additions & 15 deletions

File tree

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
[![Latest Stable Version](https://poser.pugx.org/wikibase/data-model-serialization/version.png)](https://packagist.org/packages/wikibase/data-model-serialization)
1111
[![Latest Unstable Version](https://poser.pugx.org/wikibase/data-model-serialization/v/unstable.svg)](//packagist.org/packages/wikibase/data-model-serialization)
1212

13-
Library containing serializers and deserializers for the [Wikibase DataModel](https://github.com/wmde/WikibaseDataModel).
13+
Library containing serializers and deserializers for the basic
14+
[Wikibase DataModel](https://github.com/wmde/WikibaseDataModel) entity types and components they are
15+
made of.
1416
The supported formats are limited to public ones, ie those used by a web API.
1517
Serialization code for private formats, such as the format used by the Wikibase
1618
Repo data access layer, belongs in other components.
@@ -44,29 +46,28 @@ Then take care of autoloading the classes defined in the src directory.
4446

4547
## Library usage
4648

47-
Construct an instance of the deserializer or serializer you need via the appropriate factory.
49+
Construct an instance of the specific deserializer or serializer you need via the appropriate factory.
4850

4951
```php
5052
use Wikibase\DataModel\DeserializerFactory;
5153

5254
$deserializerFactory = new DeserializerFactory( /* ... */ );
53-
$entityDeserializer = $deserializerFactory->newEntityDeserializer();
55+
$itemDeserializer = $deserializerFactory->newItemDeserializer();
5456
```
5557

56-
The use the deserialize or serialize method.
58+
Then use the `deserialize` or `serialize` method.
5759

5860
```php
59-
$entity = $entityDeserializer->deserialize( $myEntitySerialization );
61+
$item = $itemDeserializer->deserialize( $myItemSerialization );
6062
```
6163

6264
In case of deserialization, guarding against failures is good practice.
6365
So it is typically better to use the slightly more verbose try-catch approach.
6466

6567
```php
6668
try {
67-
$entity = $entityDeserializer->deserialize( $myEntitySerialization );
68-
}
69-
catch ( DeserializationException $ex ) {
69+
$item = $itemDeserializer->deserialize( $myItemSerialization );
70+
} catch ( DeserializationException $ex ) {
7071
// Handling of the exception
7172
}
7273
```
@@ -88,7 +89,7 @@ Serializers can be obtained via an instance of `SerializerFactory` and deseriali
8889
via an instance of `DeserializerFactory`. You are not allowed to construct these serializers and
8990
deserializers directly yourself or to have any kind of knowledge of them (ie type hinting). These
9091
objects are internal to this component and might change name or structure at any time. All you
91-
are allowed to know when calling `$serializerFactory->newEntitySerializer()` is that you get back
92+
are allowed to know when calling `$serializerFactory->newItemDeserializer()` is that you get back
9293
an instance of `Serializers\Serializer`.
9394

9495
## Tests

RELEASE-NOTES.md

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

3+
## 2.7.0 (dev)
4+
5+
* Improved documentation of `SerializerFactory::newEntitySerializer` as well as
6+
`DeserializerFactory::newEntityDeserializer`.
7+
38
## 2.6.0 (2017-09-18)
49

510
* Added compatibility with DataValues Number 0.9

src/DeserializerFactory.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ public function __construct(
5454
}
5555

5656
/**
57-
* Returns a Deserializer that can deserialize Item and Property objects.
58-
*
59-
* @return DispatchableDeserializer
57+
* @return DispatchableDeserializer A deserializer that can only deserialize Item and Property
58+
* objects, but no other entity types. In contexts with custom entity types other than items
59+
* and properties this is not what you want. If in doubt, favor a custom
60+
* `DispatchingDeserializer` containing the exact entity deserializers you need.
6061
*/
6162
public function newEntityDeserializer() {
6263
return new DispatchingDeserializer( [

src/SerializerFactory.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Wikibase\DataModel;
44

55
use InvalidArgumentException;
6+
use Serializers\DispatchableSerializer;
67
use Serializers\DispatchingSerializer;
78
use Serializers\Serializer;
89
use Wikibase\DataModel\Serializers\AliasGroupListSerializer;
@@ -113,9 +114,10 @@ private function shouldSerializeReferenceSnaksWithHash() {
113114
}
114115

115116
/**
116-
* Returns a Serializer that can serialize Item and Property objects.
117-
*
118-
* @return Serializer
117+
* @return DispatchableSerializer A serializer that can only serialize Item and Property
118+
* objects, but no other entity types. In contexts with custom entity types other than items
119+
* and properties this is not what you want. If in doubt, favor a custom
120+
* `DispatchingSerializer` containing the exact entity serializers you need.
119121
*/
120122
public function newEntitySerializer() {
121123
return new DispatchingSerializer( [

0 commit comments

Comments
 (0)