2017 © Pedro Peláez
 

library serializard

Flexible serializer

image

thunderer/serializard

Flexible serializer

  • Friday, February 16, 2018
  • by Thunderer
  • Repository
  • 1 Watchers
  • 18 Stars
  • 32,612 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 2 Open issues
  • 13 Versions
  • 8 % Grown

The README.md

Serializard

Build Status Latest Stable Version License Scrutinizer Code Quality Code Coverage Dependency Status, (*1)

Serializard is a library for (un)serialization of data of any complexity. Its main focus is to give user as much flexibility as possible by delegating the (un)serialization logic to the programmer to encourage good object design and only supervising the process hiding the unpleasant details about it., (*2)

Installation

This library is available on Composer/Packagist as thunderer/serializard., (*3)

Usage

Let's consider a simple User class with two properties and some setup code:, (*4)

final class User
{
    private $id;
    private $name;

    public function __construct(int $id, string $name) { /* ... */ }

    public function getId() { return $this->id; }
    public function getName() { return $this->name; }
}

$user = new User(1, 'Thomas');

$formats = new FormatContainer();
$formats->add('json', new JsonFormat());

$hydrators = new FallbackHydratorContainer();
$normalizers = new FallbackNormalizerContainer();
$serializard = new Serializard($formats, $normalizers, $hydrators);

Serialization

Serialization is controlled by registering handlers used in normalization phase:, (*5)

$normalizers->add(User::class, function(User $user) {
    return [
        'id' => $user->getId(),
        'name' => $user->getName(),
    ];
});

$result = $serializard->serialize($user, 'json');
// result is {"id":1,"name":"Thomas"}

Unserialization

Unserialization can be controlled by registering callables able to reconstruct objects from data parsed from input text:, (*6)

$hydrators->add(User::class, function(array $data) {
    return new User($data['id'], $data['name']);
});

$json = '{"id":1,"name":"Thomas"}';
$user = $serializard->unserialize($json, User::class, 'json');

Formats

  • JSON in JsonFormat converts objects to JSON,
  • Array in ArrayFormat just returns object graph normalized to arrays of scalars,
  • YAML in YamlFormat converts objects to YAML (uses symfony/yaml),
  • XML in XmlFormat converts objects to XML (uses ext-dom).

License

See LICENSE file in the main directory of this library., (*7)

The Versions

16/02 2018

dev-default-normalizer-hydrator

dev-default-normalizer-hydrator

Flexible serializer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomasz Kowalczyk

json xml library serializer yaml hydrator normalizer

13/02 2018

dev-master

9999999-dev

Flexible serializer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomasz Kowalczyk

json xml library serializer yaml hydrator normalizer

13/02 2018

v0.3.2

0.3.2.0

Flexible serializer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomasz Kowalczyk

json xml library serializer yaml hydrator normalizer

21/09 2017

dev-case-insensitive-containers

dev-case-insensitive-containers

Flexible serializer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomasz Kowalczyk

json xml library serializer yaml hydrator normalizer

28/05 2017

v0.3.1

0.3.1.0

Flexible serializer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomasz Kowalczyk

json xml library serializer yaml hydrator normalizer

28/05 2017

v0.3.0

0.3.0.0

Flexible serializer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomasz Kowalczyk

json xml library serializer yaml hydrator normalizer

10/03 2017

v0.2.0

0.2.0.0

Flexible serializer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomasz Kowalczyk

library serializer

28/02 2017

dev-phpunit6

dev-phpunit6

Flexible serializer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomasz Kowalczyk

library serializer

15/01 2017

dev-serialization-contexts

dev-serialization-contexts

Flexible serializer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomasz Kowalczyk

json xml library serializer yaml hydrator normalizer

03/08 2016

v0.1.2

0.1.2.0

Flexible serializer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomasz Kowalczyk

library serializer

08/06 2016

v0.1.1

0.1.1.0

Flexible serializer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomasz Kowalczyk

library serializer

17/02 2016

dev-introduce-context

dev-introduce-context

Flexible serializer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomasz Kowalczyk

json xml library serializer yaml normalizer

12/02 2016

v0.1.0

0.1.0.0

Flexible serializer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomasz Kowalczyk

library serializer