From 43c6652f8791e966d9739c87ffbd78dc7866e285 Mon Sep 17 00:00:00 2001 From: nateiler Date: Fri, 11 Jan 2019 14:48:01 -0700 Subject: [PATCH] consider getter priorities w/ dirty attributes --- src/records/ActiveRecord.php | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/records/ActiveRecord.php b/src/records/ActiveRecord.php index e312d5f..7707ab0 100644 --- a/src/records/ActiveRecord.php +++ b/src/records/ActiveRecord.php @@ -205,7 +205,7 @@ public function rules() } /******************************************* - * MAGIC + * ATTRIBUTES *******************************************/ /** @@ -214,13 +214,37 @@ public function rules() */ public function __get($name) { - $getter = 'get' . $name; - if (in_array($name, $this->getterPriorityAttributes, true) && - method_exists($this, $getter) - ) { - return $this->$getter(); + if ($this->hasGetterPriority($name)) { + $this->{'get' . $name}(); } return parent::__get($name); } + + /** + * @inheritdoc + */ + public function getDirtyAttributes($names = null) + { + $attributes = $names ?: $this->getterPriorityAttributes; + + // Call each attribute to see if the 'getter' has a value + foreach($attributes as $attribute) { + if ($this->hasGetterPriority($attribute)) { + $this->{'get' . $attribute}(); + } + } + + return parent::getDirtyAttributes($names); + } + + /** + * @param $name + * @return bool + */ + protected function hasGetterPriority($name) + { + return in_array($name, $this->getterPriorityAttributes, true) && + method_exists($this, 'get' . $name); + } }