Repository navigation
Getting Started
github-actions[bot] edited this page Oct 5, 2026
·
1 revision
Mapping always has three steps.
StringObjects::instance() accepts an array, an object or a JSON string.
use StrObj\StringObjects;
$data = StringObjects::instance([
'user' => [
'id' => 1,
'name' => 'John Doe',
'email' => 'john.doe@example.com',
'details' => ['age' => 30, 'city' => 'New York'],
],
]);Invalid JSON or unsupported input throws InvalidArgumentException; see the
StrObj error handling guide.
The schema is an array whose keys are the keys of the result. Values that start
with @data/ are read from the source data; everything else is copied as is.
$schema = [
'userID' => '@data/user/id',
'userName' => '@data/user/name',
'userDetails' => [
'userAge' => '@data/user/details/age',
'userCity' => '@data/user/details/city',
],
'mappedAt' => date('c'),
];use Dalue\Mapper;
$result = Mapper::map($data, $schema);[
'userID' => 1,
'userName' => 'John Doe',
'userDetails' => ['userAge' => 30, 'userCity' => 'New York'],
'mappedAt' => '2026-10-05T10:00:00+00:00',
]Mapper::map(
StringObjects $data, // source data
array $schema, // result structure
?callable $callback = null, // optional value transformer
$default = null // value used for missing paths
): arrayContinue with the Schema Reference.
Dalue is licensed under GPL-3.0-or-later. Source: uuur86/dalue · Edit these pages in docs/wiki.