setConfig($config) ->setConfigDefaults(array( // DynamoDB does not use redirects self::DISABLE_REDIRECTS => true, Options::VERSION => self::LATEST_API_VERSION, Options::SERVICE_DESCRIPTION => __DIR__ . '/Resources/dynamodb-%s.php', // DynamoDB does not require response processing other than turning JSON into an array self::COMMAND_PARAMS => array(Cmd::RESPONSE_PROCESSING => Cmd::TYPE_NO_TRANSLATION) )) ->setExceptionParser($exceptionParser) ->setIteratorsConfig(array( 'result_key' => 'Items', 'token_param' => 'ExclusiveStartKey', 'token_key' => 'LastEvaluatedKey', 'operations' => array( 'BatchGetItem' => array( 'token_param' => 'RequestItems', 'token_key' => 'UnprocessedKeys', ), 'ListTables' => array( 'result_key' => 'TableNames', 'token_param' => 'ExclusiveStartTableName', 'token_key' => 'LastEvaluatedTableName', ), 'Query', 'Scan', ) )) ->build(); } /** * Formats a value as a DynamoDB attribute. * * @param mixed $value The value to format for DynamoDB. * @param string $format The type of format (e.g. put, update). * * @return array The formatted value. */ public function formatValue($value, $format = Attribute::FORMAT_PUT) { return Attribute::factory($value)->getFormatted($format); } /** * Formats an array of values as DynamoDB attributes. * * @param array $values The values to format for DynamoDB. * @param string $format The type of format (e.g. put, update). * * @return array The formatted values. */ public function formatAttributes(array $values, $format = Attribute::FORMAT_PUT) { $formatted = array(); foreach ($values as $key => $value) { $formatted[$key] = $this->formatValue($value, $format); } return $formatted; } /** * Calculate the amount of time needed for an exponential backoff to wait * before retrying a request * * @param int $retries Number of retries * * @return float Returns the amount of time to wait in seconds */ public static function calculateRetryDelay($retries) { return $retries == 0 ? 0 : (50 * (int) pow(2, $retries - 1)) / 1000; } /** * Convenience method for instantiating and registering the DynamoDB * Session handler with this DynamoDB client object. * * @param array $config Array of options for the session handler factory * * @return SessionHandler */ public function registerSessionHandler(array $config = array()) { $config = array_replace(array('dynamodb_client' => $this), $config); $handler = SessionHandler::factory($config); $handler->register(); return $handler; } }