Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

2 Commits

Repository files navigation

ObjectPath Build Status

Allows traversal of objects and arrays with a simple string syntax. Extracted from Peridot's matcher library: Leo.

Usage

$data = [
'name' => 'Brian',
'hobbies' => [
'reading',
'programming',
'lion taming' ],
'address' => [
'street' => '1234 Lane',
'zip' => '12345' ]
];
usePeridot\ObjectPath\ObjectPath;
$path = newObjectPath($data);
$reading = $path->get('hobbies[0]');
$zip = $path->get('address[zip]');
// the result of get() is an ObjectPathValue instance$value = $reading->getPropertyValue();
// The syntax also works for objects and nested structures$data = newstdClass();
$data->name = 'Brian';
$data->address = newstdClass();
$data->address->zip = '12345';
$hobby = newstdClass();
$hobby->name = 'reading';
$hobby->style = 'relaxing';
$data->hobbies = [$hobby];
$path = newObjectPath($data);
$name = $path->get('name');
$zip = $path->get('address->zip');
$reading = $path->get('hobbies[0]->name');

Tests

$ composer install
$ vendor/bin/peridot specs/

About

A string syntax to fetch values from array and object hierarchies

Resources

Stars

10 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages