kasperhansen/dot-array-mapper

Mapping array data using dot notation.

Installs: 172

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/kasperhansen/dot-array-mapper

1.1.0 2025-08-10 18:30 UTC

This package is auto-updated.

Last update: 2026-01-10 19:34:09 UTC


README

Mapping array data using dot notation.

Installation

composer require kasperhansen/dot-array-mapper

Usage

use Kasperhansen\DotArrayMapper;

$mapper = new DotArrayMapper();

// Set the data to be mapped
$mapper
    ->setData([
        'user' => [
            'name' => 'John Doe',
            'email' => 'john@doe.com',
            'address' => [
                'city' => 'New York',
            ],
        ],
    ])
    ->map([
        'name' => 'user.name',
        'email' => 'user.email',
        'city' => 'user.address.city',
    ])
    ->addFilter('name', fn($value) => strtoupper($value))
    ->addFilter('email', fn($value) => strtolower($value));

// Extract the mapped data
$mappedData = $mapper->extract();

// Output the mapped data
echo $mappedData['name']; // John Doe
echo $mappedData['email']; // john@doe.com
echo $mappedData['city']; // New York

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome!