davek1312/serialise

Trait to serialise/deserialise objects using jms/serializer

v0.3.3 2017-02-25 00:54 UTC

This package is auto-updated.

Last update: 2024-10-14 19:41:37 UTC


README

Serialise/Deserialise objects using the jms/serializer package.

Installation

The package is available on Packagist, you can install it using Composer.

composer require davek1312/serialise

Configuration

Add the traits to the model you want to serialise/deserialise

use Davek1312\Serialise\Traits\Serialise;
use Davek1312\Serialise\Traits\Deserialise;
use Davek1312\Serialise\Traits\Common;

Or extend from the base serialise model that uses these traits

class YourClass extends Davek1312\Serialise\Models\BaseSerialiseModel

Annotate your model using the JMS annotations.

Usage

Serialise

#JSON
->serialiseToJson();
->serialise(Utils::DATA_TYPE_JSON);

#XML
->serialiseToXml();
->serialise(Utils::DATA_TYPE_XML);

#Array
->serialiseToArray();
->serialise(Utils::DATA_TYPE_ARRAY);

#YAML
->serialiseToYaml();
->serialise(Utils::DATA_TYPE_YAML);

#Errors
->hasSerialiseError();
->getSerialiseException();

Deserialise

#JSON
::deserialiseJson();
::deserialise($json, Utils::DATA_TYPE_JSON);

#XML
::deserialiseXml();
::deserialise($xml, Utils::DATA_TYPE_XML);

#Array
::deserialiseArray();
::deserialise($array, Utils::DATA_TYPE_ARRAY);

#Errors
->hasDeserialiseError();
->getDeserialiseException();