From 3d69e7a2fd5569bc50962da54545d69093a0cb7b Mon Sep 17 00:00:00 2001 From: Steffen Gransow Date: Tue, 7 Jul 2015 17:15:02 +0200 Subject: [PATCH] allow getValue to use an attribute value path This makes it easier to get nested values from an Entity. The downside atm would be that the setValue doesn't vehave the same as it just sets current level attributes instead of trying to change nested ones. refs #1 --- src/Runtime/Entity/Entity.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Runtime/Entity/Entity.php b/src/Runtime/Entity/Entity.php index 841a1d2..23c78e8 100644 --- a/src/Runtime/Entity/Entity.php +++ b/src/Runtime/Entity/Entity.php @@ -3,8 +3,10 @@ namespace Trellis\Runtime\Entity; use Closure; +use JsonSerializable; use Trellis\Common\Error\RuntimeException; use Trellis\Common\Object; +use Trellis\Runtime\Attribute\AttributeValuePath; use Trellis\Runtime\EntityTypeInterface; use Trellis\Runtime\Validator\Result\IncidentInterface; use Trellis\Runtime\Validator\Result\ResultMap; @@ -13,7 +15,6 @@ use Trellis\Runtime\ValueHolder\ValueChangedListenerInterface; use Trellis\Runtime\ValueHolder\ValueHolderInterface; use Trellis\Runtime\ValueHolder\ValueHolderMap; -use JsonSerializable; /** * Entity generically implements the EntityInterface interface @@ -182,9 +183,13 @@ public function setValues(array $values) */ public function getValue($attribute_name) { - $value_holder = $this->getValueHolderFor($attribute_name); + if (!mb_strpos($attribute_name, '.')) { + $value_holder = $this->getValueHolderFor($attribute_name); + return $value_holder->getValue(); + } else { + return AttributeValuePath::getAttributeValueByPath($this, $attribute_path); + } - return $value_holder->getValue(); } /**