From 3bf7dda541266d9923270d2f1ea18431b2394568 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Mon, 29 Jan 2024 10:36:31 -0500 Subject: [PATCH] set/get dynamic properties from the extensionData['dynamicProperties'] --- src/Extension/ExtendableTrait.php | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/Extension/ExtendableTrait.php b/src/Extension/ExtendableTrait.php index 640acde7..96abf3b3 100644 --- a/src/Extension/ExtendableTrait.php +++ b/src/Extension/ExtendableTrait.php @@ -209,11 +209,7 @@ public function addDynamicProperty($dynamicName, $value = null) } self::$extendableGuardProperties = false; - if (!property_exists($this, $dynamicName)) { - $this->{$dynamicName} = $value; - } - - $this->extensionData['dynamicProperties'][] = $dynamicName; + array_set($this->extensionData['dynamicProperties'], $dynamicName, $value); self::$extendableGuardProperties = true; } @@ -327,12 +323,7 @@ public function getClassMethods() */ public function getDynamicProperties() { - $result = []; - $propertyNames = $this->extensionData['dynamicProperties']; - foreach ($propertyNames as $propName) { - $result[$propName] = $this->{$propName}; - } - return $result; + return $this->extensionData['dynamicProperties']; } /** @@ -378,6 +369,10 @@ protected function extendableIsAccessible($class, $propertyName) */ public function extendableGet($name) { + if (isset($this->extensionData['dynamicProperties'][$name])) { + return $this->extensionData['dynamicProperties'][$name]; + } + foreach ($this->extensionData['extensions'] as $extensionObject) { if ( property_exists($extensionObject, $name) &&