summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/docs/technical/doc.serializers.md
blob: 58ded396dcf321a7c40bc223ba2959b50081c585 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
This document contains information about Semantic MediaWiki serializers.

## Components

### Serializer and Deserializer
Interfaces provided by the [Serialization extension][serialization] which describes specific serialize/deserialze public methods.

### SerializerFactory
A factory class that assigns registered serializers to an object and identifies an unserializer based on the invoked array. A serialized record has a reference to the generator (serializer) class which will automatically be used during unserialization. Each record includes a version number to compare the data model used and enable a consistency check before an attempt to unserialize a record.

```php
$foo = new Foo( ... );
$serialized = SerializerFactory::serialize( $foo );
$unserialized = SerializerFactory::deserialize( $serialized );
```

### SemanticDataSerializer
Implements the Serializer interface for the SMW\SemanticData object.

#### Data model
```php
"subject": -> Subject serialization,
"data": [
	{
		"property": -> Property serialization,
		"dataitem": [
			{
				"type": -> DataItemType,
				"item": -> DataItem serialization
			}
		]
	}
]
"sobj": [
	{
		"subject": ...,
		"data": [
			{
				"property": ...,
				"dataitem": [
					{
						"type": ...,
						"item": ...
					}
				]
			},
	},
],
"serializer": -> Class of the generator and entry point for the un-serializer,
"version": -> Number to compare structural integrity between serialization and un-serialization
```
#### Example
For a page called "Foo" that contains <code>[[Has property::Bar]]</code>, <code>{{#subobject:|Has subobjects=Bam}}</code>, <code>{{#ask:[[Has subobjects::Bam]]}}</code>, the Serializer will output:

```php
"subject": "Foo#0##",
"data": [
	{
		"property": "Has_property",
		"dataitem": [
			{
				"type": 9,
				"item": "Bar#0##"
			}
		]
	},
	{
		"property": "_ASK",
		"dataitem": [
			{
				"type": 9,
				"item": "Foo#0##_QUERYc8606da8f325fc05aa8e8b958821c3b4"
			}
		]
	},
	...
	{
		"property": "_SOBJ",
		"dataitem": [
			{
				"type": 9,
				"item": "Foo#0##_fc4b104aabf80eb06429e946aa8f7070"
			}
		]
	}
],
"sobj": [
	{
		"subject": "Foo#0##_QUERYc8606da8f325fc05aa8e8b958821c3b4",
		"data": [
			{
				"property": "_ASKDE",
				"dataitem": [
					{
						"type": 1,
						"item": "1"
					}
				]
			},
	},
	...
	{
		"subject": "Foo#0##_fc4b104aabf80eb06429e946aa8f7070",
		"data": [
			{
				"property": "Has_subobjects",
				"dataitem": [
					{
						"type": 9,
						"item": "Bam#0##"
					}
				]
			},
			{
				"property": "_SKEY",
				"dataitem": [
					{
						"type": 2,
						"item": "Foo"
					}
				]
			}
		]
	}
],
"serializer": "SMW\\Serializers\\SemanticDataSerializer",
"version": 0.1
```

### QueryResultSerializer
Implements the SerializerInterface for the SMWQueryResult object.

[serialization]: [https://github.com/wikimedia/mediawiki-extensions-Serialization]