From a1384ba812bab35c5f6f20d91e1ef76ca10228bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 19 Jan 2021 19:22:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Database/ActiveRecord.php | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/Database/ActiveRecord.php b/Database/ActiveRecord.php index 4f3ef48e..c56afd82 100644 --- a/Database/ActiveRecord.php +++ b/Database/ActiveRecord.php @@ -314,25 +314,37 @@ class ActiveRecord extends BaseActiveRecord $attributes = Snowflake::app()->getAttributes(); $callback = $attributes->getByClass(static::class); - var_dump($callback); - $data = $this->_attributes; foreach ($callback as $key => $item) { - foreach ($item['attributes'] as $attribute) { - if (!($attribute instanceof Get)) { - continue; - } - $name = $attribute->name; - - $result = call_user_func($item['handler'], $data[$name]); - - $data[$name] = $result; - } + $data = $this->resolveAttributes($item, $data); } return array_merge($data, $this->runRelate()); } + + /** + * @param $item + * @param $data + * @return array + */ + private function resolveAttributes($item, $data): array + { + if (!isset($item['attributes'])) { + return $data; + } + foreach ($item['attributes'] as $attribute) { + if (!($attribute instanceof Get)) { + continue; + } + $name = $attribute->name; + $result = call_user_func($item['handler'], $data[$name]); + $data[$name] = $result; + } + return $data; + } + + /** * @return array * @throws Exception