Skip to content

Serialize any object into array and bind any data structure to an object/array; Can (de)serialize into JSON or XML.

License

Notifications You must be signed in to change notification settings

byjg/php-serializer

Repository files navigation

Serializer

Scrutinizer Code Quality Code Coverage SensioLabsInsight Build Status

Serialize any object into array and format it JSON or XML

Basic Usage

Just use the Serializer class with any kind of object, stdClass or array;

$serializer = new \ByJG\Serializer\SerializerObject($data);
$result = $object->build();

$result is an array. You can use a Formatter to transform it in JSON or XML.

Formatting the Output with a formatter

$serializer = new \ByJG\Serializer\SerializerObject($data);
$result = $object->build();

echo (new JsonFormatter())->process($result);
echo (new XmlFormatter())->process($result);

Create a bindable object

// Create the class
class MyClass extends BinderObject
{}

// Bind any data into the properties of myclass
$myclass->bind($data);

// You can convert to array all properties
$myclass->toArray();

or

// Set all properties from $source that matches with the property in $target
BinderObject::bindObject($source, $target);

// Convert all properties of any object into array
BinderObject::toArrayFrom($source);

Install

composer require "byjg/serialize=1.0.*"

Test

phpunit

About

Serialize any object into array and bind any data structure to an object/array; Can (de)serialize into JSON or XML.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages