removed usage of call_user_func when possible

This commit is contained in:
Fabien Potencier
2015-01-14 08:51:26 +01:00
parent a9fa64e31d
commit 5388a13641
9 changed files with 20 additions and 9 deletions
+2 -2
View File
@@ -839,7 +839,7 @@ class Twig_Environment
}
foreach ($this->filterCallbacks as $callback) {
if (false !== $filter = call_user_func($callback, $name)) {
if (false !== $filter = $callback($name)) {
return $filter;
}
}
@@ -966,7 +966,7 @@ class Twig_Environment
}
foreach ($this->functionCallbacks as $callback) {
if (false !== $function = call_user_func($callback, $name)) {
if (false !== $function = $callback($name)) {
return $function;
}
}
+1 -1
View File
@@ -45,7 +45,7 @@ class Twig_ExpressionParser
$this->parser->getStream()->next();
if (isset($op['callable'])) {
$expr = call_user_func($op['callable'], $this->parser, $expr);
$expr = $op['callable']($this->parser, $expr);
} else {
$expr1 = $this->parseExpression(self::OPERATOR_LEFT === $op['associativity'] ? $op['precedence'] + 1 : $op['precedence']);
$class = $op['class'];
+1 -1
View File
@@ -1127,7 +1127,7 @@ function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html',
}
if (isset($escapers[$strategy])) {
return call_user_func($escapers[$strategy], $env, $string, $charset);
return $escapers[$strategy]($env, $string, $charset);
}
$validStrategies = implode(', ', array_merge(array('html', 'js', 'url', 'css', 'html_attr'), array_keys($escapers)));
+1 -1
View File
@@ -78,7 +78,7 @@ class Twig_Filter
}
if (null !== $this->options['is_safe_callback']) {
return call_user_func($this->options['is_safe_callback'], $filterArgs);
return $this->options['is_safe_callback']($filterArgs);
}
}
+1 -1
View File
@@ -76,7 +76,7 @@ class Twig_Function
}
if (null !== $this->options['is_safe_callback']) {
return call_user_func($this->options['is_safe_callback'], $functionArgs);
return $this->options['is_safe_callback']($functionArgs);
}
return array();
+1 -2
View File
@@ -20,9 +20,8 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression
} elseif (is_array($callable) && $callable[0] instanceof Twig_ExtensionInterface) {
$compiler->raw(sprintf('$this->env->getExtension(\'%s\')->%s', $callable[0]->getName(), $callable[1]));
} else {
$type = ucfirst($this->getAttribute('type'));
$compiler->raw(sprintf('call_user_func_array($this->env->get%s(\'%s\')->getCallable(), array', $type, $this->getAttribute('name')));
$closingParenthesis = true;
$compiler->raw(sprintf('call_user_func_array($this->env->get%s(\'%s\')->getCallable(), array', ucfirst($this->getAttribute('type')), $this->getAttribute('name')));
}
$this->compileArguments($compiler);
+1 -1
View File
@@ -155,7 +155,7 @@ class Twig_Parser
throw new Twig_Error_Syntax('A block must start with a tag name', $token->getLine(), $this->getFilename());
}
if (null !== $test && call_user_func($test, $token)) {
if (null !== $test && $test($token)) {
if ($dropNeedle) {
$this->stream->next();
}
@@ -0,0 +1,10 @@
--TEST--
use an anonymous function as a function
--TEMPLATE--
{{ anon_foo('bar') }}
{{ 'bar'|anon_foo }}
--DATA--
return array()
--EXPECT--
*bar*
*bar*
+2
View File
@@ -143,6 +143,7 @@ class TwigTestExtension extends Twig_Extension
new Twig_Filter('preserves_safety', array($this, 'preserves_safety'), array('preserves_safety' => array('html'))),
new Twig_Filter('*_path', array($this, 'dynamic_path')),
new Twig_Filter('*_foo_*_bar', array($this, 'dynamic_foo')),
new Twig_Filter('anon_foo', function ($name) { return '*'.$name.'*'; }),
);
}
@@ -154,6 +155,7 @@ class TwigTestExtension extends Twig_Extension
new Twig_Function('unsafe_br', array($this, 'br')),
new Twig_Function('*_path', array($this, 'dynamic_path')),
new Twig_Function('*_foo_*_bar', array($this, 'dynamic_foo')),
new Twig_Function('anon_foo', function ($name) { return '*'.$name.'*'; }),
);
}