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: 3 additions & 1 deletion src/View/Antlers/Language/Runtime/PathDataManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,9 @@ private function reduceVar($path, $processorData = [])
}

if (is_object($this->reducedVar) && method_exists($this->reducedVar, Str::camel($varPath))) {
$this->reducedVar = call_user_func_array([$this->reducedVar, Str::camel($varPath)], []);
$reflectionMethod = new \ReflectionMethod($this->reducedVar, Str::camel($varPath));

$this->reducedVar = $reflectionMethod->isPublic() ? call_user_func_array([$this->reducedVar, Str::camel($varPath)], []) : null;
$this->resolvedPath[] = '{method:'.$varPath.'}';

if ($doCompact) {
Expand Down
34 changes: 34 additions & 0 deletions tests/Antlers/Runtime/DataRetrieverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,38 @@ public function test_dynamic_keys_are_correctly_set()
$value = $this->getPathValue('page[view:nested:nested1:nested2]', $data);
$this->assertSame(12345, $value);
}

public function test_object_methods_are_retrieved()
{
$data = [
'view' => [
'object' => new class
{
public function publicMethod()
{
return 'Hello Public World!';
}

protected function protectedMethod()
{
return 'Hello Protected World!';
}

private function privateMethod()
{
return 'Hello Private World!';
}
},
],
];

$value = $this->getPathValue('view.object.public_method', $data);
$this->assertSame('Hello Public World!', $value);

$value = $this->getPathValue('view.object.protected_method', $data);
$this->assertNull($value);

$value = $this->getPathValue('view.object.private_method', $data);
$this->assertNull($value);
}
}
Loading