1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Guillermoandrae\DynamoDb\Contract; |
4
|
|
|
|
5
|
|
|
abstract class AbstractSearchOperation extends AbstractFilterExpressionAwareOperation |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* @var boolean Whether or not to scan forward. |
9
|
|
|
*/ |
10
|
|
|
private $scanIndexForward = false; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @var boolean Whether or not the read should be consistent. |
14
|
|
|
*/ |
15
|
|
|
private $consistentRead = false; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var string The name of a secondary index to request against. |
19
|
|
|
*/ |
20
|
|
|
private $indexName = ''; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var string The attributes to be returned in the result. |
24
|
|
|
*/ |
25
|
|
|
private $select = ''; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var string The attributes to retrieve from the specified table or index. |
29
|
|
|
*/ |
30
|
|
|
private $projectionExpression = ''; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Registers the ScanIndexForward value with this object. |
34
|
|
|
* |
35
|
|
|
* @param boolean $scanIndexForward Whether or not to scan forward. |
36
|
|
|
* @return AbstractSearchOperation This object. |
37
|
|
|
*/ |
38
|
1 |
|
public function setScanIndexForward(bool $scanIndexForward): AbstractSearchOperation |
39
|
|
|
{ |
40
|
1 |
|
$this->scanIndexForward = $scanIndexForward; |
41
|
1 |
|
return $this; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Registers the ConsistentRead value with this object. |
46
|
|
|
* |
47
|
|
|
* @param boolean $consistentRead Whether or not the read should be consistent. |
48
|
|
|
* @return AbstractSearchOperation This object. |
49
|
|
|
*/ |
50
|
1 |
|
public function setConsistentRead(bool $consistentRead): AbstractSearchOperation |
51
|
|
|
{ |
52
|
1 |
|
$this->consistentRead = $consistentRead; |
53
|
1 |
|
return $this; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Registers the name of the secondary index to use. |
58
|
|
|
* |
59
|
|
|
* @param string $indexName The name of the secondary index to use. |
60
|
|
|
* @return AbstractSearchOperation This object. |
61
|
|
|
*/ |
62
|
1 |
|
public function setIndexName(string $indexName): AbstractSearchOperation |
63
|
|
|
{ |
64
|
1 |
|
$this->indexName = $indexName; |
65
|
1 |
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Registers the attributes to be return in the result. |
70
|
|
|
* |
71
|
|
|
* @param string $select The attributes to be return in the result. |
72
|
|
|
* @return AbstractSearchOperation This object. |
73
|
|
|
*/ |
74
|
1 |
|
public function setSelect(string $select): AbstractSearchOperation |
75
|
|
|
{ |
76
|
1 |
|
$this->select = $select; |
77
|
1 |
|
return $this; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Registers the attributes to retrieve from the specified table or index. |
82
|
|
|
* |
83
|
|
|
* @param string $projectionExpression The attributes to retrieve from the specified table or index. |
84
|
|
|
* @return AbstractSearchOperation This object. |
85
|
|
|
*/ |
86
|
1 |
|
public function setProjectionExpression(string $projectionExpression): AbstractSearchOperation |
87
|
|
|
{ |
88
|
1 |
|
$this->projectionExpression = $projectionExpression; |
89
|
1 |
|
return $this; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* {@inheritDoc} |
94
|
|
|
*/ |
95
|
12 |
|
public function toArray(): array |
96
|
|
|
{ |
97
|
12 |
|
$query = parent::toArray(); |
98
|
12 |
|
$query['ScanIndexForward'] = $this->scanIndexForward; |
99
|
12 |
|
$query['ConsistentRead'] = $this->consistentRead; |
100
|
12 |
|
if (!empty($this->indexName)) { |
101
|
1 |
|
$query['IndexName'] = $this->indexName; |
102
|
|
|
} |
103
|
12 |
|
if (!empty($this->select)) { |
104
|
1 |
|
$query['Select'] = $this->select; |
105
|
|
|
} |
106
|
12 |
|
if (!empty($this->projectionExpression)) { |
107
|
1 |
|
$query['ProjectionExpression'] = $this->projectionExpression; |
108
|
|
|
} |
109
|
12 |
|
return $query; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|