guillermoandrae /
php-dynamodb
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Guillermoandrae\DynamoDb\Contract; |
||
| 4 | |||
| 5 | use Aws\DynamoDb\DynamoDbClient; |
||
| 6 | use Aws\DynamoDb\Marshaler; |
||
| 7 | |||
| 8 | /** |
||
| 9 | * Abstract for search operations. |
||
| 10 | * |
||
| 11 | * @author Guillermo A. Fisher <[email protected]> |
||
| 12 | */ |
||
| 13 | abstract class AbstractSearchOperation extends AbstractOperation implements SearchOperationInterface |
||
| 14 | { |
||
| 15 | use TableAwareOperationTrait, |
||
| 16 | LimitAwareOperationTrait, |
||
| 17 | ExpressionAttributeValueAwareOperationTrait, |
||
| 18 | ReturnConsumedCapacityAwareOperationTrait { |
||
| 19 | TableAwareOperationTrait::toArray as tableAwareTraitToArray; |
||
| 20 | LimitAwareOperationTrait::toArray as limitAwareTraitToArray; |
||
| 21 | ExpressionAttributeValueAwareOperationTrait::toArray as expressionAwareTraitToArray; |
||
| 22 | ReturnConsumedCapacityAwareOperationTrait::toArray as returnConsumedCapacityAwareTraitToArray; |
||
| 23 | } |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var boolean Whether or not the read should be consistent. |
||
| 27 | */ |
||
| 28 | protected bool $consistentRead = false; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var string The name of a secondary index to request against. |
||
| 32 | */ |
||
| 33 | protected string $indexName = ''; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var string The attributes to retrieve from the specified table or index. |
||
| 37 | */ |
||
| 38 | protected string $projectionExpression = ''; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var string The attributes to be returned in the result. |
||
| 42 | */ |
||
| 43 | protected string $select = ''; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Registers the DynamoDb client, Marshaler, and the table name with this object. |
||
| 47 | * |
||
| 48 | * @param DynamoDbClient $client The DynamoDb client. |
||
| 49 | * @param Marshaler $marshaler The Marshaler. |
||
| 50 | * @param string $tableName The table name. |
||
| 51 | */ |
||
| 52 | 22 | public function __construct(DynamoDbClient $client, Marshaler $marshaler, string $tableName) |
|
| 53 | { |
||
| 54 | 22 | parent::__construct($client, $marshaler); |
|
| 55 | 22 | $this->setTableName($tableName); |
|
| 56 | 22 | } |
|
| 57 | |||
| 58 | 1 | final public function setConsistentRead(bool $consistentRead): SearchOperationInterface |
|
| 59 | { |
||
| 60 | 1 | $this->consistentRead = $consistentRead; |
|
| 61 | 1 | return $this; |
|
| 62 | } |
||
| 63 | |||
| 64 | 1 | final public function setIndexName(string $indexName): SearchOperationInterface |
|
| 65 | { |
||
| 66 | 1 | $this->indexName = $indexName; |
|
| 67 | 1 | return $this; |
|
| 68 | } |
||
| 69 | |||
| 70 | 1 | final public function setSelect(string $select): SearchOperationInterface |
|
| 71 | { |
||
| 72 | 1 | $this->select = $select; |
|
| 73 | 1 | return $this; |
|
| 74 | } |
||
| 75 | |||
| 76 | 1 | final public function setProjectionExpression(string $projectionExpression): SearchOperationInterface |
|
| 77 | { |
||
| 78 | 1 | $this->projectionExpression = $projectionExpression; |
|
| 79 | 1 | return $this; |
|
| 80 | } |
||
| 81 | |||
| 82 | 21 | public function toArray(): array |
|
| 83 | { |
||
| 84 | 21 | $operation = $this->tableAwareTraitToArray(); |
|
| 85 | 21 | if ($this->offset || $this->limit) { |
|
|
0 ignored issues
–
show
|
|||
| 86 | 2 | $operation += $this->limitAwareTraitToArray(); |
|
| 87 | } |
||
| 88 | 21 | $operation += $this->returnConsumedCapacityAwareTraitToArray(); |
|
| 89 | 21 | $operation += $this->expressionAwareTraitToArray(); |
|
| 90 | 21 | $operation['ConsistentRead'] = $this->consistentRead; |
|
| 91 | 21 | if (!empty($this->indexName)) { |
|
| 92 | 1 | $operation['IndexName'] = $this->indexName; |
|
| 93 | } |
||
| 94 | 21 | if (!empty($this->select)) { |
|
| 95 | 1 | $operation['Select'] = $this->select; |
|
| 96 | } |
||
| 97 | 21 | if (!empty($this->projectionExpression)) { |
|
| 98 | 1 | $operation['ProjectionExpression'] = $this->projectionExpression; |
|
| 99 | } |
||
| 100 | 21 | return $operation; |
|
| 101 | } |
||
| 102 | } |
||
| 103 |
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: