|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Guillermoandrae\DynamoDb\Operation; |
|
4
|
|
|
|
|
5
|
|
|
use Aws\DynamoDb\DynamoDbClient; |
|
6
|
|
|
use Aws\DynamoDb\Exception\DynamoDbException; |
|
7
|
|
|
use Aws\DynamoDb\Marshaler; |
|
8
|
|
|
use Guillermoandrae\Common\Collection; |
|
9
|
|
|
use Guillermoandrae\Common\CollectionInterface; |
|
10
|
|
|
use Guillermoandrae\DynamoDb\Contract\AbstractSearchOperation; |
|
11
|
|
|
use Guillermoandrae\DynamoDb\Exception; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @link https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-dynamodb-2012-08-10.html#scan |
|
15
|
|
|
*/ |
|
16
|
|
|
final class ScanOperation extends AbstractSearchOperation |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* Registers the DynamoDb client, Marshaler, and table name with this object. |
|
20
|
|
|
* |
|
21
|
|
|
* @param DynamoDbClient $client The DynamoDb client. |
|
22
|
|
|
* @param Marshaler $marshaler The Marshaler. |
|
23
|
|
|
* @param string $tableName The table name. |
|
24
|
|
|
*/ |
|
25
|
3 |
|
public function __construct(DynamoDbClient $client, Marshaler $marshaler, string $tableName) |
|
26
|
|
|
{ |
|
27
|
3 |
|
$this->setClient($client); |
|
28
|
3 |
|
$this->setMarshaler($marshaler); |
|
29
|
3 |
|
$this->setTableName($tableName); |
|
30
|
3 |
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* {@inheritDoc} |
|
34
|
|
|
*/ |
|
35
|
3 |
|
public function execute(): CollectionInterface |
|
36
|
|
|
{ |
|
37
|
|
|
try { |
|
38
|
3 |
|
$results = $this->client->scan($this->toArray()); |
|
39
|
2 |
|
$rows = []; |
|
40
|
2 |
|
foreach ($results['Items'] as $item) { |
|
41
|
1 |
|
$rows[] = $this->marshaler->unmarshalItem($item); |
|
42
|
|
|
} |
|
43
|
2 |
|
return Collection::make($rows); |
|
44
|
1 |
|
} catch (DynamoDbException $ex) { |
|
45
|
1 |
|
throw new Exception($ex->getMessage()); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|