CallbackSerializerAdapter
in package
implements
SerializerInterface
Adapts a serialization callback to SerializerInterface.
$adapter = new CallbackSerializerAdapter(static function ($value) {
return json_encode($value);
});
Tags
Table of Contents
Interfaces
- SerializerInterface
- Converts PHP values to the JSON or XML string used by structured body helpers.
Methods
- __construct() : mixed
- Store a callback that must return the serialized string.
- serialize() : string
- Serialize a value to its wire-format representation.
Methods
__construct()
Store a callback that must return the serialized string.
public
__construct(callable $callback) : mixed
$adapter = new CallbackSerializerAdapter('json_encode');
Parameters
- $callback : callable
serialize()
Serialize a value to its wire-format representation.
public
serialize(mixed $data) : string
Parameters
- $data : mixed