@@ -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,7 +191,7 @@ 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) |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | if ($value === '*') { |
| 200 | 200 | return $value; |
| 201 | 201 | } |
| 202 | - if($value instanceof Raw){ |
|
| 202 | + if ($value instanceof Raw) { |
|
| 203 | 203 | return $value->get(); |
| 204 | 204 | } |
| 205 | 205 | return '`'.str_replace('`', '``', $value).'`'; |
@@ -212,8 +212,8 @@ discard block |
||
| 212 | 212 | { |
| 213 | 213 | return $this->app; |
| 214 | 214 | } |
| 215 | - const ORDER_BY_ASC ='ASC'; |
|
| 216 | - const ORDER_BY_DESC ='DESC'; |
|
| 215 | + const ORDER_BY_ASC = 'ASC'; |
|
| 216 | + const ORDER_BY_DESC = 'DESC'; |
|
| 217 | 217 | |
| 218 | 218 | /** |
| 219 | 219 | * @var \PDO |