oktavlachs / data-mapping-service
A type safe service, which maps raw data structures onto objects the >= PHP 8 way.
Requires
- php: >=8.0
- ext-json: *
- ext-libxml: *
- ext-simplexml: *
Requires (Dev)
- dg/bypass-finals: ~v1.4
- phpmd/phpmd: ~2.13
- phpstan/phpstan: ~1.9
- phpunit/php-code-coverage: ~9.2
- phpunit/phpunit: ~9.5
- roave/security-advisories: dev-master
- squizlabs/php_codesniffer: ~3.7
README
The PHP Data Mapping Service type safely maps raw source data onto target objects in a >= PHP 7.4 way: Your target object defines the way it expects source data to match - no need for type validation anymore. On top of that there is almost no use for annotation type hinting anymore.
Supported raw data types: array, stdClass, JSON string, XML string, SimpleXMLElement
supported target object types: mixed, scalar types (string, bool, int, float), user defined objects, stdClass, abstract classes,
arrays: This has to be specified in the target properties doc commen.
Please use the syntax: @var array<arrayKeyType, arrayElementType>
Allowed arrayKeyType -> 'string' or 'int'.
Allowed arrayElementType -> nested array, user specific objects
user specific objects in arrays: You don't have to provide the full namespace. It is fine if you use a use statement for this or (if the user object is in the same namespace as the target objects class), simply provide the short name.
This service is designed with different users in mind (exception handling)... TODO
Table of Contents
Installation
Dependencies
Stable Release
Development Version
Usage
Mappable source data types
This mapping service supports basic data types most of your use cases boil down to:
Source
- array
- stdClass
- json (string)
- xml (string)
- SimpleXmlElement
TODO: The outstanding behaviour with initialized null by mixed types !!!!!!!!!!!!!!!
CLI
Contributors
Maintainer
Others
- Matthias Bräuer (Testing and Code Reviews)
- Rick Barenthin (Testing and Code Reviews)
- Benedikt Vollmerhaus (Testing)
License
PHP Data Mapping Service is under the MIT license. See LICENSE for more information.