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:
Fabien Potencier
2010-05-10 12:46:52 +02:00
parent 362613c302
commit 79e5058611
3 changed files with 59 additions and 9 deletions
+27
View File
@@ -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