Download the PHP package kingson-de/marshal-serializer without Composer
On this page you can find all versions of the php package kingson-de/marshal-serializer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kingson-de/marshal-serializer
More information about kingson-de/marshal-serializer
Files in kingson-de/marshal-serializer
Package marshal-serializer
Short Description Marshal is serializing / marshalling data structures to a format that can be used to build messages for transferring data through the wires.
License Apache-2.0
Informations about the package marshal-serializer
Marshal Serializer
Introduction
Marshal is serializing / marshalling data structures to the desired format. It is also deserializing / unmarshalling the format back to the data structures.
Especially useful for building the raw response for web services which then can be formatted to JSON for example.
If you need to serialize directly to a format, use the appropriate Marshal library:
Installation
Easiest way to install the library is via composer:
The following PHP versions are supported:
- PHP 7.0
- PHP 7.1
- PHP 7.2
- PHP 7.3
Execute tests
Just run:
Or without code coverage:
Usage
Mappers
The first thing to do is to create a mapper that takes care of mapping your entities / models to the correct format.
You always need to inherit from the abstract Mapper class and implement a map
function with your type hinting.
There is also the option to use directly a callable to map data. This will be explained later.
It is always possible to use a callable in a mapper or vice versa.
Data Structures
Next step is to create the desired data structure either being an item/object or a collection.
Item/Object
Collection
Serializing / Marshalling
The final step is to map the data structures to the actual format.
You are also not forced to create data structures on your own, you can use the appropriate Marshal functions instead:
Symfony Example
Advanced Mappers
Nested Data Structures
Mappers can even include other mappers with different data structures.
Therefore you can use item
, itemCallable
, collection
or collectionCallable
function from the AbstractMapper class.
Pass as many parameters as you like to the mappers
For collections the first parameter passed is the one which Marshal will use for iterating.
All other parameters in a collection will stay as it is.
For items/objects all parameters retain.
Filter out single item's from the collection
Collection mappers can discard single item's by returning null
.
Deserializing / Unmarshalling
To transform the actual format back to your structure use Marshal's deserialize functions. You need a class extending the AbstractObjectMapper which will be passed to the deserialize function.
Another option would be to use the deserializeCallable function.
License
This project is released under the terms of the Apache 2.0 license.