Installation guide

echo "Results received. {$requestCount} request(s) made so far.\n";
});
foreach ($iterator as $object) {
echo $object['Key'] . "\n";
}
Modeled Responses
Introduction
The result of a performing an operation is what we refer to as a modeled response. Instead of returning the raw
XML or JSON data, the SDK will coerce the data into an associative array and normalize some aspects of the data
based on its knowledge of the specific service and the underlying response structure.
The actual value returned is a Model (Guzzle\Service\Resource\Model) object. The Model class is a part of
the SDK's underlying Guzzle library, but you do not need to know anything about Guzzle to use your operation
results. The Model object contains the data from the response and can be used like an array (e.g.,
$result['Table']). It also has convenience methods like get(), getPath(), and toArray(). The contents of
the modeled response depend on the operation that was executed and are documented in the API docs for each
operation (e.g., see the Returns section in the API docs for the DynamoDB DescribeTable operation).
$result = $dynamoDbClient->describeTable(array(
'TableName' => 'YourTableName',
));
// Get a specific value from the result
$table = $result['Table'];
if ($table && isset($table['TableStatus'])) {
echo $table['TableStatus'];
}
//> ACTIVE
// Get nested values from the result easily
echo $result->getPath('Table/TableStatus');
//> ACTIVE
// Convert the Model to a plain array
var_export($result->toArray());
//> array ( 'Table' => array ( 'AttributeDefinitions' => array ( ... ) ... ) ... )
Working with Model objects
Model objects (and Command objects) inherit from the Guzzle Collection class and implement PHP's native
ArrayAccess, IteratorAggregate, and Countable interfaces. This means that they behave like arrays when
you are accessing keys and iterating over key-value pairs. You can also use the toArray() method of the Model
object to get the array form directly.
However, model objects will not throw errors on undefined keys, so it's safe to use values directly without doing
isset() checks. It the key doesn't exist, then the value will be returned as null.
// Use an instance of S3Client to get an object
$result = $s3Client->getObject(array(
'Bucket' => 'my-bucket',
'Key' => 'test.txt'
));
// Using a value that may not exist
if (!$result['ContentLength']) {
echo "Empty file.";
Modeled Responses
37