Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions DynamoDBWrapper.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
<?php

// Taken from https://github.com/masayuki0812/dynamodb-php-wrapper

use Aws\DynamoDb\DynamoDbClient;
use Aws\DynamoDb\Exception\ConditionalCheckFailedException;

class DynamoDBWrapper
{
protected $client;

public function __construct($args)
public function __construct($args = NULL)
{
if (!empty($args))
{
$this->client = DynamoDbClient::factory($args);
}
}

public static function createFromClient($client)
{
$dyn = new DynamoDBWrapper();
$dyn->client = $client;

return $dyn;
}

public function get($tableName, $key, $options = array())
Expand Down Expand Up @@ -117,7 +130,7 @@ public function count($tableName, $keyConditions, $options = array())
public function scan($tableName, $filter, $limit = null)
{
if (empty($filter)) {
$scanFilter = null;
$scanFilter = array();
} else {
$scanFilter = $this->convertConditions($filter);
}
Expand Down Expand Up @@ -212,9 +225,13 @@ protected function batchWrite($requestType, $tableName, $items)
));

// if some items not processed, try again as next request
$unprocessedRequests = $result->getPath("UnprocessedItems/{$tableName}");
if (count($unprocessedRequests) > 0) {
$requests = array_merge($requests, $unprocessedRequests);
$unprocessedItems = $result->getPath("UnprocessedItems");
if ($unprocessedItems && count($unprocessedItems) > 0)
{
$unprocessedRequests = $result->getPath("UnprocessedItems/{$tableName}");
if (count($unprocessedRequests) > 0) {
$requests = array_merge($requests, $unprocessedRequests);
}
}
}

Expand Down Expand Up @@ -442,7 +459,7 @@ protected function convertItems($items)

/**
* convert string attribute paramter to array components.
*
*
* @param string $attribute double colon separated string "<Attribute Name>::<Attribute type>"
* @return array parsed parameter. [0]=<Attribute Name>, [1]=<Attribute type>
*/
Expand Down