mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-20 14:36:57 +00:00
added support for __call() in expression resolution (closes #2)
The new algorithm for object method resolution is now the following: * get all methods declared for `$object` using ReflectionObject::getMethods() * check if `$item` is in the list of method names * check if `get$item` is in the list of method names * check if `__call` is defined and pass `$item` as the method name
This commit is contained in:
+27
@@ -0,0 +1,27 @@
|
||||
--TEST--
|
||||
Twig supports __call() for attributes
|
||||
--TEMPLATE--
|
||||
{{ foo.foo }}
|
||||
{{ foo.bar }}
|
||||
--DATA--
|
||||
class TestClassForMagicCallAttributes
|
||||
{
|
||||
public function getBar()
|
||||
{
|
||||
return 'bar_from_getbar';
|
||||
}
|
||||
|
||||
public function __call($method, $arguments)
|
||||
{
|
||||
if ('foo' === $method)
|
||||
{
|
||||
return 'foo_from_call';
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return array('foo' => new TestClassForMagicCallAttributes())
|
||||
--EXPECT--
|
||||
foo_from_call
|
||||
bar_from_getbar
|
||||
Reference in New Issue
Block a user