@@ -30,11 +30,11 @@ |
||
30 | 30 | return $this->limit; |
31 | 31 | } |
32 | 32 | |
33 | - /** |
|
34 | - * Get the grammar specific operators. |
|
35 | - * |
|
36 | - * @return array |
|
37 | - */ |
|
33 | + /** |
|
34 | + * Get the grammar specific operators. |
|
35 | + * |
|
36 | + * @return array |
|
37 | + */ |
|
38 | 38 | public function getOperators() |
39 | 39 | { |
40 | 40 | return $this->operators; |
@@ -1,15 +1,15 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace Hoooklife\DynamodbPodm\Grammars; |
3 | -class DynamoDBGrammar{ |
|
4 | - protected $operators = []; |
|
3 | +class DynamoDBGrammar { |
|
4 | + protected $operators = [ ]; |
|
5 | 5 | |
6 | - protected $params = []; |
|
6 | + protected $params = [ ]; |
|
7 | 7 | |
8 | 8 | // 表达式解析 where |
9 | - public function parseKeyConditionExpression(){ |
|
10 | - $expression = []; |
|
9 | + public function parseKeyConditionExpression() { |
|
10 | + $expression = [ ]; |
|
11 | 11 | foreach ($this->wheres as $where) { |
12 | - $expression[] = "{$where['column']} {$where['operator']} {$where['value']}"; |
|
12 | + $expression[ ] = "{$where[ 'column' ]} {$where[ 'operator' ]} {$where[ 'value' ]}"; |
|
13 | 13 | } |
14 | 14 | |
15 | 15 | return implode("and", $expression); |
@@ -19,14 +19,14 @@ discard block |
||
19 | 19 | // select |
20 | 20 | public function parseProjectionExpression() |
21 | 21 | { |
22 | - if( reset($this->columns) != '*' ){ |
|
22 | + if (reset($this->columns) != '*') { |
|
23 | 23 | return implode(",", $this->columns); |
24 | 24 | } |
25 | 25 | return null; |
26 | 26 | } |
27 | 27 | |
28 | 28 | // limit |
29 | - public function parseLimit(){ |
|
29 | + public function parseLimit() { |
|
30 | 30 | return $this->limit; |
31 | 31 | } |
32 | 32 |
@@ -2,7 +2,7 @@ |
||
2 | 2 | namespace Hoooklife\DynamodbPodm; |
3 | 3 | use Hoooklife\DynamodbPodm\Query\Builder; |
4 | 4 | class DB { |
5 | - public static $config = []; |
|
5 | + public static $config = [ ]; |
|
6 | 6 | |
7 | 7 | public static function config(array $config) |
8 | 8 | { |
@@ -47,13 +47,13 @@ discard block |
||
47 | 47 | * @method QueryBuilder setLimit(int $limit) |
48 | 48 | * @method QueryBuilder setKey(array $key) |
49 | 49 | */ |
50 | -class DynamoDBBuilder{ |
|
50 | +class DynamoDBBuilder { |
|
51 | 51 | /** |
52 | 52 | * Query body to be sent to AWS |
53 | 53 | * |
54 | 54 | * @var array |
55 | 55 | */ |
56 | - public $query = []; |
|
56 | + public $query = [ ]; |
|
57 | 57 | |
58 | 58 | /** |
59 | 59 | * @param string $method |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | public function __call($method, $parameters) |
64 | 64 | { |
65 | 65 | if (starts_with($method, 'set')) { |
66 | - $key = array_reverse(explode('set', $method, 2))[0]; |
|
67 | - $this->query[$key] = current($parameters); |
|
66 | + $key = array_reverse(explode('set', $method, 2))[ 0 ]; |
|
67 | + $this->query[ $key ] = current($parameters); |
|
68 | 68 | return $this; |
69 | 69 | } |
70 | 70 | throw new BadMethodCallException(sprintf( |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | switch (DB::$config[$connection]['driver']) { |
27 | 27 | case "dynamedb": |
28 | 28 | $this->grammar = new DynamoDBGrammar(); |
29 | - break; |
|
29 | + break; |
|
30 | 30 | default: |
31 | 31 | throw new Exception("bad driver"); |
32 | 32 | } |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | if (is_array($column)) { |
90 | 90 | // 递归 |
91 | 91 | foreach ($column as $key => $value) { |
92 | - if (is_numeric($key) && is_array($value)) { |
|
92 | + if (is_numeric($key) && is_array($value)) { |
|
93 | 93 | $this->where(...array_values($value)); |
94 | 94 | } else { |
95 | 95 | $this->where($key, '=', $value, $boolean); |
@@ -127,12 +127,12 @@ discard block |
||
127 | 127 | } |
128 | 128 | |
129 | 129 | |
130 | - /** |
|
131 | - * Determine if the given operator is supported. |
|
132 | - * |
|
133 | - * @param string $operator |
|
134 | - * @return bool |
|
135 | - */ |
|
130 | + /** |
|
131 | + * Determine if the given operator is supported. |
|
132 | + * |
|
133 | + * @param string $operator |
|
134 | + * @return bool |
|
135 | + */ |
|
136 | 136 | protected function invalidOperator($operator) |
137 | 137 | { |
138 | 138 | return ! in_array(strtolower($operator), $this->operators, true) && |
@@ -199,24 +199,24 @@ discard block |
||
199 | 199 | return $this; |
200 | 200 | } |
201 | 201 | |
202 | - /** |
|
203 | - * Set the limit and offset for a given page. |
|
204 | - * |
|
205 | - * @param int $page |
|
206 | - * @param int $perPage |
|
207 | - * @return \Illuminate\Database\Query\Builder|static |
|
208 | - */ |
|
202 | + /** |
|
203 | + * Set the limit and offset for a given page. |
|
204 | + * |
|
205 | + * @param int $page |
|
206 | + * @param int $perPage |
|
207 | + * @return \Illuminate\Database\Query\Builder|static |
|
208 | + */ |
|
209 | 209 | public function forPage($page, $perPage = 15) |
210 | 210 | { |
211 | 211 | return $this->skip(($page - 1) * $perPage)->take($perPage); |
212 | 212 | } |
213 | 213 | |
214 | 214 | |
215 | - /** |
|
216 | - * Get the SQL representation of the query. |
|
217 | - * |
|
218 | - * @return string |
|
219 | - */ |
|
215 | + /** |
|
216 | + * Get the SQL representation of the query. |
|
217 | + * |
|
218 | + * @return string |
|
219 | + */ |
|
220 | 220 | public function toSql() |
221 | 221 | { |
222 | 222 | return $this->grammar->compileSelect($this); |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | namespace Hoooklife\DynamodbPodm\Query; |
4 | 4 | use Hoooklife\DynamodbPodm\DB; |
5 | 5 | use Hoooklife\DynamodbPodm\Grammars\DynamoDBGrammar; |
6 | -class Builder{ |
|
6 | +class Builder { |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * 查询排序 |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | |
24 | 24 | public function __construct($connection = 'default') |
25 | 25 | { |
26 | - switch (DB::$config[$connection]['driver']) { |
|
26 | + switch (DB::$config[ $connection ][ 'driver' ]) { |
|
27 | 27 | case "dynamedb": |
28 | 28 | $this->grammar = new DynamoDBGrammar(); |
29 | 29 | break; |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | * @param array|mixed $columns |
40 | 40 | * @return $this |
41 | 41 | */ |
42 | - public function select($columns = ['*']) |
|
42 | + public function select($columns = [ '*' ]) |
|
43 | 43 | { |
44 | 44 | $this->columns = is_array($columns) ? $columns : func_get_args(); |
45 | 45 | return $this; |
@@ -99,13 +99,13 @@ discard block |
||
99 | 99 | // return $this->addArrayOfWheres($column, $boolean); |
100 | 100 | } |
101 | 101 | |
102 | - if(func_num_args() === 2 || $this->invalidOperator($operator)) { |
|
103 | - list($value, $operator) = [$operator, '=']; |
|
102 | + if (func_num_args() === 2 || $this->invalidOperator($operator)) { |
|
103 | + list($value, $operator) = [ $operator, '=' ]; |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | // where in |
107 | - if (is_array($value)){ |
|
108 | - return $this->whereIn($column,$boolean); |
|
107 | + if (is_array($value)) { |
|
108 | + return $this->whereIn($column, $boolean); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | // is null |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | |
116 | 116 | |
117 | 117 | $type = 'Basic'; |
118 | - $this->wheres[] = compact( |
|
118 | + $this->wheres[ ] = compact( |
|
119 | 119 | 'type', 'column', 'operator', 'value', 'boolean' |
120 | 120 | ); |
121 | 121 | |
@@ -135,8 +135,8 @@ discard block |
||
135 | 135 | */ |
136 | 136 | protected function invalidOperator($operator) |
137 | 137 | { |
138 | - return ! in_array(strtolower($operator), $this->operators, true) && |
|
139 | - ! in_array(strtolower($operator), $this->grammar->getOperators(), true); |
|
138 | + return !in_array(strtolower($operator), $this->operators, true) && |
|
139 | + !in_array(strtolower($operator), $this->grammar->getOperators(), true); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | */ |
232 | 232 | public function value($column) |
233 | 233 | { |
234 | - $result = (array) $this->first([$column]); |
|
234 | + $result = (array) $this->first([ $column ]); |
|
235 | 235 | return count($result) > 0 ? reset($result) : null; |
236 | 236 | } |
237 | 237 | |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | * @param array $columns |
244 | 244 | * @return \Illuminate\Database\Eloquent\Model|object|static|null |
245 | 245 | */ |
246 | - public function first($columns = ['*']) |
|
246 | + public function first($columns = [ '*' ]) |
|
247 | 247 | { |
248 | 248 | return reset($this->take(1)->all($columns)); |
249 | 249 | } |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | * @param array $columns |
256 | 256 | * @return \Illuminate\Support\Collection |
257 | 257 | */ |
258 | - public function all($columns = ['*']) |
|
258 | + public function all($columns = [ '*' ]) |
|
259 | 259 | { |
260 | 260 | return $this->grammar->all(); |
261 | 261 | } |