From 01b01e2049d21b12eba74bded5456d2db8c692cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Wed, 28 Apr 2021 11:11:04 +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/Base/BaseActiveRecord.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/Database/Base/BaseActiveRecord.php b/Database/Base/BaseActiveRecord.php index 24d1c94a..42d236ce 100644 --- a/Database/Base/BaseActiveRecord.php +++ b/Database/Base/BaseActiveRecord.php @@ -842,13 +842,38 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess */ public function __get($name): mixed { - if (Snowflake::app()->has($name)) return Snowflake::getApp($name); + if (Snowflake::app()->has($name)) { + return Snowflake::getApp($name); + } else { + return $this->_gets($name); + } + } + + /** + * @param $name + * @return mixed + * @throws Exception + */ + private function _gets($name): mixed + { $value = $this->_attributes[$name] ?? null; $method = $this->_get_annotation($name, static::GET); if (!empty($method)) { return $this->{$method}($value); } + return $this->runRelation($name, $value); + } + + + /** + * @param $name + * @param $value + * @return mixed + * @throws Exception + */ + private function runRelation($name, $value): mixed + { $relation = $this->_get_annotation($name, static::RELATE); if (empty($relation)) { return $this->_decode($name, $value);