2017 © Pedro Peláez
 

library simple-serializer

Simple Serializer

image

opensoft/simple-serializer

Simple Serializer

  • Thursday, September 10, 2015
  • by fightmaster
  • Repository
  • 4 Watchers
  • 18 Stars
  • 10,554 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 9 Forks
  • 2 Open issues
  • 11 Versions
  • 2 % Grown

The README.md

Simple-Serializer

Build Status Total Downloads Latest Stable Version Scrutinizer Quality Score SensioLabsInsight, (*1)

Introduction

Simple-Serializer allows you to serialize your objects into a requested output format such as JSON. The library is written to work with DTO objects in the REST services., (*2)

Built-in features include:, (*3)

  • (de-)serialize object graphs
  • supports boolean, integer, double, DateTime<format>, array, T, array<T>, null types, where "T" - is some PHP object.
  • configurable via YAML
  • three unserialize mode (non-strict, medium strict, strict)

Unserialize mode: Non-Strict mode - serializer does not check incoming parameters Medium Strict - serializer extra check incoming parameters and if they exist throw InvalidArgumentException Strict - serializer extra check incoming parameters completely as expected if there are extra arguments or missing some, it throws an exception., (*4)

Some Restrictions:, (*5)

  • object must have configuration for serialize/unserialize

Possible TODO list:, (*6)

  • (de-)serialize object graphs of any complexity including circular references
  • configurable via PHP, XML, or annotations
  • custom integrates with Doctrine ORM, et. al.

It should be noted that Simple-Serializer is realy simple library with minimum configuration, but it provides wide opportunity for create REST API., (*7)

Build Status, (*8)

Installation

To install Simple-Serializer with Composer just add the following to your composer.json file:, (*9)

    // composer.json
    {
        // ...
        require: {
            // ...
            "opensoft/simple-serializer": "dev-master"
        }
    }

Then, you can install the new dependencies by running Composer's update command from the directory where your composer.json file is located:, (*10)

$ php composer.phar update

Configuration

MyBundle\Resources\config\serializer\ClassName.yml
    Fully\Qualified\ClassName:
        properties:
            some-property:
                expose: true
                type: string
                serialized_name: foo
                since_version: 1.0
                until_version: 2.0
                groups: ['get','patch']
  • expose
    • true
    • false (default)
  • type
    • integer
    • boolean
    • double
    • string
    • array
    • T - fully qualified class name
    • array<T>
    • DateTime
    • DateTime<format>
    • format could be name of DateTime constant (COOKIE, ISO8601), string or empty (default format is ISO8601)
  • serialized_name
    • default value is equal name property
  • since_version
    • string
  • until_version
    • string
  • groups
    • array
  • null_skipped
    • true
    • false (default)

Serializing Objects

Most common usage is probably to serialize objects. This can be achieved very easily:, (*11)

    <?php
    //get Serializer
    $serializer = $this->getSerializer();
    $string = $serializer->serialize($object);
    //Serialize array of the objects
    $string = $serializer->serialize(array($object));
    //Serialize specific groups
    $serializer->setGroups(array('get'));
    $string = $serializer->serialize($object);
    //Serialize specific version
    $serializer->setVersion('1.0');
    $string = $serializer->serialize($object);

Deserializing Objects

You can also unserialize objects from JSON representation. For example, when accepting data via an API., (*12)

    <?php
    //get Fully\Qualified\ClassName
    $object = $this->getClassName();
    //get Serializer
    $serializer = $this->getSerializer();
    $object = $serializer->unserialize($jsonData, $object);
    //Unserialize array of the objects
    $objects = $serializer->unserialize($jsonData, array($object));
    //Unserialize specific groups
    $serializer->setGroups(array('get'));
    $object = $serializer->unserialize($jsonData, $object);
    //Unserialize specific version
    $serializer->setVersion('1.0');
    $object = $serializer->unserialize($jsonData, $object);
    //Strict unserialize mode
    $serializer->setStrictUnserializeMode(2);
    $object = $serializer->unserialize($jsonData, $object);
    //Medium Strict unserialize mode
    $serializer->setStrictUnserializeMode(1);
    $object = $serializer->unserialize($jsonData, $object);
    //Non-Strict unserialize mode
    $serializer->setStrictUnserializeMode(0);
    $object = $serializer->unserialize($jsonData, $object);

The Versions

10/09 2015

dev-master

9999999-dev http://github.com/opensoft/simple-serializer

Simple Serializer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Petrov

php json serializer

10/09 2015

1.1.1

1.1.1.0 http://github.com/opensoft/simple-serializer

Simple Serializer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Petrov

php json serializer

08/09 2014

dev-develop

dev-develop http://github.com/opensoft/simple-serializer

Simple Serializer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Petrov

php json serializer

28/08 2014

1.1

1.1.0.0 http://github.com/opensoft/simple-serializer

Simple Serializer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Petrov

php json serializer

01/08 2014

1.0.6

1.0.6.0 http://github.com/opensoft/simple-serializer

Simple Serializer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Petrov

php json serializer

02/06 2014

1.0.5

1.0.5.0 http://github.com/opensoft/simple-serializer

Simple Serializer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Petrov

php json serializer

05/05 2014

1.0.4

1.0.4.0 http://github.com/opensoft/simple-serializer

Simple Serializer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Petrov

php json serializer

25/04 2014

1.0.3

1.0.3.0 http://github.com/opensoft/simple-serializer

Simple Serializer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Petrov

php json serializer

03/02 2014

1.0.2

1.0.2.0 http://github.com/opensoft/php-fedex

Simple Serializer

  Sources   Download

MIT

The Requires

 

by Dmitry Petrov

php json serializer

18/02 2013

1.0.1

1.0.1.0 http://github.com/opensoft/php-fedex

Simple Serializer

  Sources   Download

MIT

The Requires

 

by Dmitry Petrov

php json serializer

15/12 2012

1.0.0

1.0.0.0 http://github.com/opensoft/php-fedex

Simple Serializer

  Sources   Download

MIT

The Requires

 

by Dmitry Petrov

php json serializer