Skip to content
Rafael Santos edited this page Jun 22, 2016 · 1 revision

Array to object conversion library. Convert a array to a object using simple and common property annotations

Basic Usage

Having the following classes:
class Team
{
    /**
     * @var string
     */
    protected $name;
    
     /**
     * @var array|Player[]
     */
    protected $players;

    //getters and setters
}

class Player
{
    /**
     * @var string
     */
    protected $name;
    
    /**
     * @var integer
     */
    protected $number;
    
    //getters and setters
}
And this array
$teamArray = [
    'name' => 'Dream Team',
    'players' =>
        [
          [
            'name' => 'Player 1',
            'number' => '1',
          ]
        ],
    ];
Can use:
    $person = Array2ObjectBuilder::create()->build()->createObject(Person::class, ['name' => 'David Smith', 'age' => '18']);
    echo $person->getName(); //David Smith
Clone this wiki locally