Download the PHP package alexrili/phmap without Composer
On this page you can find all versions of the php package alexrili/phmap. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download alexrili/phmap
More information about alexrili/phmap
Files in alexrili/phmap
Package phmap
Short Description Payload maps and transform. From A structure to B structure
License MIT
Homepage https://github.com/alexrili/phmap
Informations about the package phmap
Phmap
This is just a payload map written in php. This lib helps you to get values from A structure and put it on B struscture
Note: Phmap uses illuminate/support
under the hood. If you are using laravel or lumen framework, make sure that you version is >= 9.x, if you're not using any of these frameworks or this dependency(illuminate/support) , than you have nothing to worry about.
Install
Via Composer
Basic usage
Under the hood we provide a payload_map()
helper function.
The payload_map()
accpets two arguments: 1º is your input data, 2º is your map config.
Both needs to be array type.
Let`s see the example bellow.
Now let's imagine that you have a multliple values from an array and needs to change the inside properties. With Phmap you can do that :)
Notice: The
mainAddress
property was not in the new payload, this is happening because we're not tells the payload map to map that
Map configs
Direct values
you can map a value from a direct path in your structure just point where the values are in from key and point the destination path within to key
Concatanated values
you can concatanate one or more values using the
.+.
symbol
Fixed values
you can add some fixed values using the
__()__
symbol
Collection(array) of values
you can map a nested property inside an array using the
.*.
symbol
One Or Antoher value
you can map two(or more) direferente paths to bring a value, then the phmap will go through all the paths until it finds a value. To make one or another value, you can use
||
symbol
Nullable values
you may need to map some properties that has a null value, for that you just need to pass a string flag called
nullable
with one of this two values ["true"
|"false"
], if trues, means you want to bring this property to you new structure even if their value is null.Default value is
"false"
Advanced usage
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
Contributing
Please see CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please email alexrili instead of using the issue tracker.
Credits
- [Alex Ribeiro][link-author]
- [All Contributors][link-contributors]
License
The MIT License (MIT). Please see License File for more information.
All versions of phmap with dependencies
ext-json Version *
alexrili/vephar Version ^2.0
illuminate/support Version >=9