summaryrefslogtreecommitdiff
path: root/www/wiki/vendor/serialization/serialization/README.md
blob: 43d82f561e4708055deace7becbdadcc6f29dc5f (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
134
# Serialization

[![Build Status](https://secure.travis-ci.org/wmde/Serialization.png?branch=master)](http://travis-ci.org/wmde/Serialization)
[![Code Coverage](https://scrutinizer-ci.com/g/wmde/Serialization/badges/coverage.png?s=c1db04f88f763f63dc0f0d8315cf9b8491fc81e6)](https://scrutinizer-ci.com/g/wmde/Serialization/)
[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/wmde/Serialization/badges/quality-score.png?s=d25b9d7cbc4a737817ebf072d2e4b55b0bd8b662)](https://scrutinizer-ci.com/g/wmde/Serialization/)

On Packagist:
[![Latest Stable Version](https://poser.pugx.org/serialization/serialization/version.png)](https://packagist.org/packages/serialization/serialization)
[![Download count](https://poser.pugx.org/serialization/serialization/d/total.png)](https://packagist.org/packages/serialization/serialization)

Small library defining a Serializer and a Deserializer interface.

Also contains various Exceptions and a few basic (de)serialization utilities.

## Requirements

* PHP 5.3 or later

## Installation

You can use [Composer](http://getcomposer.org/) to download and install
this package as well as its dependencies. Alternatively you can simply clone
the git repository and take care of loading yourself.

### Composer

To add this package as a local, per-project dependency to your project, simply add a
dependency on `serialization/serialization` to your project's `composer.json` file.
Here is a minimal example of a `composer.json` file that just defines a dependency on
Serialization 3.0:

    {
        "require": {
            "serialization/serialization": "3.0.*"
        }
    }

### Manual

Get the Serialization code, either via git, or some other means. Also get all dependencies.
You can find a list of the dependencies in the "require" section of the composer.json file.
This file also specifies how the resources provided by this library should be loaded, in
its "autoload" section.

## Usage

### Library structure

This component contains two sub parts, one containing serialization related code, the
other holding deserializaion specific code. The former is located in the Serializers
namespace, while the later resides in the Deserializers one. Both namespaces are PSR-0
mapped onto the src directory.

### Interfaces

The primary thing provided by this library are the Serializer and Deserializer namespaces.
A set of Exceptions each process typically can encounter are also provided, and are located
in respective Exceptions namespaces. They all derive from (Des/S)erializationException.

Both interfaces define two methods: a (de)serialize method that does the actual work, and
a can(Des/S)erialize method that allows finding out if a given (de)serializer can process
a given input.

### Utilities

A DispatchingSerializer and a DispatcingDeserializer are two generally usable implementations
of the interfaces that are included in this library. They both do the same thing: contain a
list of (de)serializers and dispatch calls to the (de)serialize method to the appropriate one.
This allows for bundling multiple (de)serializers together and enables handling of nested
data with variable structure.

## Tests

This library comes with a set up PHPUnit tests that cover all non-trivial code. You can run these
tests using the PHPUnit configuration file found in the root directory. The tests can also be run
via TravisCI, as a TravisCI configuration file is also provided in the root directory.

The library contains some code that was split factored out of concrete classes part of
[AskSerialization](https://github.com/wmde/AskSerialization). Those tests have not been
split, hence the low apparent coverage. It is recommended to run the AskSerialization
tests when making changes to the code in question.

## Authors

Serialization has been written by [Jeroen De Dauw](https://www.mediawiki.org/wiki/User:Jeroen_De_Dauw)
as [Wikimedia Germany](https://wikimedia.de) employee for the [Wikidata project](https://wikidata.org/).

## Release notes

### 3.2.1 (2014-08-19)

* Tested against hhvm-nightly
* Tests now run in strict mode

### 3.2 (2014-05-20)

* Made SerializationException non-abstract

### 3.1 (2014-03-18)

* TypedObjectDeserializer now explicitly implements DispatchableDeserializer.

### 3.0 (2014-03-05)

* Split is(Des/S)erializerFor methods off into new Dispatchable(Des/S)erializer interfaces
* Changed from classmap based autoloading to PSR-4 based autoloading
* Improved PHPUnit bootstrap

### 2.2 (2013-12-11)

* Removed custom autoloader in favour of using the declarative system provided by Composer

### 2.1 (2013-11-19)

* The type key in TypedObjectDeserializer can now be specified via a constructor argument
* TypedObjectDeserializer now has some tests in this component itself
* The documentation was somewhat improved

### 2.0 (2013-09-05)

* Renamed Serializer::canSerialize to Serializer::isDeserializerFor
* Renamed Deserializer::canDeserialize to Deserializer::isDeserializerFor

### 1.0 (2013-07-13)

* Initial release.

## Links

* [Serialization on Packagist](https://packagist.org/packages/serialization/serialization)
* [Serialization on Ohloh](https://www.ohloh.net/p/serialization-php)
* [TravisCI build status](https://travis-ci.org/wmde/Serialization)
* [Serialization on ScrutinizerCI](https://scrutinizer-ci.com/g/wmde/Serialization/)