Skip to content
/ trunk Public

🪵 A safe way to query data from a PHP array inspired by SwiftyJSON

License

Notifications You must be signed in to change notification settings

giann/trunk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Trunk

A safe way to query data from a PHP array inspired by SwiftyJSON

$trunk = new Trunk($data);

$this->assertTrue($trunk['astring'] instanceof Trunk);
$this->assertEquals($trunk['astring']->string(), 'hello world');

$this->assertEquals($trunk['anint']->int(), 12);

$this->assertEquals($trunk['alist']->listValue()[3]->string(), 'hello');

$this->assertEquals($trunk['amap']['hello']->string(), 'world');

$this->assertEquals($trunk['amap']['hello']['doesnexists']->data, null);

$this->assertTrue($trunk['anobject']->ofClass(Person::class) instanceof Person);
$this->assertEquals($trunk['anobject']->ofClass(Person::class)->name, 'joe');

$this->assertTrue($trunk['listofobject']->listOfClass(Person::class)[0] instanceof Person);
$this->assertEquals($trunk['listofobject']->listOfClass(Person::class)[0]->name, 'joe');

$this->assertTrue($trunk['mapofobject']->mapOfClass(Person::class)['joe'] instanceof Person);
$this->assertEquals($trunk['mapofobject']->mapOfClass(Person::class)['joe']->name, 'joe');

$this->assertTrue(
    $trunk['transformlist']
        ->listOfClass(
            Person::class,
            fn ($el) => new Person($el)
        )[0] instanceof Person
);

$this->assertTrue(
    $trunk['transformmap']
        ->mapOfClass(
            Person::class,
            fn ($el) => new Person($el)
        )['joe'] instanceof Person
);

About

🪵 A safe way to query data from a PHP array inspired by SwiftyJSON

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages