This commit is contained in:
2021-02-23 17:19:46 +08:00
parent 21bdf32fc3
commit 31d5024663
10 changed files with 41 additions and 26 deletions
+3 -4
View File
@@ -181,7 +181,7 @@ class ActiveQuery extends Component
*/
public function page(int $size, callable $callback): Pagination
{
$pagination = new Pagination($this);
$pagination = objectPool(Pagination::class, [$this]);
$pagination->setOffset(0);
$pagination->setLimit($size);
$pagination->setCallback($callback);
@@ -206,9 +206,8 @@ class ActiveQuery extends Component
*/
public function all(): Collection|array
{
$collect = new Collection($this, $this->modelClass::getDb()
->createCommand($this->queryBuilder())
->all(), $this->modelClass);
$data = $this->modelClass::getDb()->createCommand($this->queryBuilder())->all();
$collect = objectPool(Collection::class, [$this, $data, $this->modelClass]);
if ($this->asArray) {
return $collect->toArray();
}
+5 -5
View File
@@ -126,7 +126,7 @@ class ActiveRecord extends BaseActiveRecord
if (empty($attributes)) {
return \logger()->addError(FIND_OR_CREATE_MESSAGE, 'mysql');
}
$select = new static();
$select = objectPool(self::class);
$select->attributes = $attributes;
if (!$select->save()) {
throw new Exception($select->getLastError());
@@ -365,7 +365,7 @@ class ActiveRecord extends BaseActiveRecord
$relation = $this->getRelation();
return new HasOne($modelName, $foreignKey, $value, $relation);
return objectPool(HasOne::class, [$modelName, $foreignKey, $value, $relation]);
}
@@ -386,7 +386,7 @@ class ActiveRecord extends BaseActiveRecord
$relation = $this->getRelation();
return new HasCount($modelName, $foreignKey, $value, $relation);
return objectPool(HasCount::class, [$modelName, $foreignKey, $value, $relation]);
}
@@ -407,7 +407,7 @@ class ActiveRecord extends BaseActiveRecord
$relation = $this->getRelation();
return new HasMany($modelName, $foreignKey, $value, $relation);
return objectPool(HasMany::class, [$modelName, $foreignKey, $value, $relation]);
}
/**
@@ -427,7 +427,7 @@ class ActiveRecord extends BaseActiveRecord
$relation = $this->getRelation();
return new HasMany($modelName, $foreignKey, $value, $relation);
return objectPool(HasMany::class, [$modelName, $foreignKey, $value, $relation]);
}
/**
+1 -1
View File
@@ -107,7 +107,7 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat
*/
public function getModel(): ActiveRecord
{
return Snowflake::app()->getObject()->get($this->model, false);
return objectPool($this->model);
}
+1 -2
View File
@@ -898,8 +898,7 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
*/
public static function populate(array $data): static
{
$object = Snowflake::app()->getObject();
$model = $object->get(static::class);
$model = objectPool(static::class);
$model->setAttributes($data);
$model->setIsCreate(false);
$model->refresh();
+1 -4
View File
@@ -50,10 +50,7 @@ class CollectionIterator extends \ArrayIterator
*/
protected function newModel($current): ActiveRecord
{
$object = Snowflake::app()->getObject();
$model = $object->get($this->model, false);
return $model->setAttributes($current);
return objectPool($this->model)->setAttributes($current);
}
+1 -1
View File
@@ -198,7 +198,7 @@ class Collection extends AbstractCollection
}
$_filters[] = $value;
}
return new Collection($this->query, $_filters, $this->model);
return objectPool(Collection::class, [$this->query, $_filters, $this->model]);
}