@@ -30,7 +30,7 @@ |
||
| 30 | 30 | |
| 31 | 31 | public function getWhereType(); |
| 32 | 32 | |
| 33 | - public function setWhere($field,$value = false); |
|
| 33 | + public function setWhere($field, $value = false); |
|
| 34 | 34 | |
| 35 | 35 | public function setLimit($limit); |
| 36 | 36 | |
@@ -14,13 +14,13 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | interface QueryBuilderInterface { |
| 16 | 16 | |
| 17 | - public function getResultQuery($table,\SimpleORM\ISpecificationCriteria $Criteria); |
|
| 17 | + public function getResultQuery($table, \SimpleORM\ISpecificationCriteria $Criteria); |
|
| 18 | 18 | |
| 19 | - public function update($table,array $data,$where = []); |
|
| 19 | + public function update($table, array $data, $where = []); |
|
| 20 | 20 | |
| 21 | - public function insert($table,array $data); |
|
| 21 | + public function insert($table, array $data); |
|
| 22 | 22 | |
| 23 | 23 | public function insert_id(); |
| 24 | 24 | |
| 25 | - public function delete($table,$where = []); |
|
| 25 | + public function delete($table, $where = []); |
|
| 26 | 26 | } |
@@ -71,8 +71,7 @@ discard block |
||
| 71 | 71 | |
| 72 | 72 | if(!$like){ |
| 73 | 73 | return $this->adapter->escape_str($str); |
| 74 | - } |
|
| 75 | - else{ |
|
| 74 | + } else{ |
|
| 76 | 75 | return $this->adapter->escape_like_str($str); |
| 77 | 76 | } |
| 78 | 77 | |
@@ -145,8 +144,7 @@ discard block |
||
| 145 | 144 | if(preg_match('~(.*?)\.(.*?)$~is',$table,$m)){ |
| 146 | 145 | $this->database = $m[1]; |
| 147 | 146 | $this->TableName = $m[2]; |
| 148 | - } |
|
| 149 | - else{ |
|
| 147 | + } else{ |
|
| 150 | 148 | $this->TableName = $table; |
| 151 | 149 | } |
| 152 | 150 | } |
@@ -38,9 +38,9 @@ discard block |
||
| 38 | 38 | protected function escape($str) |
| 39 | 39 | { |
| 40 | 40 | if (is_string($str)) { |
| 41 | - $str = "'" . $this->escape_str($str) . "'"; |
|
| 41 | + $str = "'".$this->escape_str($str)."'"; |
|
| 42 | 42 | } elseif (is_bool($str)) { |
| 43 | - $str = ($str === FALSE) ? 0 : 1; |
|
| 43 | + $str = ($str===FALSE) ? 0 : 1; |
|
| 44 | 44 | } elseif (is_null($str)) { |
| 45 | 45 | $str = 'NULL'; |
| 46 | 46 | } |
@@ -48,13 +48,13 @@ discard block |
||
| 48 | 48 | return $str; |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - public function update($table,array $data,$where = []){ |
|
| 52 | - return $this->adapter->update($table,$data,$where); |
|
| 51 | + public function update($table, array $data, $where = []) { |
|
| 52 | + return $this->adapter->update($table, $data, $where); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - public function insert($table,array $data) |
|
| 55 | + public function insert($table, array $data) |
|
| 56 | 56 | { |
| 57 | - return $this->adapter->insert($table,$data); |
|
| 57 | + return $this->adapter->insert($table, $data); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | public function insert_id() |
@@ -62,17 +62,17 @@ discard block |
||
| 62 | 62 | return $this->adapter->insert_id(); |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - public function delete($table,$where = []){ |
|
| 66 | - return $this->adapter->delete($table,$where); |
|
| 65 | + public function delete($table, $where = []) { |
|
| 66 | + return $this->adapter->delete($table, $where); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | protected function escape_str($str, $like = FALSE) |
| 70 | 70 | { |
| 71 | 71 | |
| 72 | - if(!$like){ |
|
| 72 | + if (!$like) { |
|
| 73 | 73 | return $this->adapter->escape_str($str); |
| 74 | 74 | } |
| 75 | - else{ |
|
| 75 | + else { |
|
| 76 | 76 | return $this->adapter->escape_like_str($str); |
| 77 | 77 | } |
| 78 | 78 | |
@@ -111,8 +111,8 @@ discard block |
||
| 111 | 111 | throw new HttpException('You cannot have an empty field name.'); |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - if (strpos($field, '.') === false) { |
|
| 115 | - return $this->TableName . '.' . $field; |
|
| 114 | + if (strpos($field, '.')===false) { |
|
| 115 | + return $this->TableName.'.'.$field; |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | return $field; |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * |
| 123 | 123 | * @param type $param |
| 124 | 124 | */ |
| 125 | - public function getResultQuery($table,\SimpleORM\ISpecificationCriteria $Criteria ) { |
|
| 125 | + public function getResultQuery($table, \SimpleORM\ISpecificationCriteria $Criteria) { |
|
| 126 | 126 | |
| 127 | 127 | $this->setTable($table); |
| 128 | 128 | |
@@ -142,12 +142,12 @@ discard block |
||
| 142 | 142 | return $res; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - protected function setTable($table){ |
|
| 146 | - if(preg_match('~(.*?)\.(.*?)$~is',$table,$m)){ |
|
| 145 | + protected function setTable($table) { |
|
| 146 | + if (preg_match('~(.*?)\.(.*?)$~is', $table, $m)) { |
|
| 147 | 147 | $this->database = $m[1]; |
| 148 | 148 | $this->TableName = $m[2]; |
| 149 | 149 | } |
| 150 | - else{ |
|
| 150 | + else { |
|
| 151 | 151 | $this->TableName = $table; |
| 152 | 152 | } |
| 153 | 153 | } |
@@ -158,12 +158,12 @@ discard block |
||
| 158 | 158 | * @param type $joins |
| 159 | 159 | * @return type |
| 160 | 160 | */ |
| 161 | - protected function createSelect(array $joins,$manualSelect) |
|
| 161 | + protected function createSelect(array $joins, $manualSelect) |
|
| 162 | 162 | { |
| 163 | - $s = !empty($manualSelect) ? $manualSelect :"`" . $this->TableName . '`.*'; |
|
| 163 | + $s = !empty($manualSelect) ? $manualSelect : "`".$this->TableName.'`.*'; |
|
| 164 | 164 | |
| 165 | 165 | foreach ($joins as $table => $join) { |
| 166 | - $table = isset($join['alias']) ? "`{$join['alias']}`": $table; |
|
| 166 | + $table = isset($join['alias']) ? "`{$join['alias']}`" : $table; |
|
| 167 | 167 | $s .= ", $table.*"; |
| 168 | 168 | } |
| 169 | 169 | return $s; |
@@ -186,8 +186,8 @@ discard block |
||
| 186 | 186 | */ |
| 187 | 187 | protected function buildQuery($where = array(), $limit = 25, $offset = 0, $joins = array(), $order = array(), $manualJoins = array(), $group = null, $manualWheres = array(), $whereType = 'AND', $manualSelect = '') |
| 188 | 188 | { |
| 189 | - $table = !empty($this->database)? "`{$this->database}`.".$this->TableName : $this->TableName; |
|
| 190 | - $query = 'SELECT ' . $this->createSelect($joins, $manualSelect) . " FROM `".$table."`"; |
|
| 189 | + $table = !empty($this->database) ? "`{$this->database}`.".$this->TableName : $this->TableName; |
|
| 190 | + $query = 'SELECT '.$this->createSelect($joins, $manualSelect)." FROM `".$table."`"; |
|
| 191 | 191 | //$countQuery = "SELECT COUNT(*) AS cnt FROM `{$this->database}`.".$this->getTableName(); |
| 192 | 192 | |
| 193 | 193 | $wheres = array(); |
@@ -197,15 +197,15 @@ discard block |
||
| 197 | 197 | |
| 198 | 198 | if (!is_array($value)) { |
| 199 | 199 | $params[] = $value; |
| 200 | - $wheres[] = $key . ' = ?'; |
|
| 200 | + $wheres[] = $key.' = ?'; |
|
| 201 | 201 | } else { |
| 202 | 202 | if (isset($value['operator'])) { |
| 203 | 203 | if (is_array($value['value'])) { |
| 204 | - if ($value['operator'] == 'between') { |
|
| 204 | + if ($value['operator']=='between') { |
|
| 205 | 205 | $params[] = $value['value'][0]; |
| 206 | 206 | $params[] = $value['value'][1]; |
| 207 | - $wheres[] = $key . ' BETWEEN ? AND ?'; |
|
| 208 | - } elseif ($value['operator'] == 'IN') { |
|
| 207 | + $wheres[] = $key.' BETWEEN ? AND ?'; |
|
| 208 | + } elseif ($value['operator']=='IN') { |
|
| 209 | 209 | $in = array(); |
| 210 | 210 | |
| 211 | 211 | foreach ($value['value'] as $item) { |
@@ -213,67 +213,67 @@ discard block |
||
| 213 | 213 | $in[] = '?'; |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - $wheres[] = $key . ' IN (' . implode(', ', $in) . ') '; |
|
| 216 | + $wheres[] = $key.' IN ('.implode(', ', $in).') '; |
|
| 217 | 217 | } else { |
| 218 | 218 | $ors = array(); |
| 219 | 219 | foreach ($value['value'] as $item) { |
| 220 | - if ($item == 'null') { |
|
| 220 | + if ($item=='null') { |
|
| 221 | 221 | switch ($value['operator']) { |
| 222 | 222 | case '!=': |
| 223 | - $ors[] = $key . ' IS NOT NULL'; |
|
| 223 | + $ors[] = $key.' IS NOT NULL'; |
|
| 224 | 224 | break; |
| 225 | 225 | |
| 226 | 226 | case '==': |
| 227 | 227 | default: |
| 228 | - $ors[] = $key . ' IS NULL'; |
|
| 228 | + $ors[] = $key.' IS NULL'; |
|
| 229 | 229 | break; |
| 230 | 230 | } |
| 231 | 231 | } else { |
| 232 | 232 | $params[] = $item; |
| 233 | - $ors[] = $this->fieldCheck($key) . ' ' . $value['operator'] . ' ?'; |
|
| 233 | + $ors[] = $this->fieldCheck($key).' '.$value['operator'].' ?'; |
|
| 234 | 234 | } |
| 235 | 235 | } |
| 236 | - $wheres[] = '(' . implode(' OR ', $ors) . ')'; |
|
| 236 | + $wheres[] = '('.implode(' OR ', $ors).')'; |
|
| 237 | 237 | } |
| 238 | 238 | } else { |
| 239 | - if ($value['operator'] == 'like') { |
|
| 240 | - $params[] = '%' . $value['value'] . '%'; |
|
| 241 | - $wheres[] = $key . ' ' . $value['operator'] . ' ?'; |
|
| 239 | + if ($value['operator']=='like') { |
|
| 240 | + $params[] = '%'.$value['value'].'%'; |
|
| 241 | + $wheres[] = $key.' '.$value['operator'].' ?'; |
|
| 242 | 242 | } else { |
| 243 | - if ($value['value'] === 'null') { |
|
| 243 | + if ($value['value']==='null') { |
|
| 244 | 244 | switch ($value['operator']) { |
| 245 | 245 | case '!=': |
| 246 | - $wheres[] = $key . ' IS NOT NULL'; |
|
| 246 | + $wheres[] = $key.' IS NOT NULL'; |
|
| 247 | 247 | break; |
| 248 | 248 | |
| 249 | 249 | case '==': |
| 250 | 250 | default: |
| 251 | - $wheres[] = $key . ' IS NULL'; |
|
| 251 | + $wheres[] = $key.' IS NULL'; |
|
| 252 | 252 | break; |
| 253 | 253 | } |
| 254 | 254 | } else { |
| 255 | 255 | $params[] = $value['value']; |
| 256 | - $wheres[] = $key . ' ' . $value['operator'] . ' ?'; |
|
| 256 | + $wheres[] = $key.' '.$value['operator'].' ?'; |
|
| 257 | 257 | } |
| 258 | 258 | } |
| 259 | 259 | } |
| 260 | 260 | } else { |
| 261 | - $wheres[] = $key . ' IN (' . implode(', ', array_map(array($this, 'escape'), $value)) . ')'; |
|
| 261 | + $wheres[] = $key.' IN ('.implode(', ', array_map(array($this, 'escape'), $value)).')'; |
|
| 262 | 262 | } |
| 263 | 263 | } |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | if (count($joins)) { |
| 267 | 267 | foreach ($joins as $table => $join) { |
| 268 | - $type = isset($join['type'])?$join['type']:'INNER'; |
|
| 269 | - $query .= ' '. $type.' JOIN `' . $table . '` as `' . $join['alias'] . '` ON ' . $join['on'] . ' '; |
|
| 268 | + $type = isset($join['type']) ? $join['type'] : 'INNER'; |
|
| 269 | + $query .= ' '.$type.' JOIN `'.$table.'` as `'.$join['alias'].'` ON '.$join['on'].' '; |
|
| 270 | 270 | //$countQuery .= ' '.$type.' JOIN ' . $table . ' ' . $join['alias'] . ' ON ' . $join['on'] . ' '; |
| 271 | 271 | } |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | if (count($manualJoins)) { |
| 275 | 275 | foreach ($manualJoins as $join) { |
| 276 | - $query .= ' ' . $join . ' '; |
|
| 276 | + $query .= ' '.$join.' '; |
|
| 277 | 277 | //$countQuery .= ' ' . $join . ' '; |
| 278 | 278 | } |
| 279 | 279 | } |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | $hasWhere = false; |
| 282 | 282 | if (count($wheres)) { |
| 283 | 283 | $hasWhere = true; |
| 284 | - $query .= ' WHERE (' . implode(' ' . $whereType . ' ', $wheres) . ')'; |
|
| 284 | + $query .= ' WHERE ('.implode(' '.$whereType.' ', $wheres).')'; |
|
| 285 | 285 | //$countQuery .= ' WHERE (' . implode(' ' . $whereType . ' ', $wheres) . ')'; |
| 286 | 286 | } |
| 287 | 287 | |
@@ -292,11 +292,11 @@ discard block |
||
| 292 | 292 | $query .= ' WHERE '; |
| 293 | 293 | //$countQuery .= ' WHERE '; |
| 294 | 294 | } else { |
| 295 | - $query .= ' ' . $where['type'] . ' '; |
|
| 295 | + $query .= ' '.$where['type'].' '; |
|
| 296 | 296 | //$countQuery .= ' ' . $where['type'] . ' '; |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - $query .= ' ' . $where['query']; |
|
| 299 | + $query .= ' '.$where['query']; |
|
| 300 | 300 | //$countQuery .= ' ' . $where['query']; |
| 301 | 301 | |
| 302 | 302 | if (isset($where['params'])) { |
@@ -308,28 +308,28 @@ discard block |
||
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | if (!is_null($group)) { |
| 311 | - $query .= ' GROUP BY ' . $group . ' '; |
|
| 311 | + $query .= ' GROUP BY '.$group.' '; |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | if (count($order)) { |
| 315 | 315 | $orders = array(); |
| 316 | - if (is_string($order) && $order == 'rand') { |
|
| 316 | + if (is_string($order) && $order=='rand') { |
|
| 317 | 317 | $query .= ' ORDER BY RAND() '; |
| 318 | 318 | } else { |
| 319 | 319 | foreach ($order as $key => $value) { |
| 320 | - $orders[] = $this->fieldCheck($key) . ' ' . $value; |
|
| 320 | + $orders[] = $this->fieldCheck($key).' '.$value; |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | - $query .= ' ORDER BY ' . implode(', ', $orders); |
|
| 323 | + $query .= ' ORDER BY '.implode(', ', $orders); |
|
| 324 | 324 | } |
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | if ($limit) { |
| 328 | - $query .= ' LIMIT ' . $limit; |
|
| 328 | + $query .= ' LIMIT '.$limit; |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | if ($offset) { |
| 332 | - $query .= ' OFFSET ' . $offset; |
|
| 332 | + $query .= ' OFFSET '.$offset; |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | |
@@ -347,7 +347,7 @@ discard block |
||
| 347 | 347 | try { |
| 348 | 348 | //$query = $this->compile_binds($query, $params); |
| 349 | 349 | |
| 350 | - return $this->adapter->query($query,$params); |
|
| 350 | + return $this->adapter->query($query, $params); |
|
| 351 | 351 | //ed( $this->adapter->query($query) ,1); |
| 352 | 352 | // if ($res = $this->adapter->getRows($query)) { |
| 353 | 353 | // $rtn = array(); |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | // } else { |
| 362 | 362 | // return false; |
| 363 | 363 | // } |
| 364 | - } catch(\PDOException $ex) { |
|
| 364 | + } catch (\PDOException $ex) { |
|
| 365 | 365 | throw $ex; |
| 366 | 366 | } |
| 367 | 367 | } |
@@ -376,7 +376,7 @@ discard block |
||
| 376 | 376 | */ |
| 377 | 377 | protected function compile_binds($sql, $binds) |
| 378 | 378 | { |
| 379 | - if (strpos($sql, $this->bind_marker) === FALSE) { |
|
| 379 | + if (strpos($sql, $this->bind_marker)===FALSE) { |
|
| 380 | 380 | return $sql; |
| 381 | 381 | } |
| 382 | 382 | |
@@ -1,7 +1,7 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | $loader = require_once __DIR__.'/../vendor/autoload.php'; |
| 3 | 3 | |
| 4 | -class TestHelper{ |
|
| 4 | +class TestHelper { |
|
| 5 | 5 | |
| 6 | 6 | /** |
| 7 | 7 | * получение защищенного свойства |
@@ -45,7 +45,7 @@ |
||
| 45 | 45 | 'primary' => true |
| 46 | 46 | ] |
| 47 | 47 | ) |
| 48 | - ->addMappingField('name','cty_name') |
|
| 48 | + ->addMappingField('name', 'cty_name') |
|
| 49 | 49 | ; |
| 50 | 50 | |
| 51 | 51 | } |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | public function createEntity(array $row) { |
| 33 | 33 | $Group = $this->DI->get('UserGroupMapper')->createEntity([]); |
| 34 | - return $this->buildEntity(new User('testname','[email protected]','asdftyasdvh21267g',$Group), $row); |
|
| 34 | + return $this->buildEntity(new User('testname', '[email protected]', 'asdftyasdvh21267g', $Group), $row); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | /** |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | 'primary' => true |
| 47 | 47 | ] |
| 48 | 48 | ) |
| 49 | - ->addMappingField('name','usr_name') |
|
| 49 | + ->addMappingField('name', 'usr_name') |
|
| 50 | 50 | ->addMappingField('email', 'usr_email') |
| 51 | 51 | ->addMappingField('password', 'usr_password') |
| 52 | 52 | ->addMappingField('group', [ |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | |
| 19 | 19 | protected $title; |
| 20 | 20 | |
| 21 | - function __construct($code,$title){ |
|
| 21 | + function __construct($code, $title) { |
|
| 22 | 22 | $this->setCode($code); |
| 23 | 23 | $this->setTitle($title); |
| 24 | 24 | } |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * @return type |
| 31 | 31 | */ |
| 32 | 32 | public function createEntity(array $row) { |
| 33 | - return $this->buildEntity(new UserGroup('admin','admin test'), $row); |
|
| 33 | + return $this->buildEntity(new UserGroup('admin', 'admin test'), $row); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
@@ -45,8 +45,8 @@ discard block |
||
| 45 | 45 | 'primary' => true |
| 46 | 46 | ] |
| 47 | 47 | ) |
| 48 | - ->addMappingField('title','grp_title') |
|
| 49 | - ->addMappingField('code','grp_code') |
|
| 48 | + ->addMappingField('title', 'grp_title') |
|
| 49 | + ->addMappingField('code', 'grp_code') |
|
| 50 | 50 | ; |
| 51 | 51 | |
| 52 | 52 | } |
@@ -24,20 +24,20 @@ |
||
| 24 | 24 | |
| 25 | 25 | $db = new \SimpleORM\Adapter\CodeigniterQueryBuilder(get_instance()->db); |
| 26 | 26 | |
| 27 | - $this->getContainer()->add('UserMapper','Test\Domain\User\UserMapper') |
|
| 27 | + $this->getContainer()->add('UserMapper', 'Test\Domain\User\UserMapper') |
|
| 28 | 28 | ->withArgument($this->getContainer()) |
| 29 | 29 | ->withArgument($db) |
| 30 | 30 | ->withArgument($__AR2['autoresource_db']); |
| 31 | 31 | |
| 32 | - $this->getContainer()->add('UserGroupMapper','Test\Domain\UserGroup\UserGroupMapper') |
|
| 32 | + $this->getContainer()->add('UserGroupMapper', 'Test\Domain\UserGroup\UserGroupMapper') |
|
| 33 | 33 | ->withArgument($this->getContainer()) |
| 34 | 34 | ->withArgument($db) |
| 35 | 35 | ->withArgument($__AR2['autoresource_db']); |
| 36 | - $this->getContainer()->add('UserAddressMapper','Test\Domain\UserAddress\UserAddressMapper') |
|
| 36 | + $this->getContainer()->add('UserAddressMapper', 'Test\Domain\UserAddress\UserAddressMapper') |
|
| 37 | 37 | ->withArgument($this->getContainer()) |
| 38 | 38 | ->withArgument($db) |
| 39 | 39 | ->withArgument($__AR2['autoresource_db']); |
| 40 | - $this->getContainer()->add('CityMapper','Test\Domain\City\CityMapper') |
|
| 40 | + $this->getContainer()->add('CityMapper', 'Test\Domain\City\CityMapper') |
|
| 41 | 41 | ->withArgument($this->getContainer()) |
| 42 | 42 | ->withArgument($db) |
| 43 | 43 | ->withArgument($__AR2['autoresource_db']); |