2017 © Pedro PelĂĄez
 

library serializer

A universal, config-less PHP serializer for all purpose.

image

remi-san/serializer

A universal, config-less PHP serializer for all purpose.

  • Tuesday, September 27, 2016
  • by remi-san
  • Repository
  • 1 Watchers
  • 3 Stars
  • 9,711 Installations
  • PHP
  • 2 Dependents
  • 2 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 6 % Grown

The README.md

Serializer

Author Build Status Quality Score Software License Packagist Version Coverage Status SensioLabsInsight, (*1)

Based on GeneratedHydrator, it serializes recursively, adding metadata to the generated array in order to be able to deserialize an object without knowing its type beforehand., (*2)

Installation

Serializer can be found on Packagist. The recommended way to install Serializer is through composer., (*3)

Run the following on the command line:, (*4)

composer require remi-san/serializer=@stable

And install dependencies:, (*5)

composer install

Usage

$classMapper = new RemiSan\Serializer\Mapper\DefaultMapper(
    new RemiSan\Serializer\NameExtractor\DefaultNameExtractor()
);
$classMapper->register(RemiSan\Serializer\Sample\MySampleClass::class);

$serializer = new RemiSan\Serializer\Serializer(
    $classMapper,
    new RemiSan\Serializer\Hydrator\HydratorFactory(__DIR__ . '/proxies', true),
    new RemiSan\Serializer\Formatter\FlatFormatter(),
    new Doctrine\Instantiator\Instantiator()
);

$object = new MySampleClass(new MySampleClass());
$serialized = $serializer->serialize($object);
$deserialized = $serializer->deserialize($serialized);

Command usage

When installing through composer, a CLI command is also made available (in vendor/bin/ or bin/ according to your composer.json):, (*6)

bin/serializer generate:cache <cache-path> <fully-qualified-class-name>

It will write the cached version of the hydrator for the requested class in the path you provided., (*7)

You'll have to generate cached files for all your serializable classes when running in production (with the generateProxies option of the HydratorFactory set to `false)., (*8)

You'll also have to make the autoloader aware of your hydrators by adding the following to your composer.json:, (*9)

{
    "autoload": {
        "classmap": [
            "/path/to/cache-dir"
        ]
    }
}

Details

To be instantiated, the Serializer needs a SerializableClassMapper, a HydratorFactory, a DataFormatter and an Instantiator., (*10)

SerializableClassMapper is used to register the classes the serializer will be able to (de-)serialize. It needs a SerializableClassNameExtractor which will be able to normalize the name of the class the way you want it., (*11)

HydratorFactory will retrieve the hydrators needed to deserialize data. It needs the path to the cache directory and whether or not, it should generate the proxies on runtime., (*12)

DataFormatter will provide the way the serialized array will be formatted (provided implementations allow it to format it as a 2-level array or a flat one with a _metadata key)., (*13)

Instantiator will allow to instantiate an object without the constructor based on the fully qualified class name of the requested object., (*14)

The Versions

24/05 2016
12/03 2016
08/03 2016

v0.2.0

0.2.0.0

A universal, configless PHP serializer for all purpose.

  Sources   Download

The Requires

 

The Development Requires

php serializer

08/03 2016

v0.1.0

0.1.0.0

A universal, configless PHP serializer for all purpose.

  Sources   Download

The Requires

 

The Development Requires

php serializer