@@ -95,7 +95,7 @@ |
||
95 | 95 | * @param mixed $value |
96 | 96 | * @return \PhpBoot\DB\rules\basic\ExecRule |
97 | 97 | */ |
98 | - public function onDuplicateKeyUpdate($expr, $_=null) { |
|
98 | + public function onDuplicateKeyUpdate($expr, $_ = null) { |
|
99 | 99 | $this->impl->set($this->context, $expr, array_slice(func_get_args(), 1)); |
100 | 100 | return new ExecRule($this->context); |
101 | 101 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | |
25 | 25 | class UpdateSetRule extends WhereRule |
26 | 26 | { |
27 | - public function __construct($context){ |
|
27 | + public function __construct($context) { |
|
28 | 28 | parent::__construct($context); |
29 | 29 | $this->impl = new UpdateSetImpl(); |
30 | 30 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * @param mixed $_ |
38 | 38 | * @return \PhpBoot\DB\rules\update\UpdateSetRule |
39 | 39 | */ |
40 | - public function set($expr, $_=null) { |
|
40 | + public function set($expr, $_ = null) { |
|
41 | 41 | $this->impl->set($this->context, $expr, array_slice(func_get_args(), 1)); |
42 | 42 | return $this; |
43 | 43 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * @param string|false $asDict |
38 | 38 | * @return array |
39 | 39 | */ |
40 | - public function get($asDict=false) { |
|
40 | + public function get($asDict = false) { |
|
41 | 41 | return ExecImpl::get($this->context, $asDict); |
42 | 42 | } |
43 | 43 | |
@@ -51,9 +51,9 @@ discard block |
||
51 | 51 | * Execute sql and get one response |
52 | 52 | * @return null |
53 | 53 | */ |
54 | - public function getFirst(){ |
|
54 | + public function getFirst() { |
|
55 | 55 | $res = ExecImpl::get($this->context); |
56 | - if(count($res)){ |
|
56 | + if (count($res)) { |
|
57 | 57 | return $res[0]; |
58 | 58 | } |
59 | 59 | return null; |
@@ -66,8 +66,8 @@ discard block |
||
66 | 66 | * @param string $table |
67 | 67 | * @return \PhpBoot\DB\rules\select\JoinRule |
68 | 68 | */ |
69 | - public function from($table, $as=null){ |
|
70 | - FromImpl::from($this->context, $table,$as); |
|
69 | + public function from($table, $as = null) { |
|
70 | + FromImpl::from($this->context, $table, $as); |
|
71 | 71 | return new JoinRule($this->context); |
72 | 72 | } |
73 | 73 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * @param string $column |
79 | 79 | * @return \PhpBoot\DB\rules\select\GetRule |
80 | 80 | */ |
81 | - public function of($column){ |
|
81 | + public function of($column) { |
|
82 | 82 | ForUpdateOfImpl::of($this->context, $column); |
83 | 83 | return new GetRule($this->context); |
84 | 84 | } |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | * forUpdate() => 'FOR UPDATE' |
90 | 90 | * @return \PhpBoot\DB\rules\select\ForUpdateOfRule |
91 | 91 | */ |
92 | - public function forUpdate(){ |
|
92 | + public function forUpdate() { |
|
93 | 93 | ForUpdateImpl::forUpdate($this->context); |
94 | 94 | return new ForUpdateOfRule($this->context); |
95 | 95 | } |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | |
112 | 112 | class OrderByRule extends LimitRule |
113 | 113 | { |
114 | - public function __construct($context){ |
|
114 | + public function __construct($context) { |
|
115 | 115 | parent::__construct($context); |
116 | 116 | $this->order = new OrderByImpl(); |
117 | 117 | } |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | * @param string $order Sql::ORDER_BY_ASC or Sql::ORDER_BY_DESC |
127 | 127 | * @return \PhpBoot\DB\rules\select\OrderByRule |
128 | 128 | */ |
129 | - public function orderBy($column, $order=null) { |
|
129 | + public function orderBy($column, $order = null) { |
|
130 | 130 | $this->order->orderBy($this->context, $column, $order); |
131 | 131 | return $this; |
132 | 132 | } |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | * @param string $_ |
168 | 168 | * @return \PhpBoot\DB\rules\select\OrderByRule |
169 | 169 | */ |
170 | - public function having($expr, $_=null) { |
|
170 | + public function having($expr, $_ = null) { |
|
171 | 171 | WhereImpl::having($this->context, $expr, array_slice(func_get_args(), 1)); |
172 | 172 | return new OrderByRule($this->context); |
173 | 173 | } |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | * @param mixed $_ |
215 | 215 | * @return \PhpBoot\DB\rules\select\GroupByRule |
216 | 216 | */ |
217 | - public function where($conditions=null, $_=null) { |
|
217 | + public function where($conditions = null, $_ = null) { |
|
218 | 218 | WhereImpl::where($this->context, $conditions, array_slice(func_get_args(), 1)); |
219 | 219 | return new GroupByRule($this->context); |
220 | 220 | } |
@@ -227,8 +227,8 @@ discard block |
||
227 | 227 | * @param string $table |
228 | 228 | * @return \PhpBoot\DB\rules\select\JoinOnRule |
229 | 229 | */ |
230 | - public function join($table){ |
|
231 | - JoinImpl::join($this->context,null, $table); |
|
230 | + public function join($table) { |
|
231 | + JoinImpl::join($this->context, null, $table); |
|
232 | 232 | return new JoinOnRule($this->context); |
233 | 233 | } |
234 | 234 | /** |
@@ -236,8 +236,8 @@ discard block |
||
236 | 236 | * @param string $table |
237 | 237 | * @return \PhpBoot\DB\rules\select\JoinOnRule |
238 | 238 | */ |
239 | - public function leftJoin($table){ |
|
240 | - JoinImpl::join($this->context,'LEFT', $table); |
|
239 | + public function leftJoin($table) { |
|
240 | + JoinImpl::join($this->context, 'LEFT', $table); |
|
241 | 241 | return new JoinOnRule($this->context); |
242 | 242 | } |
243 | 243 | /** |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | * @return \PhpBoot\DB\rules\select\JoinOnRule |
247 | 247 | */ |
248 | 248 | public function rightJoin($table) { |
249 | - JoinImpl::join($this->context,'RIGHT', $table); |
|
249 | + JoinImpl::join($this->context, 'RIGHT', $table); |
|
250 | 250 | return new JoinOnRule($this->context); |
251 | 251 | } |
252 | 252 | /** |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | * @return \PhpBoot\DB\rules\select\JoinOnRule |
256 | 256 | */ |
257 | 257 | public function innerJoin($table) { |
258 | - JoinImpl::join($this->context,'INNER', $table); |
|
258 | + JoinImpl::join($this->context, 'INNER', $table); |
|
259 | 259 | return new JoinOnRule($this->context); |
260 | 260 | } |
261 | 261 | } |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | * @param string $condition |
268 | 268 | * @return \PhpBoot\DB\rules\select\JoinRule |
269 | 269 | */ |
270 | - public function on($condition){ |
|
270 | + public function on($condition) { |
|
271 | 271 | JoinOnImpl::on($this->context, $condition); |
272 | 272 | return new JoinRule($this->context); |
273 | 273 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * |
56 | 56 | * @author caoym <[email protected]> |
57 | 57 | */ |
58 | -class DB{ |
|
58 | +class DB { |
|
59 | 59 | |
60 | 60 | /** |
61 | 61 | * DB constructor. |
@@ -96,18 +96,18 @@ discard block |
||
96 | 96 | * @param string $column0 |
97 | 97 | * @return \PhpBoot\DB\rules\select\FromRule |
98 | 98 | */ |
99 | - function select($column0=null, $_=null){ |
|
99 | + function select($column0 = null, $_ = null) { |
|
100 | 100 | $obj = new SelectRule(new Context($this->connection)); |
101 | - if($column0 == null){ |
|
101 | + if ($column0 == null) { |
|
102 | 102 | $args = ['*']; |
103 | - }elseif(is_array($column0)){ |
|
103 | + }elseif (is_array($column0)) { |
|
104 | 104 | $args = $column0; |
105 | - }else{ |
|
105 | + }else { |
|
106 | 106 | $args = func_get_args(); |
107 | 107 | } |
108 | - foreach ($args as &$arg){ |
|
108 | + foreach ($args as &$arg) { |
|
109 | 109 | $arg = DB::wrap($arg); |
110 | - if($arg == '*'){ |
|
110 | + if ($arg == '*') { |
|
111 | 111 | continue; |
112 | 112 | } |
113 | 113 | |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | * @param string $table |
140 | 140 | * @return \PhpBoot\DB\rules\basic\WhereRule |
141 | 141 | */ |
142 | - public function deleteFrom($table){ |
|
143 | - $obj = new DeleteRule(new Context($this->connection)); |
|
142 | + public function deleteFrom($table) { |
|
143 | + $obj = new DeleteRule(new Context($this->connection)); |
|
144 | 144 | return $obj->deleteFrom($table); |
145 | 145 | } |
146 | 146 | /** |
@@ -148,8 +148,8 @@ discard block |
||
148 | 148 | * @param string $table |
149 | 149 | * @return \PhpBoot\DB\rules\replace\ValuesRule |
150 | 150 | */ |
151 | - public function replaceInto($table){ |
|
152 | - $obj = new ReplaceIntoRule(new Context($this->connection)); |
|
151 | + public function replaceInto($table) { |
|
152 | + $obj = new ReplaceIntoRule(new Context($this->connection)); |
|
153 | 153 | return $obj->replaceInto($table); |
154 | 154 | } |
155 | 155 | |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | * @param string $str |
169 | 169 | * @return Raw |
170 | 170 | */ |
171 | - static public function raw($str){ |
|
171 | + static public function raw($str) { |
|
172 | 172 | return new Raw($str); |
173 | 173 | } |
174 | 174 | static public function wrap($value) |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | if ($value === '*') { |
177 | 177 | return $value; |
178 | 178 | } |
179 | - if($value instanceof Raw){ |
|
179 | + if ($value instanceof Raw) { |
|
180 | 180 | return $value->get(); |
181 | 181 | } |
182 | 182 | return '`'.str_replace('`', '``', $value).'`'; |
@@ -189,8 +189,8 @@ discard block |
||
189 | 189 | { |
190 | 190 | return $this->app; |
191 | 191 | } |
192 | - const ORDER_BY_ASC ='ASC'; |
|
193 | - const ORDER_BY_DESC ='DESC'; |
|
192 | + const ORDER_BY_ASC = 'ASC'; |
|
193 | + const ORDER_BY_DESC = 'DESC'; |
|
194 | 194 | |
195 | 195 | /** |
196 | 196 | * @var \PDO |
@@ -28,11 +28,11 @@ discard block |
||
28 | 28 | public function create() |
29 | 29 | { |
30 | 30 | $data = []; |
31 | - foreach ($this->getColumns() as $column){ |
|
32 | - if(isset($this->object->$column)){ |
|
33 | - if(is_array($this->object->$column) || is_object($this->object->$column)){ |
|
31 | + foreach ($this->getColumns() as $column) { |
|
32 | + if (isset($this->object->$column)) { |
|
33 | + if (is_array($this->object->$column) || is_object($this->object->$column)) { |
|
34 | 34 | $data[$column] = json_encode($this->object->$column); |
35 | - }else{ |
|
35 | + }else { |
|
36 | 36 | $data[$column] = $this->object->$column; |
37 | 37 | } |
38 | 38 | |
@@ -48,18 +48,18 @@ discard block |
||
48 | 48 | * @param array $columns columns to update. if columns is empty array, update all of the columns |
49 | 49 | * @return int rows updated |
50 | 50 | */ |
51 | - public function update(array $columns=[]) |
|
51 | + public function update(array $columns = []) |
|
52 | 52 | { |
53 | 53 | $data = []; |
54 | 54 | $pk = $this->entity->getPK(); |
55 | - foreach ($this->getColumns() as $column){ |
|
56 | - if(count($columns) && !in_array($column, $columns)){ |
|
55 | + foreach ($this->getColumns() as $column) { |
|
56 | + if (count($columns) && !in_array($column, $columns)) { |
|
57 | 57 | continue; |
58 | 58 | } |
59 | - if($pk != $column && isset($this->object->$column)){ |
|
60 | - if(is_array($this->object->$column) || is_object($this->object->$column)){ |
|
59 | + if ($pk != $column && isset($this->object->$column)) { |
|
60 | + if (is_array($this->object->$column) || is_object($this->object->$column)) { |
|
61 | 61 | $data[$column] = json_encode($this->object->$column); |
62 | - }else{ |
|
62 | + }else { |
|
63 | 63 | $data[$column] = $this->object->$column; |
64 | 64 | } |
65 | 65 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | protected function getColumns() |
86 | 86 | { |
87 | 87 | $columns = []; |
88 | - foreach ($this->entity->getProperties() as $p){ |
|
88 | + foreach ($this->entity->getProperties() as $p) { |
|
89 | 89 | $columns[] = $p->name; |
90 | 90 | } |
91 | 91 | return $columns; |