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
Requires
- php: >=8.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.84
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.2
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!