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.
1416The supported formats are limited to public ones, ie those used by a web API.
1517Serialization code for private formats, such as the format used by the Wikibase
1618Repo 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
5052use 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
6264In case of deserialization, guarding against failures is good practice.
6365So it is typically better to use the slightly more verbose try-catch approach.
6466
6567``` php
6668try {
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
8889via an instance of ` DeserializerFactory ` . You are not allowed to construct these serializers and
8990deserializers directly yourself or to have any kind of knowledge of them (ie type hinting). These
9091objects 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
9293an instance of ` Serializers\Serializer ` .
9394
9495## Tests
0 commit comments