From c13d4101b9f6b615adc5867d7402732029586325 Mon Sep 17 00:00:00 2001 From: Administrator Date: Thu, 11 Nov 2021 03:14:52 +0800 Subject: [PATCH] 1 --- src/Base/AbstractCollection.php | 2 +- src/Base/CollectionIterator.php | 2 +- src/Base/Model.php | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Base/AbstractCollection.php b/src/Base/AbstractCollection.php index 003b19c..dd46ee5 100644 --- a/src/Base/AbstractCollection.php +++ b/src/Base/AbstractCollection.php @@ -134,7 +134,7 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat return NULL; } if (!($this->_item[$offset] instanceof ModelInterface)) { - return $this->model->setAttributes($this->_item[$offset]); + return $this->model::populate($this->_item[$offset]); } return $this->_item[$offset]; } diff --git a/src/Base/CollectionIterator.php b/src/Base/CollectionIterator.php index 1812257..acfa468 100644 --- a/src/Base/CollectionIterator.php +++ b/src/Base/CollectionIterator.php @@ -56,7 +56,7 @@ class CollectionIterator extends \ArrayIterator */ protected function newModel($current): ModelInterface { - return $this->model->setAttributes($current); + return $this->model::populate($current); } diff --git a/src/Base/Model.php b/src/Base/Model.php index 8ff7880..ca4d313 100644 --- a/src/Base/Model.php +++ b/src/Base/Model.php @@ -512,7 +512,9 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T if (empty($param)) { return $this; } - $this->_attributes = $param; + foreach ($this->_attributes as $key => $attribute) { + $this->_attributes[$key] = $this->_setter($key, $attribute); + } return $this; } @@ -525,7 +527,9 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T if (empty($param) || !is_array($param)) { return $this; } - $this->_oldAttributes = $param; + foreach ($this->_oldAttributes as $key => $attribute) { + $this->_oldAttributes[$key] = $this->_setter($key, $attribute); + } return $this; }