Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Dust/Evaluate/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ public function resolveLocal(Ast\Identifier $identifier, $parentObject, $forceAr

public function findInObject($key, $parent) {
if (is_object($parent) && !is_numeric($key)) {
//prop or method
if (array_key_exists($key, $parent)) {
//prop || overloaded prop or method
if (array_key_exists($key, $parent) || ( !($parent instanceof \Closure) && isset($parent->{$key})) ) {
return $parent->{$key};
} elseif (method_exists($parent, $key)) {
return (new \ReflectionMethod($parent, $key))->getClosure($parent);
Expand Down
4 changes: 4 additions & 0 deletions tests/Dust/StandardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,9 @@ public function testCustomHelper() {
//test some things (kinda taken from PHP manual)
$this->assertTemplate('bcdef,bcd,abcd,abcdef,bc', '{@substr str="abcdef" begin=1 /},' . '{@substr str="abcdef" begin=1 len=3 /},' . '{@substr str="abcdef" len=4 /},' . '{@substr str="abcdef" len=8 /},' . '{@substr str="abcdef" begin=1 end=3 /}', (object)[]);
}

public function testIssetAccess() {
$this->assertTemplate('Farce,slapstick,musical comedy', '{#genres}{.}{@sep},{/sep}{/genres}', new StoogesContext());
}

}
18 changes: 17 additions & 1 deletion tests/Dust/StoogesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,21 @@ class StoogesContext {
public function names() {
return [new StoogeName('Larry'), new StoogeName('Curly'), new StoogeName('Moe')];
}


public function __isset($name)
{
if($name === 'genres')
{
return true;
}
}

public function __get($key)
{
if($key === 'genres')
{
return ['Farce', 'slapstick', 'musical comedy'];
}
}

}