inpunktonet / object-flatten
This package lets you convert an object with a passed separator into a flat object and back again
Fund package maintenance!
inpunktonet
Requires
- php: ^8.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.64.0
- phpunit/phpunit: ^11.4.2
- spatie/ray: ^1.41.2
README
This is where your description should go. Try and limit it to a paragraph or two. Consider adding a small example.
Installation
You can install the package via composer:
composer require inpunktonet/object-flatten
Usage
Flatten an object
$data = [ 'company' => [ 'name' => 'InPunktoNET', 'depth' => [ 'level' => 1, 'level2' => [ 'level3' => 3, ], ], ], ]; $skeleton = new InPunktoNET\ObjectFlatten(); $skeleton->setKeyValueSeparator(';'); $skeleton->setKeySeparator('.'); echo $skeleton->toFlattenString(data: $object);
Response:
company.name;InPunktoNET company.depth.level;1 company.depth.level2.level3;3
Unflatten an object
$flattenedStrings = [ "company.name;InPunktoNET", "company.depth.level;1", "company.depth.level2.level3;3" ];
$skeleton = new InPunktoNET\ObjectFlatten(); $skeleton->setKeyValueSeparator(';'); $skeleton->setKeySeparator('.'); echo $skeleton->toObject(data: $object);
Response:
[ 'company' => [ 'name' => 'InPunktoNET', 'depth' => [ 'level' => "1", 'level2' => [ 'level3' => "3", ], ], ], ]
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.