From ad70e14f83e444ba1edddf86477b4012e5ae2193 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Thu, 4 Mar 2021 00:04:37 +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 | 4 ++-- Database/Base/BaseActiveRecord.php | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Database/ActiveRecord.php b/Database/ActiveRecord.php index 555e7104..af509d2c 100644 --- a/Database/ActiveRecord.php +++ b/Database/ActiveRecord.php @@ -275,11 +275,11 @@ class ActiveRecord extends BaseActiveRecord public function toArray(): array { $data = $this->_attributes; - foreach ($this->getAnnotation() as $key => $item) { + foreach ($this->getAnnotation('get') as $key => $item) { if (!isset($data[$key])) { continue; } - $data[$key] = call_user_func([$this, $item[1]], $data[$key]); + $data[$key] = call_user_func($item, $data[$key]); } $data = array_merge($data, $this->runRelate()); $this->recover(); diff --git a/Database/Base/BaseActiveRecord.php b/Database/Base/BaseActiveRecord.php index df5086a2..10f454b8 100644 --- a/Database/Base/BaseActiveRecord.php +++ b/Database/Base/BaseActiveRecord.php @@ -820,11 +820,12 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess /** + * @param string $type * @return array */ - protected function getAnnotation(): array + protected function getAnnotation($type = 'get'): array { - return $this->_annotations; + return $this->_annotations[$type] ?? []; }