@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | |
| 10 | -class Table{ |
|
| 10 | +class Table { |
|
| 11 | 11 | public function getuser() |
| 12 | 12 | { |
| 13 | 13 | return "ok"; |
@@ -20,27 +20,27 @@ discard block |
||
| 20 | 20 | echo "class find\r\n"; |
| 21 | 21 | |
| 22 | 22 | $t1 = microtime(true); |
| 23 | - foreach (range(1,500) as $a){ |
|
| 23 | + foreach (range(1, 500) as $a) { |
|
| 24 | 24 | $func = "get".$field; |
| 25 | - if (method_exists($this,$func)) { |
|
| 26 | - call_user_func([$this,$func]); |
|
| 25 | + if (method_exists($this, $func)) { |
|
| 26 | + call_user_func([ $this, $func ]); |
|
| 27 | 27 | } |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - var_dump(microtime(true)-$t1); |
|
| 30 | + var_dump(microtime(true) - $t1); |
|
| 31 | 31 | |
| 32 | 32 | |
| 33 | 33 | |
| 34 | 34 | echo "array find\r\n"; |
| 35 | 35 | $t1 = microtime(true); |
| 36 | - foreach (range(1,500) as $a) { |
|
| 37 | - $a = ['set.user' => 'getuser', 'get.user' => 'getuser']; |
|
| 38 | - $func = 'set.' . $field; |
|
| 36 | + foreach (range(1, 500) as $a) { |
|
| 37 | + $a = [ 'set.user' => 'getuser', 'get.user' => 'getuser' ]; |
|
| 38 | + $func = 'set.'.$field; |
|
| 39 | 39 | // if (isset($a[$func])) { |
| 40 | - call_user_func([$this, $a[$func]]); |
|
| 40 | + call_user_func([ $this, $a[ $func ] ]); |
|
| 41 | 41 | // } |
| 42 | 42 | } |
| 43 | - var_dump(microtime(true)-$t1); |
|
| 43 | + var_dump(microtime(true) - $t1); |
|
| 44 | 44 | } |
| 45 | 45 | } |
| 46 | 46 | |
@@ -28,8 +28,8 @@ discard block |
||
| 28 | 28 | |
| 29 | 29 | $item = $marshaler->marshalJson(' |
| 30 | 30 | { |
| 31 | - "year": ' . $year . ', |
|
| 32 | - "title": "' . $title . '", |
|
| 31 | + "year": ' . $year.', |
|
| 32 | + "title": "' . $title.'", |
|
| 33 | 33 | "info": { |
| 34 | 34 | "plot": "Nothing happens at all.", |
| 35 | 35 | "rating": 0 |
@@ -52,5 +52,5 @@ discard block |
||
| 52 | 52 | |
| 53 | 53 | } catch (DynamoDbException $e) { |
| 54 | 54 | echo "Unable to add item:\n"; |
| 55 | - echo $e->getMessage() . "\n"; |
|
| 55 | + echo $e->getMessage()."\n"; |
|
| 56 | 56 | } |
| 57 | 57 | \ No newline at end of file |
@@ -42,14 +42,14 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | public function offsetExists($offset) |
| 44 | 44 | { |
| 45 | - return isset($this->data[$offset]); |
|
| 45 | + return isset($this->data[ $offset ]); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | |
| 49 | 49 | public function offsetGet($offset) |
| 50 | 50 | { |
| 51 | - if (isset($this->data[$offset])) { |
|
| 52 | - return $this->getMarshaler()->unmarshalItem($this->data[$offset]); |
|
| 51 | + if (isset($this->data[ $offset ])) { |
|
| 52 | + return $this->getMarshaler()->unmarshalItem($this->data[ $offset ]); |
|
| 53 | 53 | } |
| 54 | 54 | return null; |
| 55 | 55 | } |
@@ -57,21 +57,21 @@ discard block |
||
| 57 | 57 | |
| 58 | 58 | public function offsetSet($offset, $value) |
| 59 | 59 | { |
| 60 | - $this->data[$offset] = $value; |
|
| 60 | + $this->data[ $offset ] = $value; |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | |
| 64 | 64 | public function offsetUnset($offset) |
| 65 | 65 | { |
| 66 | - unset($this->data[$offset]); |
|
| 66 | + unset($this->data[ $offset ]); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | public function toArray() |
| 70 | 70 | { |
| 71 | 71 | |
| 72 | - $result = []; |
|
| 73 | - foreach ($this->data["Items"] as $item) { |
|
| 74 | - $result[] = $this->getMarshaler()->unmarshalItem($item); |
|
| 72 | + $result = [ ]; |
|
| 73 | + foreach ($this->data[ "Items" ] as $item) { |
|
| 74 | + $result[ ] = $this->getMarshaler()->unmarshalItem($item); |
|
| 75 | 75 | } |
| 76 | 76 | return $result; |
| 77 | 77 | } |
@@ -6,7 +6,7 @@ |
||
| 6 | 6 | |
| 7 | 7 | class DB |
| 8 | 8 | { |
| 9 | - public static $config = []; |
|
| 9 | + public static $config = [ ]; |
|
| 10 | 10 | public static $connect; |
| 11 | 11 | |
| 12 | 12 | public static function config(array $config, string $connect = 'default') |
@@ -13,8 +13,8 @@ discard block |
||
| 13 | 13 | * 查询排序 |
| 14 | 14 | */ |
| 15 | 15 | public $limit; |
| 16 | - public $wheres = []; |
|
| 17 | - public $bindings = []; |
|
| 16 | + public $wheres = [ ]; |
|
| 17 | + public $bindings = [ ]; |
|
| 18 | 18 | public $columns; |
| 19 | 19 | public $table; |
| 20 | 20 | |
@@ -37,9 +37,9 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | public function __construct($connection = 'default') |
| 39 | 39 | { |
| 40 | - switch (DB::$config[$connection]['driver']) { |
|
| 40 | + switch (DB::$config[ $connection ][ 'driver' ]) { |
|
| 41 | 41 | case "dynamedb": |
| 42 | - $this->grammar = new DynamoDBGrammar($this, DB::$config[$connection]); |
|
| 42 | + $this->grammar = new DynamoDBGrammar($this, DB::$config[ $connection ]); |
|
| 43 | 43 | break; |
| 44 | 44 | default: |
| 45 | 45 | throw new \Exception("bad driver"); |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | if (func_num_args() === 2 || $this->invalidOperator($operator)) { |
| 89 | - list($value, $operator) = [$operator, '=']; |
|
| 89 | + list($value, $operator) = [ $operator, '=' ]; |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | // where in |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | $type = 'Basic'; |
| 103 | - $this->wheres[] = compact( |
|
| 103 | + $this->wheres[ ] = compact( |
|
| 104 | 104 | 'type', 'column', 'operator', 'value', 'boolean' |
| 105 | 105 | ); |
| 106 | 106 | |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | */ |
| 217 | 217 | public function value($column) |
| 218 | 218 | { |
| 219 | - $result = (array)$this->first([$column]); |
|
| 219 | + $result = (array) $this->first([ $column ]); |
|
| 220 | 220 | return count($result) > 0 ? reset($result) : null; |
| 221 | 221 | } |
| 222 | 222 | |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | * @param array $columns |
| 228 | 228 | * @return \Illuminate\Database\Eloquent\Model|object|static|null |
| 229 | 229 | */ |
| 230 | - public function first($columns = ['*']) |
|
| 230 | + public function first($columns = [ '*' ]) |
|
| 231 | 231 | { |
| 232 | 232 | return reset($this->take(1)->all($columns)); |
| 233 | 233 | } |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | * @param array $columns |
| 240 | 240 | * @return Collection |
| 241 | 241 | */ |
| 242 | - public function all($columns = ['*']): Collection |
|
| 242 | + public function all($columns = [ '*' ]): Collection |
|
| 243 | 243 | { |
| 244 | 244 | $columns = is_array($columns) ? $columns : func_get_args(); |
| 245 | 245 | $this->columns = $columns; |
@@ -52,15 +52,15 @@ discard block |
||
| 52 | 52 | * |
| 53 | 53 | * @var array |
| 54 | 54 | */ |
| 55 | - public $query = []; |
|
| 56 | - public $batchWriteItem = []; |
|
| 55 | + public $query = [ ]; |
|
| 56 | + public $batchWriteItem = [ ]; |
|
| 57 | 57 | |
| 58 | 58 | /** @var $dynamodbClient DynamoDbClient */ |
| 59 | 59 | protected $dynamodbClient; |
| 60 | 60 | |
| 61 | 61 | public function __construct(array $config) |
| 62 | 62 | { |
| 63 | - $this->dynamodbClient = new DynamoDbClient($config["S3Config"]); |
|
| 63 | + $this->dynamodbClient = new DynamoDbClient($config[ "S3Config" ]); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | public function hydrate(array $query) |
@@ -71,20 +71,20 @@ discard block |
||
| 71 | 71 | |
| 72 | 72 | public function setExpressionAttributeName($placeholder, $name) |
| 73 | 73 | { |
| 74 | - $this->query['ExpressionAttributeNames'][$placeholder] = $name; |
|
| 74 | + $this->query[ 'ExpressionAttributeNames' ][ $placeholder ] = $name; |
|
| 75 | 75 | return $this; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | public function setExpressionAttributeValue($placeholder, $value) |
| 79 | 79 | { |
| 80 | - $this->query['ExpressionAttributeValues'][$placeholder] = $value; |
|
| 80 | + $this->query[ 'ExpressionAttributeValues' ][ $placeholder ] = $value; |
|
| 81 | 81 | return $this; |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | public function setKeyConditionExpression($mapping) |
| 85 | 85 | { |
| 86 | 86 | if ($mapping) { |
| 87 | - $this->query['KeyConditionExpression'] = $mapping; |
|
| 87 | + $this->query[ 'KeyConditionExpression' ] = $mapping; |
|
| 88 | 88 | } |
| 89 | 89 | return $this; |
| 90 | 90 | } |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | public function setProjectionExpression($expression) |
| 93 | 93 | { |
| 94 | 94 | if ($expression) { |
| 95 | - $this->query['ProjectionExpression'] = $expression; |
|
| 95 | + $this->query[ 'ProjectionExpression' ] = $expression; |
|
| 96 | 96 | } |
| 97 | 97 | return $this; |
| 98 | 98 | } |
@@ -100,14 +100,14 @@ discard block |
||
| 100 | 100 | public function setExpressionAttributeValues($mapping) |
| 101 | 101 | { |
| 102 | 102 | if ($mapping) { |
| 103 | - $this->query['ExpressionAttributeValues'] = $mapping; |
|
| 103 | + $this->query[ 'ExpressionAttributeValues' ] = $mapping; |
|
| 104 | 104 | } |
| 105 | 105 | return $this; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | public function setRequestItems($items) |
| 109 | 109 | { |
| 110 | - $this->batchWriteItem['RequestItems'] = $items; |
|
| 110 | + $this->batchWriteItem[ 'RequestItems' ] = $items; |
|
| 111 | 111 | return $this; |
| 112 | 112 | } |
| 113 | 113 | |
@@ -136,8 +136,8 @@ discard block |
||
| 136 | 136 | public function __call($method, $parameters) |
| 137 | 137 | { |
| 138 | 138 | if (strpos($method, 'set') === 0) { |
| 139 | - $key = array_reverse(explode('set', $method, 2))[0]; |
|
| 140 | - $this->query[$key] = current($parameters); |
|
| 139 | + $key = array_reverse(explode('set', $method, 2))[ 0 ]; |
|
| 140 | + $this->query[ $key ] = current($parameters); |
|
| 141 | 141 | return $this; |
| 142 | 142 | } |
| 143 | 143 | throw new BadMethodCallException(sprintf( |
@@ -14,9 +14,9 @@ discard block |
||
| 14 | 14 | 'begins_with' |
| 15 | 15 | ]; |
| 16 | 16 | |
| 17 | - protected $params = []; |
|
| 17 | + protected $params = [ ]; |
|
| 18 | 18 | |
| 19 | - protected $insertParam = []; |
|
| 19 | + protected $insertParam = [ ]; |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * @var Builder |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | private $dynamoDBBuilder; |
| 31 | 31 | |
| 32 | - private $attributeValues = []; |
|
| 32 | + private $attributeValues = [ ]; |
|
| 33 | 33 | |
| 34 | 34 | /** @var Marshaler $marshaler */ |
| 35 | 35 | private $marshaler; |
@@ -52,19 +52,19 @@ discard block |
||
| 52 | 52 | // 表达式解析 where |
| 53 | 53 | private function parseKeyConditionExpression() |
| 54 | 54 | { |
| 55 | - $expression = []; |
|
| 55 | + $expression = [ ]; |
|
| 56 | 56 | |
| 57 | 57 | foreach ($this->builder->wheres as $index => $where) { |
| 58 | - switch (strtolower($where['operator'])){ |
|
| 58 | + switch (strtolower($where[ 'operator' ])) { |
|
| 59 | 59 | case "begins_with": |
| 60 | - $expression[] = "begins_with({$where['column']}, :{$index})"; |
|
| 60 | + $expression[ ] = "begins_with({$where[ 'column' ]}, :{$index})"; |
|
| 61 | 61 | break; |
| 62 | 62 | default: |
| 63 | - $expression[] = "{$where['column']} {$where['operator']} :{$index}"; |
|
| 63 | + $expression[ ] = "{$where[ 'column' ]} {$where[ 'operator' ]} :{$index}"; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | // param bind |
| 67 | - $this->attributeValues[':' . $index] = $where['value']; |
|
| 67 | + $this->attributeValues[ ':'.$index ] = $where[ 'value' ]; |
|
| 68 | 68 | } |
| 69 | 69 | return implode(" and ", $expression); |
| 70 | 70 | } |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | $this->createInsertParam($data); |
| 105 | 105 | |
| 106 | 106 | $builder = $this->dynamoDBBuilder |
| 107 | - ->setRequestItems([$this->builder->table => $this->insertParam]); |
|
| 107 | + ->setRequestItems([ $this->builder->table => $this->insertParam ]); |
|
| 108 | 108 | |
| 109 | 109 | return $builder->batchWriteItem(); |
| 110 | 110 | } |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | if (is_numeric($key) && is_array($value)) { |
| 116 | 116 | $this->createInsertParam($value); |
| 117 | 117 | } else { |
| 118 | - $this->insertParam[] = [ |
|
| 118 | + $this->insertParam[ ] = [ |
|
| 119 | 119 | 'PutRequest' => [ |
| 120 | 120 | 'Item' => $this->marshaler->marshalItem($data) |
| 121 | 121 | ] |