1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Rennokki\DynamoDb; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class RawDynamoDbQuery. |
7
|
|
|
*/ |
8
|
|
|
class RawDynamoDbQuery implements \IteratorAggregate, \ArrayAccess, \Countable |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* 'Scan', 'Query', etc. |
12
|
|
|
* |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
public $op; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* The query body being sent to AWS. |
19
|
|
|
* |
20
|
|
|
* @var array |
21
|
|
|
*/ |
22
|
|
|
public $query; |
23
|
|
|
|
24
|
15 |
|
public function __construct($op, $query) |
25
|
|
|
{ |
26
|
15 |
|
$this->op = $op; |
27
|
15 |
|
$this->query = $query; |
28
|
15 |
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Perform any final clean up. |
32
|
|
|
* Remove any empty values to avoid errors. |
33
|
|
|
* |
34
|
|
|
* @return $this |
35
|
|
|
*/ |
36
|
15 |
|
public function finalize() |
37
|
|
|
{ |
38
|
|
|
$this->query = array_filter($this->query, function ($value) { |
39
|
15 |
|
return ! empty($value) || is_bool($value) || is_numeric($value); |
40
|
15 |
|
}); |
41
|
|
|
|
42
|
15 |
|
return $this; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Whether a offset exists. |
47
|
|
|
* @link http://php.net/manual/en/arrayaccess.offsetexists.php |
48
|
|
|
* @param mixed $offset <p> |
49
|
|
|
* An offset to check for. |
50
|
|
|
* </p> |
51
|
|
|
* @return bool true on success or false on failure. |
52
|
|
|
* </p> |
53
|
|
|
* <p> |
54
|
|
|
* The return value will be casted to boolean if non-boolean was returned. |
55
|
|
|
* @since 5.0.0 |
56
|
|
|
*/ |
57
|
|
|
public function offsetExists($offset) |
58
|
|
|
{ |
59
|
|
|
return isset($this->internal()[$offset]); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Offset to retrieve. |
64
|
|
|
* @link http://php.net/manual/en/arrayaccess.offsetget.php |
65
|
|
|
* @param mixed $offset <p> |
66
|
|
|
* The offset to retrieve. |
67
|
|
|
* </p> |
68
|
|
|
* @return mixed Can return all value types. |
69
|
|
|
* @since 5.0.0 |
70
|
|
|
*/ |
71
|
|
|
public function offsetGet($offset) |
72
|
|
|
{ |
73
|
|
|
return $this->internal()[$offset]; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Offset to set. |
78
|
|
|
* @link http://php.net/manual/en/arrayaccess.offsetset.php |
79
|
|
|
* @param mixed $offset <p> |
80
|
|
|
* The offset to assign the value to. |
81
|
|
|
* </p> |
82
|
|
|
* @param mixed $value <p> |
83
|
|
|
* The value to set. |
84
|
|
|
* </p> |
85
|
|
|
* @return void |
86
|
|
|
* @since 5.0.0 |
87
|
|
|
*/ |
88
|
|
|
public function offsetSet($offset, $value) |
89
|
|
|
{ |
90
|
|
|
$this->internal()[$offset] = $value; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Offset to unset. |
95
|
|
|
* @link http://php.net/manual/en/arrayaccess.offsetunset.php |
96
|
|
|
* @param mixed $offset <p> |
97
|
|
|
* The offset to unset. |
98
|
|
|
* </p> |
99
|
|
|
* @return void |
100
|
|
|
* @since 5.0.0 |
101
|
|
|
*/ |
102
|
|
|
public function offsetUnset($offset) |
103
|
|
|
{ |
104
|
|
|
unset($this->internal()[$offset]); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Retrieve an external iterator. |
109
|
|
|
* @link http://php.net/manual/en/iteratoraggregate.getiterator.php |
110
|
|
|
* @return \Traversable An instance of an object implementing <b>Iterator</b> or |
111
|
|
|
* <b>Traversable</b> |
112
|
|
|
* @since 5.0.0 |
113
|
|
|
*/ |
114
|
|
|
public function getIterator() |
115
|
|
|
{ |
116
|
|
|
return new \ArrayObject($this->internal()); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Count elements of an object. |
121
|
|
|
* @link http://php.net/manual/en/countable.count.php |
122
|
|
|
* @return int The custom count as an integer. |
123
|
|
|
* </p> |
124
|
|
|
* <p> |
125
|
|
|
* The return value is cast to an integer. |
126
|
|
|
* @since 5.1.0 |
127
|
|
|
*/ |
128
|
|
|
public function count() |
129
|
|
|
{ |
130
|
|
|
return count($this->internal()); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* For backward compatibility, previously we use array to represent the raw query. |
135
|
|
|
* |
136
|
|
|
* @var array |
137
|
|
|
* |
138
|
|
|
* @return array |
139
|
|
|
*/ |
140
|
|
|
private function internal() |
141
|
|
|
{ |
142
|
|
|
return [$this->op, $this->query]; |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|