hpkns/objkit

Create data objects from unstructured data

1.0.0 2024-09-12 09:11 UTC

This package is auto-updated.

Last update: 2024-11-02 12:14:11 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,
        ]
    ]
]);