|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Guillermoandrae\DynamoDb\Contract; |
|
4
|
|
|
|
|
5
|
|
|
abstract class AbstractSearchOperation extends AbstractOperation implements SearchOperationInterface |
|
6
|
|
|
{ |
|
7
|
|
|
use LimitAwareOperationTrait, FilterExpressionAwareOperationTrait, ReturnConsumedCapacityAwareOperationTrait { |
|
8
|
|
|
LimitAwareOperationTrait::toArray as limitAwareTraitToArray; |
|
9
|
|
|
FilterExpressionAwareOperationTrait::toArray as filterExpressionAwareTraitToArray; |
|
10
|
|
|
ReturnConsumedCapacityAwareOperationTrait::toArray as returnConsumedCapacityAwareTraitToArray; |
|
11
|
|
|
} |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @var boolean Whether or not the read should be consistent. |
|
15
|
|
|
*/ |
|
16
|
|
|
private $consistentRead = false; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var string The name of a secondary index to request against. |
|
20
|
|
|
*/ |
|
21
|
|
|
private $indexName = ''; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var string The attributes to retrieve from the specified table or index. |
|
25
|
|
|
*/ |
|
26
|
|
|
private $projectionExpression = ''; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var string The attributes to be returned in the result. |
|
30
|
|
|
*/ |
|
31
|
|
|
private $select = ''; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* {@inheritDoc} |
|
35
|
|
|
*/ |
|
36
|
1 |
|
final public function setConsistentRead(bool $consistentRead): SearchOperationInterface |
|
37
|
|
|
{ |
|
38
|
1 |
|
$this->consistentRead = $consistentRead; |
|
39
|
1 |
|
return $this; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* {@inheritDoc} |
|
44
|
|
|
*/ |
|
45
|
1 |
|
final public function setIndexName(string $indexName): SearchOperationInterface |
|
46
|
|
|
{ |
|
47
|
1 |
|
$this->indexName = $indexName; |
|
48
|
1 |
|
return $this; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* {@inheritDoc} |
|
53
|
|
|
*/ |
|
54
|
1 |
|
final public function setSelect(string $select): SearchOperationInterface |
|
55
|
|
|
{ |
|
56
|
1 |
|
$this->select = $select; |
|
57
|
1 |
|
return $this; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* {@inheritDoc} |
|
62
|
|
|
*/ |
|
63
|
1 |
|
final public function setProjectionExpression(string $projectionExpression): SearchOperationInterface |
|
64
|
|
|
{ |
|
65
|
1 |
|
$this->projectionExpression = $projectionExpression; |
|
66
|
1 |
|
return $this; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* {@inheritDoc} |
|
71
|
|
|
*/ |
|
72
|
19 |
|
public function toArray(): array |
|
73
|
|
|
{ |
|
74
|
19 |
|
$operation = parent::toArray(); |
|
75
|
19 |
|
if ($this->limit) { |
|
76
|
1 |
|
$operation += $this->limitAwareTraitToArray(); |
|
77
|
|
|
} |
|
78
|
19 |
|
$operation += $this->returnConsumedCapacityAwareTraitToArray(); |
|
79
|
19 |
|
$operation += $this->filterExpressionAwareTraitToArray(); |
|
80
|
19 |
|
$operation['ConsistentRead'] = $this->consistentRead; |
|
81
|
19 |
|
if (!empty($this->indexName)) { |
|
82
|
1 |
|
$operation['IndexName'] = $this->indexName; |
|
83
|
|
|
} |
|
84
|
19 |
|
if (!empty($this->select)) { |
|
85
|
1 |
|
$operation['Select'] = $this->select; |
|
86
|
|
|
} |
|
87
|
19 |
|
if (!empty($this->projectionExpression)) { |
|
88
|
1 |
|
$operation['ProjectionExpression'] = $this->projectionExpression; |
|
89
|
|
|
} |
|
90
|
19 |
|
return $operation; |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|