Skip to content

Commit

Permalink
fixed named args for static methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kriswallsmith committed Jan 29, 2015
1 parent 6b434f4 commit 7868fe8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/Twig/Node/Expression/Call.php
Expand Up @@ -120,6 +120,9 @@ protected function getArguments($callable, $arguments)
} elseif (is_object($callable) && !$callable instanceof Closure) {
$r = new ReflectionObject($callable);
$r = $r->getMethod('__invoke');
} elseif (is_string($callable) && false !== strpos($callable, '::')) {
$parts = explode('::', $callable, 2);
$r = new ReflectionMethod($parts[0], $parts[1]);
} else {
$r = new ReflectionFunction($callable);
}
Expand Down
10 changes: 10 additions & 0 deletions test/Twig/Tests/Node/Expression/CallTest.php
Expand Up @@ -78,6 +78,16 @@ public function testResolveArgumentsOnlyNecessaryArgumentsForCustomFunction()
$this->assertEquals(array('arg1'), $node->getArguments(array($this, 'customFunction'), array('arg1' => 'arg1')));
}

public function testGetArgumentsForStaticMethod()
{
$node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'custom_static_function'));
$this->assertEquals(array('arg1'), $node->getArguments(__CLASS__.'::customStaticFunction', array('arg1' => 'arg1')));
}

public static function customStaticFunction($arg1, $arg2 = 'default', $arg3 = array())
{
}

public function customFunction($arg1, $arg2 = 'default', $arg3 = array())
{
}
Expand Down

0 comments on commit 7868fe8

Please sign in to comment.