Class Marshaler
Marshals and unmarshals JSON documents and PHP arrays into DynamoDB items.
Methods Summary
-
__construct ( array $options = [] )
Instantiates a DynamoDB Marshaler.
-
binary ( mixed $value )
Creates a special object to represent a DynamoDB binary (B) value.
-
number ( string|int|float $value )
Creates a special object to represent a DynamoDB number (N) value.
-
set ( array $values )
Creates a special object to represent a DynamoDB set (SS/NS/BS) value.
-
marshalJson ( string $json )
Marshal a JSON document from a string to a DynamoDB item.
-
marshalItem ( array|\stdClass $item )
Marshal a native PHP array of data to a DynamoDB item.
-
marshalValue ( mixed $value )
Marshal a native PHP value into a DynamoDB attribute value.
-
unmarshalJson ( array $data, int $jsonEncodeFlags = 0 )
Unmarshal a document (item) from a DynamoDB operation result into a JSON document string.
-
unmarshalItem ( array $data, bool $mapAsObject = false )
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.
-
unmarshalValue ( array $value, bool $mapAsObject = false )
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 Details
__construct ( array $options = [] )
Instantiates a DynamoDB Marshaler.
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
array | $options = [] | Marshaler options |
Aws\DynamoDb\BinaryValue
binary (
mixed
$value
)
Creates a special object to represent a DynamoDB binary (B) value.
This helps disambiguate binary values from string (S) values.
Parameters
mixed | $value | A binary value compatible with Guzzle streams. |
Returns
Aws\DynamoDb\BinaryValue |
See
Aws\DynamoDb\NumberValue
number (
string|integer|float
$value
)
Creates a special object to represent a DynamoDB number (N) value.
This helps maintain the precision of large integer/float in PHP.
Parameters
string|integer|float | $value | A number value. |
Returns
Aws\DynamoDb\NumberValue |
Aws\DynamoDb\SetValue
set (
array
$values
)
Creates a special object to represent a DynamoDB set (SS/NS/BS) value.
This helps disambiguate set values from list (L) values.
Parameters
array | $values | The values of the set. |
Returns
Aws\DynamoDb\SetValue |
array marshalJson ( string $json )
Marshal a JSON document from a string to a DynamoDB item.
The result is an array formatted in the proper parameter structure required by the DynamoDB API for items.
Parameters
string | $json | A valid JSON document. |
Returns
array Item formatted for DynamoDB. |
Exceptions
InvalidArgumentException if the JSON is invalid. |
array marshalItem ( array|stdClass $item )
Marshal a native PHP array of data to a DynamoDB item.
The result is an array formatted in the proper parameter structure required by the DynamoDB API for items.
Parameters
array|stdClass | $item | An associative array of data. |
Returns
array Item formatted for DynamoDB. |
array marshalValue ( mixed $value )
Marshal a native PHP value into a DynamoDB attribute value.
The result is an associative array that is formatted in the proper
[TYPE => VALUE]
parameter structure required by the DynamoDB API.
Parameters
mixed | $value | A scalar, array, or stdClass value. |
Returns
array Attribute formatted for DynamoDB. |
Exceptions
UnexpectedValueException if the value cannot be marshaled. |
string unmarshalJson ( array $data, integer $jsonEncodeFlags = 0 )
Unmarshal a document (item) from a DynamoDB operation result into a JSON document string.
Parameters
array | $data | Item/document from a DynamoDB result. |
integer | $jsonEncodeFlags = 0 | Flags to use with json_encode() . |
Returns
string |
array|stdClass unmarshalItem ( array $data, boolean $mapAsObject = false )
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.
Parameters
array | $data | Item from a DynamoDB result. |
boolean | $mapAsObject = false | Whether maps should be represented as stdClass. |
Returns
array|stdClass |
mixed unmarshalValue ( array $value, boolean $mapAsObject = false )
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.
Parameters
array | $value | Value from a DynamoDB result. |
boolean | $mapAsObject = false | Whether maps should be represented as stdClass. |
Returns
mixed |
Exceptions
UnexpectedValueException |