<commit_before># *estvoyage\serialization* [![Build Status](https://api.travis-ci.org/estvoyage/serialization.svg)](https://travis-ci.org/estvoyage/serialization) [![Coverage Status](https://coveralls.io/repos/estvoyage/serialization/badge.svg)](https://coveralls.io/r/estvoyage/serialization)

## An east-oriented serialization interface

**serialization** is a [PHP](http://www.php.net) library that allows you to implement a [serialization](http://en.wikipedia.org/wiki/Serialization) protocol in any class.  
Traditionaly, if you want serialize an instance as JSON, you implements the `[jsonSerializable](http://php.net/jsonserializable)` interface in its class.  
Moreover, if several classes should support JSON serialization, you should implements this interface in each of them.  
And if you want using an another serialization format, as XML, you should implements a new method in each classes.  
With **serialization**, you can define only one method in each classes to handle any number of serialization format.

## Installation

Minimal PHP version to use **serialization** is 5.6.  
The recommended way to install Negotiation is through [Composer](http://getcomposer.org/):

``` json
{
	"require": {
		"estvoyage/serialization": "@dev",
		"estvoyage/object": "@dev",
		"estvoyage/value": "@dev"
	}
}
```

## Usage

In a nutshell:

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use
	estvoyage\object,
	estvoyage\serialization
;

class foo implements object\storable
{
	private
		$stringProperty,
		$integerProperty,
		$floatProperty,
		$booleanProperty,
		$storableProperty,
		$nullProperty
	;

	function __construct($string, $integer, $float, $boolean, object\storable $storable, $null = null)
	{
		$this->stringProperty = $string;
		$this->integerProperty = $integer;
		$this->floatProperty = $float;
		$this->booleanProperty = $boolean;
		$this->storableProperty = $storable;
		$this->nullProperty = $null;
	}

	function storerIsReady(object\storer $storer)
	{
		$storer
			->stringPropertyHasValue(new object\property('stringProperty'), new object\property\string($this->stringProperty))
			->integerPropertyHasValue(new object\property('integerProperty'), new object\property\integer($this->integerProperty))
			->floatPropertyHasValue(new object\property('floatProperty'), new object\property\float($this->floatProperty))
			->booleanPropertyHasValue(new object\property('booleanProperty'), new object\property\boolean($this->booleanProperty))
			->storablePropertyHasValue(new object\property('storableProperty'), $this->storableProperty)
			->nullProperty(new object\property('nullProperty'))
		;
	}
}

class bar implements object\storable
{
	private
		$value
	;

	function __construct($value)
	{
		$this->value = $value;
	}

	function storerIsReady(object\storer $storer)
	{
		$storer
			->stringPropertyHasValue(new object\property('value'), new object\property\string($this->value))
		;
	}
}

$jsonSerializer = new serialization\serializer\json;
$foo = new foo(uniqid(), 666, 666.999, true, new bar(uniqid()));

echo "As JSON:" . PHP_EOL;
echo (new serialization\serializer\json)->serialize($foo) . PHP_EOL;
// {"stringProperty":"54e8b71a4419d","integerProperty":666,"floatProperty":666.999,"booleanProperty":true,"storableProperty":{"value":"54e8b71a441aa"},"nullProperty":null}

echo "As CSV:" . PHP_EOL;
echo (new serialization\serializer\csv)->serialize($foo) . PHP_EOL;

/*
"stringProperty","integerProperty","floatProperty","booleanProperty","storableProperty.value","nullProperty"
"54e8b71a4419d",666,666.999,1,"54e8b71a441aa",
*/
```

## Unit Tests

Setup the test suite using Composer:

    $ composer install --dev

Run it using **atoum**:

    $ vendor/bin/atoum

## License

**serialization** is released under the FreeBSD License, see the bundled `COPYING` file for details.
<commit_msg>Typo.<commit_after># *estvoyage\serialization* [![Build Status](https://api.travis-ci.org/estvoyage/serialization.svg)](https://travis-ci.org/estvoyage/serialization) [![Coverage Status](https://coveralls.io/repos/estvoyage/serialization/badge.svg)](https://coveralls.io/r/estvoyage/serialization)

## An east-oriented serialization interface

**serialization** is a [PHP](http://www.php.net) library that allows you to implement a [serialization](http://en.wikipedia.org/wiki/Serialization) protocol in any class.  
Traditionaly, if you want serialize an instance as JSON, you implements the [`jsonSerializable`](http://php.net/jsonserializable) interface in its class.  
Moreover, if several classes should support JSON serialization, you should implements this interface in each of them.  
And if you want using an another serialization format, as XML, you should implements a new method in each classes.  
With **serialization**, you can define only one method in each classes to handle any number of serialization format.

## Installation

Minimal PHP version to use **serialization** is 5.6.  
The recommended way to install Negotiation is through [Composer](http://getcomposer.org/):

``` json
{
	"require": {
		"estvoyage/serialization": "@dev",
		"estvoyage/object": "@dev",
		"estvoyage/value": "@dev"
	}
}
```

## Usage

In a nutshell:

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use
	estvoyage\object,
	estvoyage\serialization
;

class foo implements object\storable
{
	private
		$stringProperty,
		$integerProperty,
		$floatProperty,
		$booleanProperty,
		$storableProperty,
		$nullProperty
	;

	function __construct($string, $integer, $float, $boolean, object\storable $storable, $null = null)
	{
		$this->stringProperty = $string;
		$this->integerProperty = $integer;
		$this->floatProperty = $float;
		$this->booleanProperty = $boolean;
		$this->storableProperty = $storable;
		$this->nullProperty = $null;
	}

	function storerIsReady(object\storer $storer)
	{
		$storer
			->stringPropertyHasValue(new object\property('stringProperty'), new object\property\string($this->stringProperty))
			->integerPropertyHasValue(new object\property('integerProperty'), new object\property\integer($this->integerProperty))
			->floatPropertyHasValue(new object\property('floatProperty'), new object\property\float($this->floatProperty))
			->booleanPropertyHasValue(new object\property('booleanProperty'), new object\property\boolean($this->booleanProperty))
			->storablePropertyHasValue(new object\property('storableProperty'), $this->storableProperty)
			->nullProperty(new object\property('nullProperty'))
		;
	}
}

class bar implements object\storable
{
	private
		$value
	;

	function __construct($value)
	{
		$this->value = $value;
	}

	function storerIsReady(object\storer $storer)
	{
		$storer
			->stringPropertyHasValue(new object\property('value'), new object\property\string($this->value))
		;
	}
}

$jsonSerializer = new serialization\serializer\json;
$foo = new foo(uniqid(), 666, 666.999, true, new bar(uniqid()));

echo "As JSON:" . PHP_EOL;
echo (new serialization\serializer\json)->serialize($foo) . PHP_EOL;
// {"stringProperty":"54e8b71a4419d","integerProperty":666,"floatProperty":666.999,"booleanProperty":true,"storableProperty":{"value":"54e8b71a441aa"},"nullProperty":null}

echo "As CSV:" . PHP_EOL;
echo (new serialization\serializer\csv)->serialize($foo) . PHP_EOL;

/*
"stringProperty","integerProperty","floatProperty","booleanProperty","storableProperty.value","nullProperty"
"54e8b71a4419d",666,666.999,1,"54e8b71a441aa",
*/
```

## Unit Tests

Setup the test suite using Composer:

    $ composer install --dev

Run it using **atoum**:

    $ vendor/bin/atoum

## License

**serialization** is released under the FreeBSD License, see the bundled `COPYING` file for details.

{'fraction_non_alphanumeric': 0.14112271540469973, 'fraction_numerical': 0.01671018276762402, 'mean_word_length': 5.5929432013769365, 'pattern_counts': {'":': 22, '<': 5, '<?xml version=': 0, '>': 47, 'https://': 8, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '33214', 'n_tokens_mistral': 2549, 'n_tokens_neox': 2368, 'n_words': 544}