<commit_before>serial
======

A collection of PHP serialization helpers with a consistent interface for each.

[![Build Status](https://travis-ci.org/duncan3dc/serial.svg?branch=master)](https://travis-ci.org/duncan3dc/serial)
[![Latest Stable Version](https://poser.pugx.org/duncan3dc/serial/version.svg)](https://packagist.org/packages/duncan3dc/serial)


Available Classes
=================

* Json (using the native json_* functions)
* Yaml (using the Symfony Yaml component)


Interface
=========

All serialization classes implement the interface [duncan3dc\Serial\SerialInterface](src/SerialInterface.php)


Examples
========

Convert array data to string format
```php
use duncan3dc\Serial\Json;
$data = BusinessLogic::getDataAsArray();
$json = Json::encode($data);
```

Convert string formatted data to an array
```php
use duncan3dc\Serial\Yaml;
$yaml = Api::getYamlResponse($request);
$response = Yaml::decode($yaml);
```

Convient methods to serialize and store data on disk
```php
use duncan3dc\Serial\Json;
$filename = "/tmp/file.json";
$data = BusinessLogic::getDataAsArray();
Json::encodeToFile($filename, $data);
```

Retrieve previously stored data from disk
```php
use duncan3dc\Serial\Json;
$filename = "/tmp/file.json";
$data = Json::decodeFromFile($filename);
```


Serial Helper
=============

There is a Serial class that allows for juggling/guessing formats
```php
use duncan3dc\Serial\Serial;
$data = BusinessLogic::getDataAsArray();
$serial = new Serial($data);
$json = (string)$serial->toJson();
$yaml = (string)$serial->toYaml();
$data = $serial->toArray();
```

All the methods return the instance making them chainable
```php
use duncan3dc\Serial\Serial;
$json = Api::getJsonResponse($request);
$yaml = (new Serial($json))->fromJson()->toYaml();
```

Then serialized string is available by casting the Serial class to a string, and php array is available by calling the toArray() method<commit_msg>Minor updates to the README<commit_after>serial
======

A collection of PHP serialization helpers with a consistent interface for each.

[![Build Status](https://travis-ci.org/duncan3dc/serial.svg?branch=master)](https://travis-ci.org/duncan3dc/serial)
[![Latest Stable Version](https://poser.pugx.org/duncan3dc/serial/version.svg)](https://packagist.org/packages/duncan3dc/serial)


Available Classes
=================

* Json (using the native json_* functions)
* Yaml (using the Symfony Yaml component)
* Php (using the native serialize/unserialize functions)


Interface
=========

All serialization classes implement the interface [duncan3dc\Serial\SerialInterface](src/SerialInterface.php)


Examples
========

Convert array data to string format
```php
use duncan3dc\Serial\Json;
$data = BusinessLogic::getDataAsArray();
$json = Json::encode($data);
```

Convert string formatted data to an array
```php
use duncan3dc\Serial\Yaml;
$yaml = Api::getYamlResponse($request);
$response = Yaml::decode($yaml);
```

Convient methods to serialize and store data on disk
```php
use duncan3dc\Serial\Json;
$filename = "/tmp/file.json";
$data = BusinessLogic::getDataAsArray();
Json::encodeToFile($filename, $data);
```

Retrieve previously stored data from disk
```php
use duncan3dc\Serial\Json;
$filename = "/tmp/file.json";
$data = Json::decodeFromFile($filename);
```


Serial Helper
=============

There is a Serial class that allows for juggling/guessing formats
```php
use duncan3dc\Serial\Serial;
$data = BusinessLogic::getDataAsArray();
$serial = new Serial($data);
$json = (string) $serial->toJson();
$yaml = (string) $serial->toYaml();
$data = $serial->toArray();
```

All the methods return the instance making them chainable
```php
use duncan3dc\Serial\Serial;
$json = Api::getJsonResponse($request);
$yaml = (new Serial($json))->fromJson()->toYaml();
```

Then serialized string is available by casting the Serial class to a string, and php array is available by calling the toArray() method
{'fraction_non_alphanumeric': 0.16187325019088827, 'fraction_numerical': 0.00559938915754645, 'mean_word_length': 6.158469945355192, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, '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': '30317', 'n_tokens_mistral': 1242, 'n_tokens_neox': 1201, 'n_words': 341}