update
This commit is contained in:
parent
adb7ff5a03
commit
e9179ee084
@ -3,9 +3,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace catcher\traits\db;
|
namespace catcher\traits\db;
|
||||||
|
|
||||||
use catcher\CatchModelCollection;
|
|
||||||
use catcher\Utils;
|
use catcher\Utils;
|
||||||
use think\Collection;
|
|
||||||
|
|
||||||
trait BaseOptionsTrait
|
trait BaseOptionsTrait
|
||||||
{
|
{
|
||||||
@ -189,25 +187,4 @@ trait BaseOptionsTrait
|
|||||||
|
|
||||||
return $model->save();
|
return $model->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* rewrite collection
|
|
||||||
*
|
|
||||||
* @time 2020年10月20日
|
|
||||||
* @param array|iterable $collection
|
|
||||||
* @param string|null $resultSetType
|
|
||||||
* @return CatchModelCollection|mixed
|
|
||||||
*/
|
|
||||||
public function toCollection(iterable $collection = [], string $resultSetType = null): Collection
|
|
||||||
{
|
|
||||||
$resultSetType = $resultSetType ?: $this->resultSetType;
|
|
||||||
|
|
||||||
if ($resultSetType && false !== strpos($resultSetType, '\\')) {
|
|
||||||
$collection = new $resultSetType($collection);
|
|
||||||
} else {
|
|
||||||
$collection = new CatchModelCollection($collection);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $collection;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace catcher\traits\db;
|
namespace catcher\traits\db;
|
||||||
|
|
||||||
|
use catcher\CatchModelCollection;
|
||||||
|
use think\Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 重写 think\Model 的方法
|
* 重写 think\Model 的方法
|
||||||
*
|
*
|
||||||
@ -53,4 +56,25 @@ trait RewriteTrait
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* rewrite collection
|
||||||
|
*
|
||||||
|
* @time 2020年10月20日
|
||||||
|
* @param array|iterable $collection
|
||||||
|
* @param string|null $resultSetType
|
||||||
|
* @return CatchModelCollection|mixed
|
||||||
|
*/
|
||||||
|
public function toCollection(iterable $collection = [], string $resultSetType = null): Collection
|
||||||
|
{
|
||||||
|
$resultSetType = $resultSetType ?: $this->resultSetType;
|
||||||
|
|
||||||
|
if ($resultSetType && false !== strpos($resultSetType, '\\')) {
|
||||||
|
$collection = new $resultSetType($collection);
|
||||||
|
} else {
|
||||||
|
$collection = new CatchModelCollection($collection);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $collection;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user