2017 © Pedro Peláez
 

library lib-array2object

Array to object conversion library

image

rafrsr/lib-array2object

Array to object conversion library

  • Thursday, June 7, 2018
  • by rafrsr
  • Repository
  • 1 Watchers
  • 3 Stars
  • 6,880 Installations
  • PHP
  • 5 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 10 Versions
  • 9 % Grown

The README.md

lib-array2object

Build Status Coverage Status Scrutinizer Code Quality Latest Stable Version Latest Unstable Version Total Downloads License, (*1)

SensioLabsInsight, (*2)

Array to object conversion library. Convert a array to a object using simple and common property annotations, (*3)

Installation

  1. Install composer
  2. Execute: composer require rafrsr/lib-array2object

Usage

Only need the class with common annotations, (*4)

<?php

class Player
{
    /** @var string */
    protected $name;

   /** @var integer */
    protected $number;

   //setters and getters here
}

To use:, (*5)

$phpArray = ['name' => 'David', 'number' => '1'];
$object = Array2ObjectBuilder::create()->build()->createObject(Player::class, $phpArray);
echo $object->getName();//David
echo $object->getNumber();//1

$array = Object2ArrayBuilder::create()->build()->createArray($object);
echo $array['name'];//David
echo $array['number'];//1

Serialization

This library can be used to serialize/deserialize objects without a complex configuration., (*6)

Json
//deserialize
$json = '{"name":"David","number"=>"1"}';
$object = Array2ObjectBuilder::create()->build()->createObject(Team::class, json_decode($json, true));
echo $object->getName()//David

//serialize
$array = Object2ArrayBuilder::create()->build()->createArray($object);
echo json_encode($array); // {"name":"David","number"=>"1"}
Xml

Using the library rafrsr/lib-array2xml is very handy convert from/to xml, (*7)

//deserialize
$xml = '<Player><name>Player 1</name><number>1</number></Player>';
$object = Array2ObjectBuilder::create()->build()->create(Team::class, XML2Array::createArray($xml));
echo $object->getName()//David

//serialize
$array = Object2ArrayBuilder::create()->build()->createArray($object);
echo Array2XML::createXml('Player', $array); //  '<Player><name>Player 1</name><number>1</number></Player>'

This library its handy to use and has some advanced configuration, but in some cases (need groups, versions and other stuffs) is required use advanced libraries like jms/serializer, (*8)

Documentation

Full documentation are available on the wiki page, (*9)

This project is licensed under the MIT license., (*10)

The Versions

07/06 2018

dev-master

9999999-dev

Array to object conversion library

  Sources   Download

MIT

The Requires

 

The Development Requires

07/06 2018

v1.0.7

1.0.7.0

Array to object conversion library

  Sources   Download

MIT

The Requires

 

The Development Requires

24/05 2018

v1.0.6

1.0.6.0

Array to object conversion library

  Sources   Download

MIT

The Requires

 

The Development Requires

29/06 2016

v1.0.5

1.0.5.0

Array to object conversion library

  Sources   Download

MIT

The Requires

 

The Development Requires

28/06 2016

v1.0.4

1.0.4.0

Array to object conversion library

  Sources   Download

MIT

The Requires

 

The Development Requires

27/06 2016

v1.0.3

1.0.3.0

Array to object conversion library

  Sources   Download

MIT

The Requires

 

The Development Requires

24/06 2016

v1.0.2

1.0.2.0

Array to object conversion library

  Sources   Download

MIT

The Requires

 

The Development Requires

23/06 2016

v1.0.0

1.0.0.0

Array to object conversion library

  Sources   Download

MIT

The Requires

 

The Development Requires

23/06 2016

v1.0.1

1.0.1.0

Array to object conversion library

  Sources   Download

MIT

The Requires

 

The Development Requires

23/06 2016

v1.0.0-alpha

1.0.0.0-alpha

Array to object conversion library

  Sources   Download

MIT

The Requires

 

The Development Requires