1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Guillermoandrae\DynamoDb\Operation; |
4
|
|
|
|
5
|
|
|
use Aws\DynamoDb\DynamoDbClient; |
6
|
|
|
use Aws\DynamoDb\Marshaler; |
7
|
|
|
use Guillermoandrae\DynamoDb\Contract\AbstractTableOperation; |
8
|
|
|
use Guillermoandrae\DynamoDb\Contract\LimitAwareOperationTrait; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @link https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-dynamodb-2012-08-10.html#listtables |
12
|
|
|
*/ |
13
|
|
|
final class ListTablesOperation extends AbstractTableOperation |
14
|
|
|
{ |
15
|
|
|
use LimitAwareOperationTrait { |
16
|
|
|
LimitAwareOperationTrait::toArray as limitAwareTraitToArray; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var string The name of the last table in the current page of results. |
21
|
|
|
*/ |
22
|
|
|
protected $lastEvaluatedTableName; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Registers the DynamoDb client and Marshaler with this object. |
26
|
|
|
* |
27
|
|
|
* @param DynamoDbClient $client The DynamoDb client. |
28
|
|
|
* @param Marshaler $marshaler The Marshaler. |
29
|
|
|
*/ |
30
|
26 |
|
public function __construct(DynamoDbClient $client, Marshaler $marshaler) |
31
|
|
|
{ |
32
|
26 |
|
$this->setClient($client); |
33
|
26 |
|
$this->setMarshaler($marshaler); |
34
|
26 |
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Registers the name of table to be used as the last in the current page of results. |
38
|
|
|
* |
39
|
|
|
* @param string $lastEvaluatedTableName The name of the last table in the current page of results. |
40
|
|
|
* @return ListTablesOperation This object. |
41
|
|
|
*/ |
42
|
1 |
|
public function setLastEvaluatedTableName(string $lastEvaluatedTableName): ListTablesOperation |
43
|
|
|
{ |
44
|
1 |
|
$this->lastEvaluatedTableName = $lastEvaluatedTableName; |
45
|
1 |
|
return $this; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* {@inheritDoc} |
50
|
|
|
*/ |
51
|
24 |
|
public function execute(): ?array |
52
|
|
|
{ |
53
|
24 |
|
$tables = $this->client->listTables($this->toArray()); |
54
|
24 |
|
return $tables['TableNames']; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* {@inheritDoc} |
59
|
|
|
*/ |
60
|
26 |
|
public function toArray(): array |
61
|
|
|
{ |
62
|
26 |
|
$query = parent::toArray(); |
63
|
26 |
|
unset($query['TableName']); |
64
|
26 |
|
if ($this->lastEvaluatedTableName) { |
65
|
1 |
|
$query['LastEvaluatedTableName'] = $this->lastEvaluatedTableName; |
66
|
|
|
} |
67
|
26 |
|
if ($this->limit) { |
68
|
1 |
|
$query += $this->limitAwareTraitToArray(); |
69
|
|
|
} |
70
|
26 |
|
return $query; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|