getName() !== 'PutItem') { throw new InvalidArgumentException(); } // Get relevant data for a PutRequest $table = $command->get('TableName'); $item = $command->get('Item'); // Return an instantiated PutRequest object return new PutRequest($item, $table); } /** * Constructs a new put request * * @param array|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, $tableName = null) { if ($item instanceof Item) { $this->item = $item->toArray(); $this->tableName = $tableName ?: $item->getTableName(); } elseif (is_array($item)) { $this->item = $item; $this->tableName = $tableName; } else { throw new InvalidArgumentException('The item must be an array or an Item object.'); } 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)); } /** * Get the item * * @return Item */ public function getItem() { return new Item($this->item); } }