hpkns/objkit

Create data objects from unstructured data

0.1.4 2024-09-12 09:11 UTC

This package is auto-updated.

Last update: 2024-09-12 09:12:43 UTC


README

Create data objects from unstructured data

Installation

Simply get it from composer:

composer require hpkns/gadget

Usage

use Hpkns\Objkit\Attributes\ArrayOf;
use Hpkns\Objkit\Buildable;
use Hpkns\Objkit\ObjectBuilder;

class Person {
    use Buildable;
    
    public function __construct(
        readonly string $name,
        readonly int    $age,
        #[ArrayOf(Person)]
        readonly array  $parents = [],
    ) {
        //
    }
}

$jedi = Person::build([
    'name' => 'Luke',
    'age' => '19',
    'parents' => [
        [
            'name' => 'Anakin', 
            'age' => 41,
        ]
    ]
]);