getName() !== 'PutItem') { throw new InvalidArgumentException(); } // Get relevant data for a PutRequest $table = $command->get('TableName'); $item = $command->get('Item'); // Create an Item object from the 'item' command data if (!($item instanceof Item)) { $item = new Item($item, $table); } // Return an instantiated PutRequest object return new PutRequest($item, $table); } /** * Constructs a new put request * * @param Item $item The item to put into DynamoDB * @param string $tableName The name of the table which has the item * * @throw InvalidArgumentException if the table name is not provided */ public function __construct(Item $item, $tableName = null) { $this->item = $item; $this->tableName = $tableName ?: $item->getTableName(); if (!$this->tableName) { throw new InvalidArgumentException('A table name is required to create a PutRequest.'); } } /** * The parameter form of the request * * @return array */ public function toArray() { return array('PutRequest' => array('Item' => $this->item->toArray())); } /** * Get the item * * @return Item */ public function getItem() { return $this->item; } }