|
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
|
|
|
* ListTables operation. |
|
12
|
|
|
* |
|
13
|
|
|
* @author Guillermo A. Fisher <[email protected]> |
|
14
|
|
|
* @link https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-dynamodb-2012-08-10.html#listtables |
|
15
|
|
|
*/ |
|
16
|
|
|
final class ListTablesOperation extends AbstractTableOperation |
|
17
|
|
|
{ |
|
18
|
|
|
use LimitAwareOperationTrait { |
|
19
|
|
|
LimitAwareOperationTrait::toArray as limitAwareTraitToArray; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var string The name of the last table in the current page of results. |
|
24
|
|
|
*/ |
|
25
|
|
|
private string $lastEvaluatedTableName = ''; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Registers the DynamoDb client and Marshaler with this object. |
|
29
|
|
|
* |
|
30
|
|
|
* @param DynamoDbClient $client The DynamoDb client. |
|
31
|
|
|
* @param Marshaler $marshaler The Marshaler. |
|
32
|
|
|
*/ |
|
33
|
38 |
|
public function __construct(DynamoDbClient $client, Marshaler $marshaler) |
|
34
|
|
|
{ |
|
35
|
38 |
|
$this->setClient($client); |
|
36
|
38 |
|
$this->setMarshaler($marshaler); |
|
37
|
38 |
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Registers the name of table to be used as the last in the current page of results. |
|
41
|
|
|
* |
|
42
|
|
|
* @param string $lastEvaluatedTableName The name of the last table in the current page of results. |
|
43
|
|
|
* @return ListTablesOperation This object. |
|
44
|
|
|
*/ |
|
45
|
1 |
|
public function setLastEvaluatedTableName(string $lastEvaluatedTableName): ListTablesOperation |
|
46
|
|
|
{ |
|
47
|
1 |
|
$this->lastEvaluatedTableName = $lastEvaluatedTableName; |
|
48
|
1 |
|
return $this; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
36 |
|
public function execute(): ?array |
|
52
|
|
|
{ |
|
53
|
36 |
|
$tables = $this->client->listTables($this->toArray()); |
|
54
|
36 |
|
return $tables['TableNames']; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
38 |
|
public function toArray(): array |
|
58
|
|
|
{ |
|
59
|
38 |
|
$operation = parent::toArray(); |
|
60
|
38 |
|
unset($operation['TableName']); |
|
61
|
38 |
|
if ($this->lastEvaluatedTableName) { |
|
62
|
1 |
|
$operation['LastEvaluatedTableName'] = $this->lastEvaluatedTableName; |
|
63
|
|
|
} |
|
64
|
38 |
|
if ($this->offset || $this->limit) { |
|
|
|
|
|
|
65
|
1 |
|
$operation += $this->limitAwareTraitToArray(); |
|
66
|
|
|
} |
|
67
|
38 |
|
return $operation; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: