arth/traverse

Service for manipulate path

2.0.0 2019-11-29 22:36 UTC

This package is auto-updated.

Last update: 2024-03-29 04:05:17 UTC


README

Service for get array/object deep access by string path with some separator

Installation

composer req arth/traverse

Usage

use Arth\Util\Traverse as T;

$data = ['a' => ['b' => ['c' => 'Hello', 'd' => null]]];

$svc = new T\Service('->');

$svc->has('a->b->c', $data); // true
$svc->get('a->b->c', $data); // 'Hello'

$container = new T\Container($data);
$container['a.b']; // ['c' => 'Hello']
isset($container['a.b.d']); // false

$w = new T\Wrapper($data);
$w['a']['b.c']->getValue(); // 'Hello'

See tests for more examples