Skip to content

Commit

Permalink
set/get dynamic properties from the extensionData['dynamicProperties']
Browse files Browse the repository at this point in the history
  • Loading branch information
mjauvin committed Jan 29, 2024
1 parent 7b03a9f commit 3bf7dda
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/Extension/ExtendableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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'];
}

/**
Expand Down Expand Up @@ -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) &&
Expand Down

0 comments on commit 3bf7dda

Please sign in to comment.