改名
This commit is contained in:
@@ -18,6 +18,7 @@ use JetBrains\PhpStorm\Pure;
|
||||
use ReflectionException;
|
||||
use Snowflake\Abstracts\Component;
|
||||
use Database\ActiveRecord;
|
||||
use Snowflake\Channel;
|
||||
use Snowflake\Exception\ComponentException;
|
||||
use Snowflake\Exception\NotFindClassException;
|
||||
use Snowflake\Snowflake;
|
||||
@@ -35,7 +36,7 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat
|
||||
*/
|
||||
protected array $_item = [];
|
||||
|
||||
protected ?ActiveRecord $model;
|
||||
protected ActiveRecord|string|null $model;
|
||||
|
||||
protected ActiveQuery $query;
|
||||
|
||||
@@ -119,7 +120,10 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat
|
||||
if (is_object($model)) {
|
||||
return $model;
|
||||
}
|
||||
return objectPool($model, function () use ($model) {
|
||||
|
||||
/** @var Channel $channel */
|
||||
$channel = Snowflake::app()->get('channel');
|
||||
return $channel->pop($model, function () use ($model) {
|
||||
return new $model();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ use Database\Mysql\Columns;
|
||||
use Database\Relation;
|
||||
use Exception;
|
||||
use Snowflake\Abstracts\TraitApplication;
|
||||
use Snowflake\Channel;
|
||||
use Snowflake\Exception\ComponentException;
|
||||
use Snowflake\Exception\NotFindClassException;
|
||||
use validator\Validator;
|
||||
@@ -1032,8 +1033,9 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
|
||||
{
|
||||
$className = get_called_class();
|
||||
|
||||
/** @var static $model */
|
||||
$model = objectPool($className, function () use ($className) {
|
||||
/** @var Channel $channel */
|
||||
$channel = Snowflake::app()->get('channel');
|
||||
$model = $channel->pop($className, function () use ($className) {
|
||||
return new $className();
|
||||
});
|
||||
$model->_attributes = $data;
|
||||
|
||||
@@ -9,6 +9,7 @@ use Database\ActiveQuery;
|
||||
use Database\ActiveRecord;
|
||||
use Exception;
|
||||
use ReflectionException;
|
||||
use Snowflake\Channel;
|
||||
use Snowflake\Exception\NotFindClassException;
|
||||
use Snowflake\Snowflake;
|
||||
|
||||
@@ -56,14 +57,18 @@ class CollectionIterator extends \ArrayIterator
|
||||
*/
|
||||
protected function newModel($current): ActiveRecord
|
||||
{
|
||||
/** @var ActiveRecord|string $model */
|
||||
$model = $this->model;
|
||||
if (is_object($model)) {
|
||||
$model = get_class($model);
|
||||
}
|
||||
return objectPool($model, function () use ($model) {
|
||||
return new $model();
|
||||
})->setAttributes($current);
|
||||
|
||||
/** @var Channel $channel */
|
||||
$channel = Snowflake::app()->get('channel');
|
||||
$model = $channel->pop($model, function () use ($model) {
|
||||
return new $model();
|
||||
});
|
||||
return $model->setAttributes($current);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user