Skip to content

Commit

Permalink
allow getValue to use an attribute value path
Browse files Browse the repository at this point in the history
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
  • Loading branch information
graste committed Jul 7, 2015
1 parent 5784da8 commit 3d69e7a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Runtime/Entity/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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();
}

/**
Expand Down

0 comments on commit 3d69e7a

Please sign in to comment.