@@ -49,7 +49,6 @@ discard block |
||
49 | 49 | |
50 | 50 | /** |
51 | 51 | * where 语法见 @see WhereRule |
52 | - * @param array|string $expr |
|
53 | 52 | * @param mixed|null $_ |
54 | 53 | * @return \PhpBoot\DB\rules\basic\WhereRule |
55 | 54 | */ |
@@ -91,7 +90,7 @@ discard block |
||
91 | 90 | /** |
92 | 91 | * @param int|string $id |
93 | 92 | * @param array $values |
94 | - * @return int updated row count |
|
93 | + * @return \PhpBoot\DB\impls\ExecResult updated row count |
|
95 | 94 | */ |
96 | 95 | public function update($id, $values) |
97 | 96 | { |
@@ -29,9 +29,9 @@ discard block |
||
29 | 29 | ->from($this->entity->getTable()) |
30 | 30 | ->where("`{$this->entity->getPK()}` = ?", $id) |
31 | 31 | ->getFirst(); |
32 | - if($row){ |
|
32 | + if ($row) { |
|
33 | 33 | return $this->entity->make($row, false); |
34 | - }else{ |
|
34 | + }else { |
|
35 | 35 | return null; |
36 | 36 | } |
37 | 37 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * @param mixed|null $_ |
54 | 54 | * @return \PhpBoot\DB\rules\basic\WhereRule |
55 | 55 | */ |
56 | - public function deleteWhere($conditions, $_=null) |
|
56 | + public function deleteWhere($conditions, $_ = null) |
|
57 | 57 | { |
58 | 58 | $query = $this->db->deleteFrom($this->entity->getTable()); |
59 | 59 | return call_user_func_array([$query, 'where'], func_get_args()); |
@@ -75,12 +75,12 @@ discard block |
||
75 | 75 | * @param string $_ |
76 | 76 | * @return \PhpBoot\DB\rules\select\WhereRule |
77 | 77 | */ |
78 | - public function findWhere($conditions=null, $_=null) |
|
78 | + public function findWhere($conditions = null, $_ = null) |
|
79 | 79 | { |
80 | - $query = $this->db->select($this->getColumns()) |
|
80 | + $query = $this->db->select($this->getColumns()) |
|
81 | 81 | ->from($this->entity->getTable()); |
82 | - $query->context->resultHandler = function ($result){ |
|
83 | - foreach ($result as &$i){ |
|
82 | + $query->context->resultHandler = function($result) { |
|
83 | + foreach ($result as &$i) { |
|
84 | 84 | $i = $this->entity->make($i, false); |
85 | 85 | } |
86 | 86 | return $result; |
@@ -107,16 +107,16 @@ discard block |
||
107 | 107 | * @param string $_ |
108 | 108 | * @return \PhpBoot\DB\rules\basic\WhereRule |
109 | 109 | */ |
110 | - public function updateWhere($values, $conditions, $_=null) |
|
110 | + public function updateWhere($values, $conditions, $_ = null) |
|
111 | 111 | { |
112 | - $query = $this->db->update($this->entity->getTable())->set($values); |
|
113 | - return call_user_func_array([$query, 'where'], array_slice(func_get_args(),1)); |
|
112 | + $query = $this->db->update($this->entity->getTable())->set($values); |
|
113 | + return call_user_func_array([$query, 'where'], array_slice(func_get_args(), 1)); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | protected function getColumns() |
117 | 117 | { |
118 | 118 | $columns = []; |
119 | - foreach ($this->entity->getProperties() as $p){ |
|
119 | + foreach ($this->entity->getProperties() as $p) { |
|
120 | 120 | $columns[] = $p->name; |
121 | 121 | } |
122 | 122 | return $columns; |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | * |
57 | 57 | * @author caoym <[email protected]> |
58 | 58 | */ |
59 | -class DB{ |
|
59 | +class DB { |
|
60 | 60 | |
61 | 61 | /** |
62 | 62 | * DB constructor. |
@@ -97,18 +97,18 @@ discard block |
||
97 | 97 | * @param string $column0 |
98 | 98 | * @return \PhpBoot\DB\rules\select\FromRule |
99 | 99 | */ |
100 | - function select($column0=null, $_=null){ |
|
100 | + function select($column0 = null, $_ = null) { |
|
101 | 101 | $obj = new SelectRule(new Context($this->connection)); |
102 | - if($column0 == null){ |
|
102 | + if ($column0 == null) { |
|
103 | 103 | $args = ['*']; |
104 | - }elseif(is_array($column0)){ |
|
104 | + }elseif (is_array($column0)) { |
|
105 | 105 | $args = $column0; |
106 | - }else{ |
|
106 | + }else { |
|
107 | 107 | $args = func_get_args(); |
108 | 108 | } |
109 | - foreach ($args as &$arg){ |
|
109 | + foreach ($args as &$arg) { |
|
110 | 110 | $arg = DB::wrap($arg); |
111 | - if($arg == '*'){ |
|
111 | + if ($arg == '*') { |
|
112 | 112 | continue; |
113 | 113 | } |
114 | 114 | |
@@ -140,8 +140,8 @@ discard block |
||
140 | 140 | * @param string $table |
141 | 141 | * @return \PhpBoot\DB\rules\basic\WhereRule |
142 | 142 | */ |
143 | - public function deleteFrom($table){ |
|
144 | - $obj = new DeleteRule(new Context($this->connection)); |
|
143 | + public function deleteFrom($table) { |
|
144 | + $obj = new DeleteRule(new Context($this->connection)); |
|
145 | 145 | return $obj->deleteFrom($table); |
146 | 146 | } |
147 | 147 | /** |
@@ -149,8 +149,8 @@ discard block |
||
149 | 149 | * @param string $table |
150 | 150 | * @return \PhpBoot\DB\rules\replace\ValuesRule |
151 | 151 | */ |
152 | - public function replaceInto($table){ |
|
153 | - $obj = new ReplaceIntoRule(new Context($this->connection)); |
|
152 | + public function replaceInto($table) { |
|
153 | + $obj = new ReplaceIntoRule(new Context($this->connection)); |
|
154 | 154 | return $obj->replaceInto($table); |
155 | 155 | } |
156 | 156 | |
@@ -161,16 +161,16 @@ discard block |
||
161 | 161 | */ |
162 | 162 | public function transaction(callable $callback) |
163 | 163 | { |
164 | - if($this->inTransaction){ |
|
164 | + if ($this->inTransaction) { |
|
165 | 165 | return $callback($this); |
166 | 166 | } |
167 | 167 | $this->getConnection()->beginTransaction() or \PhpBoot\abort('beginTransaction failed'); |
168 | 168 | $this->inTransaction = true; |
169 | - try{ |
|
169 | + try { |
|
170 | 170 | $res = $callback($this); |
171 | 171 | $this->getConnection()->commit() or \PhpBoot\abort('commit failed'); |
172 | 172 | return $res; |
173 | - }catch (\Exception $e){ |
|
173 | + }catch (\Exception $e) { |
|
174 | 174 | $this->getConnection()->rollBack(); |
175 | 175 | Logger::warning('commit failed with '.get_class($e).' '.$e->getMessage()); |
176 | 176 | throw $e; |
@@ -191,12 +191,12 @@ discard block |
||
191 | 191 | * @param string $str |
192 | 192 | * @return Raw |
193 | 193 | */ |
194 | - static public function raw($str){ |
|
194 | + static public function raw($str) { |
|
195 | 195 | return new Raw($str); |
196 | 196 | } |
197 | 197 | static public function wrap($value) |
198 | 198 | { |
199 | - if($value instanceof Raw){ |
|
199 | + if ($value instanceof Raw) { |
|
200 | 200 | return $value->get(); |
201 | 201 | } |
202 | 202 | $value = trim($value); |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | return $value; |
205 | 205 | } |
206 | 206 | |
207 | - if(strpos($value, '.') !== false && !preg_match('/\\s+/', $value)){ |
|
207 | + if (strpos($value, '.') !== false && !preg_match('/\\s+/', $value)) { |
|
208 | 208 | return $value; |
209 | 209 | } |
210 | 210 | return '`'.str_replace('`', '``', $value).'`'; |
@@ -217,8 +217,8 @@ discard block |
||
217 | 217 | { |
218 | 218 | return $this->app; |
219 | 219 | } |
220 | - const ORDER_BY_ASC ='ASC'; |
|
221 | - const ORDER_BY_DESC ='DESC'; |
|
220 | + const ORDER_BY_ASC = 'ASC'; |
|
221 | + const ORDER_BY_DESC = 'DESC'; |
|
222 | 222 | |
223 | 223 | /** |
224 | 224 | * @var \PDO |