@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | } elseif (array_key_exists($name, $this->relation)) { |
| 272 | 272 | return $this->relation[$name]; |
| 273 | 273 | } |
| 274 | - throw new InvalidArgumentException('property not exists:' . static::class . '->' . $name); |
|
| 274 | + throw new InvalidArgumentException('property not exists:'.static::class.'->'.$name); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | /** |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | if ($this->force) { |
| 285 | 285 | $data = $this->data; |
| 286 | 286 | } else { |
| 287 | - $data = array_udiff_assoc($this->data, $this->origin, function ($a, $b) { |
|
| 287 | + $data = array_udiff_assoc($this->data, $this->origin, function($a, $b) { |
|
| 288 | 288 | if ((empty($a) || empty($b)) && $a !== $b) { |
| 289 | 289 | return 1; |
| 290 | 290 | } |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | $value = $this->autoWriteTimestamp($name); |
| 325 | 325 | } else { |
| 326 | 326 | // 检测修改器 |
| 327 | - $method = 'set' . Loader::parseName($name, 1) . 'Attr'; |
|
| 327 | + $method = 'set'.Loader::parseName($name, 1).'Attr'; |
|
| 328 | 328 | |
| 329 | 329 | if (method_exists($this, $method)) { |
| 330 | 330 | $origin = $this->data; |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | |
| 482 | 482 | // 检测属性获取器 |
| 483 | 483 | $fieldName = Loader::parseName($name); |
| 484 | - $method = 'get' . Loader::parseName($name, 1) . 'Attr'; |
|
| 484 | + $method = 'get'.Loader::parseName($name, 1).'Attr'; |
|
| 485 | 485 | |
| 486 | 486 | if (isset($this->withAttr[$fieldName])) { |
| 487 | 487 | if ($notFound && $relation = $this->isRelationAttr($name)) { |
@@ -540,7 +540,7 @@ discard block |
||
| 540 | 540 | $key = is_numeric($key) ? $attr : $key; |
| 541 | 541 | |
| 542 | 542 | if (isset($item[$key])) { |
| 543 | - throw new Exception('bind attr has exists:' . $key); |
|
| 543 | + throw new Exception('bind attr has exists:'.$key); |
|
| 544 | 544 | } else { |
| 545 | 545 | $item[$key] = $value ? $value->getAttr($attr) : null; |
| 546 | 546 | } |
@@ -556,7 +556,7 @@ discard block |
||
| 556 | 556 | } |
| 557 | 557 | } |
| 558 | 558 | |
| 559 | - throw new InvalidArgumentException('property not exists:' . static::class . '->' . $name); |
|
| 559 | + throw new InvalidArgumentException('property not exists:'.static::class.'->'.$name); |
|
| 560 | 560 | } |
| 561 | 561 | |
| 562 | 562 | /** |
@@ -85,7 +85,7 @@ |
||
| 85 | 85 | foreach ($append as $key => $attr) { |
| 86 | 86 | $key = is_numeric($key) ? $attr : $key; |
| 87 | 87 | if (isset($this->data[$key])) { |
| 88 | - throw new Exception('bind attr has exists:' . $key); |
|
| 88 | + throw new Exception('bind attr has exists:'.$key); |
|
| 89 | 89 | } else { |
| 90 | 90 | $this->data[$key] = $model->$attr; |
| 91 | 91 | } |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | public function setRelation($name, $value, $data = []) |
| 105 | 105 | { |
| 106 | 106 | // 检测修改器 |
| 107 | - $method = 'set' . Loader::parseName($name, 1) . 'Attr'; |
|
| 107 | + $method = 'set'.Loader::parseName($name, 1).'Attr'; |
|
| 108 | 108 | |
| 109 | 109 | if (method_exists($this, $method)) { |
| 110 | 110 | $value = $this->$method($value, array_merge($this->data, $data)); |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | $count = $this->$relation()->relationCount($result, $closure, $aggregate, $field, $name); |
| 325 | 325 | |
| 326 | 326 | if (empty($name)) { |
| 327 | - $name = Loader::parseName($relation) . '_' . $aggregate; |
|
| 327 | + $name = Loader::parseName($relation).'_'.$aggregate; |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | $result->setAttr($name, $count); |
@@ -423,8 +423,8 @@ discard block |
||
| 423 | 423 | // 记录当前关联信息 |
| 424 | 424 | $model = $this->parseModel($model); |
| 425 | 425 | $name = Loader::parseName(basename(str_replace('\\', '/', $model))); |
| 426 | - $table = $table ?: Loader::parseName($this->name) . '_' . $name; |
|
| 427 | - $foreignKey = $foreignKey ?: $name . '_id'; |
|
| 426 | + $table = $table ?: Loader::parseName($this->name).'_'.$name; |
|
| 427 | + $foreignKey = $foreignKey ?: $name.'_id'; |
|
| 428 | 428 | $localKey = $localKey ?: $this->getForeignKey($this->name); |
| 429 | 429 | |
| 430 | 430 | return new BelongsToMany($this, $model, $table, $foreignKey, $localKey); |
@@ -451,8 +451,8 @@ discard block |
||
| 451 | 451 | if (is_array($morph)) { |
| 452 | 452 | list($morphType, $foreignKey) = $morph; |
| 453 | 453 | } else { |
| 454 | - $morphType = $morph . '_type'; |
|
| 455 | - $foreignKey = $morph . '_id'; |
|
| 454 | + $morphType = $morph.'_type'; |
|
| 455 | + $foreignKey = $morph.'_id'; |
|
| 456 | 456 | } |
| 457 | 457 | |
| 458 | 458 | $type = $type ?: get_class($this); |
@@ -483,8 +483,8 @@ discard block |
||
| 483 | 483 | if (is_array($morph)) { |
| 484 | 484 | list($morphType, $foreignKey) = $morph; |
| 485 | 485 | } else { |
| 486 | - $morphType = $morph . '_type'; |
|
| 487 | - $foreignKey = $morph . '_id'; |
|
| 486 | + $morphType = $morph.'_type'; |
|
| 487 | + $foreignKey = $morph.'_id'; |
|
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | return new MorphMany($this, $model, $foreignKey, $morphType, $type); |
@@ -510,8 +510,8 @@ discard block |
||
| 510 | 510 | if (is_array($morph)) { |
| 511 | 511 | list($morphType, $foreignKey) = $morph; |
| 512 | 512 | } else { |
| 513 | - $morphType = $morph . '_type'; |
|
| 514 | - $foreignKey = $morph . '_id'; |
|
| 513 | + $morphType = $morph.'_type'; |
|
| 514 | + $foreignKey = $morph.'_id'; |
|
| 515 | 515 | } |
| 516 | 516 | |
| 517 | 517 | return new MorphTo($this, $morphType, $foreignKey, $alias, $relation); |
@@ -547,7 +547,7 @@ discard block |
||
| 547 | 547 | $name = basename(str_replace('\\', '/', $name)); |
| 548 | 548 | } |
| 549 | 549 | |
| 550 | - return Loader::parseName($name) . '_id'; |
|
| 550 | + return Loader::parseName($name).'_id'; |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | /** |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | $query->where($data); |
| 147 | 147 | $data = null; |
| 148 | 148 | } elseif ($data instanceof \Closure) { |
| 149 | - call_user_func_array($data, [ & $query]); |
|
| 149 | + call_user_func_array($data, [& $query]); |
|
| 150 | 150 | $data = null; |
| 151 | 151 | } elseif (is_null($data)) { |
| 152 | 152 | return false; |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | if (false === strpos($field, '.')) { |
| 216 | - $field = '__TABLE__.' . $field; |
|
| 216 | + $field = '__TABLE__.'.$field; |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | if (!$read && strpos($field, '.')) { |
@@ -231,7 +231,7 @@ |
||
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | return $this->query |
| 234 | - ->whereExp($this->morphKey, '=' . $this->parent->getTable() . '.' . $this->parent->getPk()) |
|
| 234 | + ->whereExp($this->morphKey, '='.$this->parent->getTable().'.'.$this->parent->getPk()) |
|
| 235 | 235 | ->where($this->morphType, '=', $this->type) |
| 236 | 236 | ->fetchSql() |
| 237 | 237 | ->$aggregate($field); |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | // 关联查询 |
| 153 | 153 | $pk = $this->parent->getPk(); |
| 154 | 154 | |
| 155 | - $condition[] = ['pivot.' . $localKey, '=', $this->parent->$pk]; |
|
| 155 | + $condition[] = ['pivot.'.$localKey, '=', $this->parent->$pk]; |
|
| 156 | 156 | |
| 157 | 157 | return $this->belongsToManyQuery($foreignKey, $localKey, $condition); |
| 158 | 158 | } |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | */ |
| 282 | 282 | public function wherePivot($field, $op = null, $condition = null) |
| 283 | 283 | { |
| 284 | - $this->query->where('pivot.' . $field, $op, $condition); |
|
| 284 | + $this->query->where('pivot.'.$field, $op, $condition); |
|
| 285 | 285 | return $this; |
| 286 | 286 | } |
| 287 | 287 | |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | if (!empty($range)) { |
| 312 | 312 | // 查询关联数据 |
| 313 | 313 | $data = $this->eagerlyManyToMany([ |
| 314 | - ['pivot.' . $localKey, 'in', $range], |
|
| 314 | + ['pivot.'.$localKey, 'in', $range], |
|
| 315 | 315 | ], $relation, $subRelation, $closure); |
| 316 | 316 | |
| 317 | 317 | // 关联属性名 |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | $pk = $result->$pk; |
| 346 | 346 | // 查询管理数据 |
| 347 | 347 | $data = $this->eagerlyManyToMany([ |
| 348 | - ['pivot.' . $this->localKey, '=', $pk], |
|
| 348 | + ['pivot.'.$this->localKey, '=', $pk], |
|
| 349 | 349 | ], $relation, $subRelation, $closure); |
| 350 | 350 | |
| 351 | 351 | // 关联数据封装 |
@@ -386,7 +386,7 @@ discard block |
||
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | return $this->belongsToManyQuery($this->foreignKey, $this->localKey, [ |
| 389 | - ['pivot.' . $this->localKey, '=', $pk], |
|
| 389 | + ['pivot.'.$this->localKey, '=', $pk], |
|
| 390 | 390 | ])->$aggregate($field); |
| 391 | 391 | } |
| 392 | 392 | |
@@ -411,7 +411,7 @@ discard block |
||
| 411 | 411 | |
| 412 | 412 | return $this->belongsToManyQuery($this->foreignKey, $this->localKey, [ |
| 413 | 413 | [ |
| 414 | - 'pivot.' . $this->localKey, 'exp', $this->query->raw('=' . $this->parent->getTable() . '.' . $this->parent->getPk()), |
|
| 414 | + 'pivot.'.$this->localKey, 'exp', $this->query->raw('='.$this->parent->getTable().'.'.$this->parent->getPk()), |
|
| 415 | 415 | ], |
| 416 | 416 | ])->fetchSql()->$aggregate($field); |
| 417 | 417 | } |
@@ -479,7 +479,7 @@ discard block |
||
| 479 | 479 | |
| 480 | 480 | if (empty($this->baseQuery)) { |
| 481 | 481 | $relationFk = $this->query->getPk(); |
| 482 | - $query->join([$table => 'pivot'], 'pivot.' . $foreignKey . '=' . $tableName . '.' . $relationFk) |
|
| 482 | + $query->join([$table => 'pivot'], 'pivot.'.$foreignKey.'='.$tableName.'.'.$relationFk) |
|
| 483 | 483 | ->where($condition); |
| 484 | 484 | } |
| 485 | 485 | |
@@ -701,8 +701,8 @@ discard block |
||
| 701 | 701 | $table = $this->pivot->getTable(); |
| 702 | 702 | |
| 703 | 703 | $this->query |
| 704 | - ->join([$table => 'pivot'], 'pivot.' . $this->foreignKey . '=' . $this->query->getTable() . '.' . $this->query->getPk()) |
|
| 705 | - ->where('pivot.' . $this->localKey, $this->parent->$pk); |
|
| 704 | + ->join([$table => 'pivot'], 'pivot.'.$this->foreignKey.'='.$this->query->getTable().'.'.$this->query->getPk()) |
|
| 705 | + ->where('pivot.'.$this->localKey, $this->parent->$pk); |
|
| 706 | 706 | $this->baseQuery = true; |
| 707 | 707 | } |
| 708 | 708 | } |
@@ -107,16 +107,16 @@ discard block |
||
| 107 | 107 | $relationTable = $relation->getTable(); |
| 108 | 108 | |
| 109 | 109 | if ('*' != $id) { |
| 110 | - $id = $relationTable . '.' . $relation->getPk(); |
|
| 110 | + $id = $relationTable.'.'.$relation->getPk(); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | return $this->parent->db() |
| 114 | 114 | ->alias($model) |
| 115 | - ->field($model . '.*') |
|
| 116 | - ->join($throughTable, $throughTable . '.' . $this->foreignKey . '=' . $model . '.' . $this->localKey) |
|
| 117 | - ->join($relationTable, $relationTable . '.' . $throughKey . '=' . $throughTable . '.' . $this->throughPk) |
|
| 118 | - ->group($relationTable . '.' . $this->throughKey) |
|
| 119 | - ->having('count(' . $id . ')' . $operator . $count); |
|
| 115 | + ->field($model.'.*') |
|
| 116 | + ->join($throughTable, $throughTable.'.'.$this->foreignKey.'='.$model.'.'.$this->localKey) |
|
| 117 | + ->join($relationTable, $relationTable.'.'.$throughKey.'='.$throughTable.'.'.$this->throughPk) |
|
| 118 | + ->group($relationTable.'.'.$this->throughKey) |
|
| 119 | + ->having('count('.$id.')'.$operator.$count); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
@@ -145,9 +145,9 @@ discard block |
||
| 145 | 145 | |
| 146 | 146 | return $this->parent->db() |
| 147 | 147 | ->alias($model) |
| 148 | - ->join($throughTable, $throughTable . '.' . $this->foreignKey . '=' . $model . '.' . $this->localKey) |
|
| 149 | - ->join($modelTable, $modelTable . '.' . $throughKey . '=' . $throughTable . '.' . $this->throughPk) |
|
| 150 | - ->group($modelTable . '.' . $this->throughKey) |
|
| 148 | + ->join($throughTable, $throughTable.'.'.$this->foreignKey.'='.$model.'.'.$this->localKey) |
|
| 149 | + ->join($modelTable, $modelTable.'.'.$throughKey.'='.$throughTable.'.'.$this->throughPk) |
|
| 150 | + ->group($modelTable.'.'.$this->throughKey) |
|
| 151 | 151 | ->where($where) |
| 152 | 152 | ->field($fields); |
| 153 | 153 | } |
@@ -294,14 +294,14 @@ discard block |
||
| 294 | 294 | $modelTable = $this->parent->getTable(); |
| 295 | 295 | |
| 296 | 296 | if (false === strpos($field, '.')) { |
| 297 | - $field = $alias . '.' . $field; |
|
| 297 | + $field = $alias.'.'.$field; |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | return $this->query |
| 301 | 301 | ->alias($alias) |
| 302 | - ->join($throughTable, $throughTable . '.' . $pk . '=' . $alias . '.' . $throughKey) |
|
| 303 | - ->join($modelTable, $modelTable . '.' . $this->localKey . '=' . $throughTable . '.' . $this->foreignKey) |
|
| 304 | - ->where($throughTable . '.' . $this->foreignKey, $result->$localKey) |
|
| 302 | + ->join($throughTable, $throughTable.'.'.$pk.'='.$alias.'.'.$throughKey) |
|
| 303 | + ->join($modelTable, $modelTable.'.'.$this->localKey.'='.$throughTable.'.'.$this->foreignKey) |
|
| 304 | + ->where($throughTable.'.'.$this->foreignKey, $result->$localKey) |
|
| 305 | 305 | ->$aggregate($field); |
| 306 | 306 | } |
| 307 | 307 | |
@@ -327,14 +327,14 @@ discard block |
||
| 327 | 327 | $modelTable = $this->parent->getTable(); |
| 328 | 328 | |
| 329 | 329 | if (false === strpos($field, '.')) { |
| 330 | - $field = $alias . '.' . $field; |
|
| 330 | + $field = $alias.'.'.$field; |
|
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | return $this->query |
| 334 | 334 | ->alias($alias) |
| 335 | - ->join($throughTable, $throughTable . '.' . $pk . '=' . $alias . '.' . $throughKey) |
|
| 336 | - ->join($modelTable, $modelTable . '.' . $this->localKey . '=' . $throughTable . '.' . $this->foreignKey) |
|
| 337 | - ->whereExp($throughTable . '.' . $this->foreignKey, '=' . $this->parent->getTable() . '.' . $this->localKey) |
|
| 335 | + ->join($throughTable, $throughTable.'.'.$pk.'='.$alias.'.'.$throughKey) |
|
| 336 | + ->join($modelTable, $modelTable.'.'.$this->localKey.'='.$throughTable.'.'.$this->foreignKey) |
|
| 337 | + ->whereExp($throughTable.'.'.$this->foreignKey, '='.$this->parent->getTable().'.'.$this->localKey) |
|
| 338 | 338 | ->fetchSql() |
| 339 | 339 | ->$aggregate($field); |
| 340 | 340 | } |
@@ -357,9 +357,9 @@ discard block |
||
| 357 | 357 | $this->query |
| 358 | 358 | ->field($fields) |
| 359 | 359 | ->alias($alias) |
| 360 | - ->join($throughTable, $throughTable . '.' . $pk . '=' . $alias . '.' . $throughKey) |
|
| 361 | - ->join($modelTable, $modelTable . '.' . $this->localKey . '=' . $throughTable . '.' . $this->foreignKey) |
|
| 362 | - ->where($throughTable . '.' . $this->foreignKey, $this->parent->{$this->localKey}); |
|
| 360 | + ->join($throughTable, $throughTable.'.'.$pk.'='.$alias.'.'.$throughKey) |
|
| 361 | + ->join($modelTable, $modelTable.'.'.$this->localKey.'='.$throughTable.'.'.$this->foreignKey) |
|
| 362 | + ->where($throughTable.'.'.$this->foreignKey, $this->parent->{$this->localKey}); |
|
| 363 | 363 | |
| 364 | 364 | $this->baseQuery = true; |
| 365 | 365 | } |
@@ -82,9 +82,9 @@ discard block |
||
| 82 | 82 | $query->via($joinAlias); |
| 83 | 83 | |
| 84 | 84 | if ($this instanceof BelongsTo) { |
| 85 | - $joinOn = $name . '.' . $this->foreignKey . '=' . $joinAlias . '.' . $this->localKey; |
|
| 85 | + $joinOn = $name.'.'.$this->foreignKey.'='.$joinAlias.'.'.$this->localKey; |
|
| 86 | 86 | } else { |
| 87 | - $joinOn = $name . '.' . $this->localKey . '=' . $joinAlias . '.' . $this->foreignKey; |
|
| 87 | + $joinOn = $name.'.'.$this->localKey.'='.$joinAlias.'.'.$this->foreignKey; |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | if ($closure) { |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | $query->join([$joinTable => $joinAlias], $joinOn, $joinType) |
| 102 | - ->field($field, false, $joinTable, $joinAlias, $relation . '__'); |
|
| 102 | + ->field($field, false, $joinTable, $joinAlias, $relation.'__'); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | foreach ($this->bindAttr as $key => $attr) { |
| 292 | 292 | $key = is_numeric($key) ? $attr : $key; |
| 293 | 293 | if (isset($result->$key)) { |
| 294 | - throw new Exception('bind attr has exists:' . $key); |
|
| 294 | + throw new Exception('bind attr has exists:'.$key); |
|
| 295 | 295 | } else { |
| 296 | 296 | $result->setAttr($key, $model ? $model->$attr : null); |
| 297 | 297 | } |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | return $this->query |
| 91 | - ->whereExp($this->localKey, '=' . $this->parent->getTable() . '.' . $this->foreignKey) |
|
| 91 | + ->whereExp($this->localKey, '='.$this->parent->getTable().'.'.$this->foreignKey) |
|
| 92 | 92 | ->fetchSql() |
| 93 | 93 | ->$aggregate($field); |
| 94 | 94 | } |
@@ -143,10 +143,10 @@ discard block |
||
| 143 | 143 | |
| 144 | 144 | return $this->parent->db() |
| 145 | 145 | ->alias($model) |
| 146 | - ->whereExists(function ($query) use ($table, $model, $relation, $localKey, $foreignKey) { |
|
| 146 | + ->whereExists(function($query) use ($table, $model, $relation, $localKey, $foreignKey) { |
|
| 147 | 147 | $query->table([$table => $relation]) |
| 148 | - ->field($relation . '.' . $localKey) |
|
| 149 | - ->whereExp($model . '.' . $foreignKey, '=' . $relation . '.' . $localKey); |
|
| 148 | + ->field($relation.'.'.$localKey) |
|
| 149 | + ->whereExp($model.'.'.$foreignKey, '='.$relation.'.'.$localKey); |
|
| 150 | 150 | }); |
| 151 | 151 | } |
| 152 | 152 | |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | return $this->parent->db() |
| 173 | 173 | ->alias($model) |
| 174 | 174 | ->field($fields) |
| 175 | - ->join([$table => $relation], $model . '.' . $this->foreignKey . '=' . $relation . '.' . $this->localKey, $this->joinType) |
|
| 175 | + ->join([$table => $relation], $model.'.'.$this->foreignKey.'='.$relation.'.'.$this->localKey, $this->joinType) |
|
| 176 | 176 | ->where($where); |
| 177 | 177 | } |
| 178 | 178 | |