Marshaler
in package
Marshals and unmarshals JSON documents and PHP arrays into DynamoDB items.
Table of Contents
Methods
- __construct() : mixed
- Instantiates a DynamoDB Marshaler.
- binary() : BinaryValue
- Creates a special object to represent a DynamoDB binary (B) value.
- marshalItem() : array<string|int, mixed>
- Marshal a native PHP array of data to a DynamoDB item.
- marshalJson() : array<string|int, mixed>
- Marshal a JSON document from a string to a DynamoDB item.
- marshalValue() : array<string|int, mixed>
- Marshal a native PHP value into a DynamoDB attribute value.
- number() : NumberValue
- Creates a special object to represent a DynamoDB number (N) value.
- set() : SetValue
- Creates a special object to represent a DynamoDB set (SS/NS/BS) value.
- unmarshalItem() : array<string|int, mixed>|stdClass
- Unmarshal an item from a DynamoDB operation result into a native PHP array. If you set $mapAsObject to true, then a stdClass value will be returned instead.
- unmarshalJson() : string
- Unmarshal a document (item) from a DynamoDB operation result into a JSON document string.
- unmarshalValue() : mixed
- Unmarshal a value from a DynamoDB operation result into a native PHP value. Will return a scalar, array, or (if you set $mapAsObject to true) stdClass value.
Methods
__construct()
Instantiates a DynamoDB Marshaler.
public
__construct([array<string|int, mixed> $options = [] ]) : mixed
The following options are valid.
- ignore_invalid: (bool) Set to
true
if invalid values should be ignored (i.e., not included) during marshaling. - nullify_invalid: (bool) Set to
true
if invalid values should be set to null. - wrap_numbers: (bool) Set to
true
to wrap numbers withNumberValue
objects during unmarshaling to preserve the precision.
Parameters
- $options : array<string|int, mixed> = []
-
Marshaler options
binary()
Creates a special object to represent a DynamoDB binary (B) value.
public
binary(mixed $value) : BinaryValue
This helps disambiguate binary values from string (S) values.
Parameters
- $value : mixed
-
A binary value compatible with Guzzle streams.
Tags
Return values
BinaryValuemarshalItem()
Marshal a native PHP array of data to a DynamoDB item.
public
marshalItem(array<string|int, mixed>|stdClass $item) : array<string|int, mixed>
The result is an array formatted in the proper parameter structure required by the DynamoDB API for items.
Parameters
- $item : array<string|int, mixed>|stdClass
-
An associative array of data.
Return values
array<string|int, mixed> —Item formatted for DynamoDB.
marshalJson()
Marshal a JSON document from a string to a DynamoDB item.
public
marshalJson(string $json) : array<string|int, mixed>
The result is an array formatted in the proper parameter structure required by the DynamoDB API for items.
Parameters
- $json : string
-
A valid JSON document.
Tags
Return values
array<string|int, mixed> —Item formatted for DynamoDB.
marshalValue()
Marshal a native PHP value into a DynamoDB attribute value.
public
marshalValue(mixed $value) : array<string|int, mixed>
The result is an associative array that is formatted in the proper
[TYPE => VALUE]
parameter structure required by the DynamoDB API.
Parameters
- $value : mixed
-
A scalar, array, or
stdClass
value.
Tags
Return values
array<string|int, mixed> —Attribute formatted for DynamoDB.
number()
Creates a special object to represent a DynamoDB number (N) value.
public
number(string|int|float $value) : NumberValue
This helps maintain the precision of large integer/float in PHP.
Parameters
- $value : string|int|float
-
A number value.
Return values
NumberValueset()
Creates a special object to represent a DynamoDB set (SS/NS/BS) value.
public
set(array<string|int, mixed> $values) : SetValue
This helps disambiguate set values from list (L) values.
Parameters
- $values : array<string|int, mixed>
-
The values of the set.
Return values
SetValueunmarshalItem()
Unmarshal an item from a DynamoDB operation result into a native PHP array. If you set $mapAsObject to true, then a stdClass value will be returned instead.
public
unmarshalItem(array<string|int, mixed> $data[, bool $mapAsObject = false ]) : array<string|int, mixed>|stdClass
Parameters
- $data : array<string|int, mixed>
-
Item from a DynamoDB result.
- $mapAsObject : bool = false
-
Whether maps should be represented as stdClass.
Return values
array<string|int, mixed>|stdClassunmarshalJson()
Unmarshal a document (item) from a DynamoDB operation result into a JSON document string.
public
unmarshalJson(array<string|int, mixed> $data[, int $jsonEncodeFlags = 0 ]) : string
Parameters
- $data : array<string|int, mixed>
-
Item/document from a DynamoDB result.
- $jsonEncodeFlags : int = 0
-
Flags to use with
json_encode()
.
Return values
stringunmarshalValue()
Unmarshal a value from a DynamoDB operation result into a native PHP value. Will return a scalar, array, or (if you set $mapAsObject to true) stdClass value.
public
unmarshalValue(array<string|int, mixed> $value[, bool $mapAsObject = false ]) : mixed
Parameters
- $value : array<string|int, mixed>
-
Value from a DynamoDB result.
- $mapAsObject : bool = false
-
Whether maps should be represented as stdClass.