2017 © Pedro PelĂĄez
 

library serialization

An east-oriented serialization interface

image

estvoyage/serialization

An east-oriented serialization interface

  • Tuesday, September 22, 2015
  • by mageekguy
  • Repository
  • 2 Watchers
  • 1 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

estvoyage\serialization Build Status Coverage Status

An east-oriented serialization interface

serialization is a PHP library that allows you to implement a serialization protocol in any class.
Traditionaly, if you want serialize an instance as JSON, you implements the 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 to use an another serialization format, e.g. XML, you should implement a new method in each class. With serialization, you can define a unique method in each class to handle any serialization format., (*1)

Installation

Minimal PHP version to use serialization is 5.6.
The recommended way to install Negotiation is through Composer, just add this in your composer.json and execute php composer.phar install:, (*2)

``` json { "require": { "estvoyage/serialization": "@dev", "estvoyage/object": "@dev", "estvoyage/value": "@dev" } }, (*3)


## Usage In a nutshell: ```php <?php require __DIR__ . '/../vendor/autoload.php'; use estvoyage\csv, estvoyage\data, estvoyage\object, estvoyage\serialization ; class console implements data\consumer { function dataProviderIs(data\provider $provider) { $provider->dataConsumerIs($this); return $this; } function newData(data\data $data) { echo 'Serialization: <' . $data . '>' . PHP_EOL; return $this; } function noMoreData() { return $this; } function dataConsumerControllerIs(data\consumer\controller $controller) { return $this; } } 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 objectStorerIs(object\storer $storer) { $storer ->stringObjectPropertyHasValue(new object\property('stringProperty'), new object\property\string($this->stringProperty)) ->integerObjectPropertyHasValue(new object\property('integerProperty'), new object\property\integer($this->integerProperty)) ->floatObjectPropertyHasValue(new object\property('floatProperty'), new object\property\float($this->floatProperty)) ->booleanObjectPropertyHasValue(new object\property('booleanProperty'), new object\property\boolean($this->booleanProperty)) ->storableObjectPropertyHasValue(new object\property('storableProperty'), $this->storableProperty) ->nullObjectProperty(new object\property('nullProperty')) ; } } class bar implements object\storable { private $value ; function __construct($value) { $this->value = $value; } function objectStorerIs(object\storer $storer) { $storer ->stringObjectPropertyHasValue(new object\property('value'), new object\property\string($this->value)) ; } } $console = new console; $foo = new foo(uniqid(), 666, 666.999, true, new bar(uniqid())); (new serialization\serializer\json) ->newStorable($foo) ->dataConsumerIs($console) ; (new serialization\serializer\csv(new csv\generator\rfc4180)) ->newStorable($foo) ->dataConsumerIs($console) ; /* Output will be something like: Serialization: <{"stringProperty":"5511d589ef90a","integerProperty":666,"floatProperty":666.999,"booleanProperty":true,"storableProperty":{"value":"5511d589ef932"},"nullProperty":null}> Serialization: <stringProperty,integerProperty,floatProperty,booleanProperty,storableProperty.value,nullProperty 5511d589ef90a,666,666.999,1,5511d589ef932, > */

A working script is available in the bundled examples directory, just do php examples/nutshell.php to execute it., (*4)

Unit Tests

Setup the test suite using Composer:, (*5)

$ composer install --dev

Run it using atoum:, (*6)

$ vendor/bin/atoum

Contributing

See the bundled CONTRIBUTING file for details., (*7)

License

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

The Versions

22/09 2015

dev-master

9999999-dev http://github.com/estvoyage/serialization

An east-oriented serialization interface

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

  • mageekguy/atoum @dev

serialization east