Skip to content
Snippets Groups Projects
Commit 772895be authored by Elmar Ludwig's avatar Elmar Ludwig Committed by David Siegfried
Browse files

require Closure instead of callable, fixes #2446

Closes #2446

Merge request studip/studip!1669
parent 43f35cc4
No related branches found
No related tags found
No related merge requests found
......@@ -320,7 +320,7 @@ class FunctionExpression implements Expression
$arguments[] = $expr->value($context);
}
if (is_callable($callable)) {
if ($callable instanceof \Closure) {
return call_user_func_array($callable, $arguments);
}
......
......@@ -49,7 +49,10 @@ class Template
public function __construct($string)
{
$this->template = new ArrayNode();
$this->functions = array('count' => 'count', 'strlen' => 'mb_strlen');
$this->functions = array(
'count' => function($a) { return count($a); },
'strlen' => function($a) { return mb_strlen($a); }
);
self::parseTemplate($this->template, $string, 0);
}
......
......@@ -168,8 +168,12 @@ class template_test extends PHPUnit\Framework\TestCase
public function testFilters()
{
$bindings = array('pi' => 3.14159, 'format_number' => 'number_format', 'upper' => 'strtoupper');
$template = '{pi|format_number(3) ~ ":" ~ "foobar"|upper}';
$bindings = array(
'pi' => 3.14159,
'format' => function($a, $b) { return number_format($a, $b); },
'upper' => function($a) { return strtoupper($a); }
);
$template = '{pi|format(3) ~ ":" ~ "foobar"|upper}';
$expected = '3.142:FOOBAR';
$tmpl_obj = new Template($template);
......@@ -178,7 +182,7 @@ class template_test extends PHPUnit\Framework\TestCase
public function testRawFilter()
{
$bindings = array('foo' => '<img>', 'upper' => 'strtoupper');
$bindings = array('foo' => '<img>', 'upper' => function($a) { return strtoupper($a); });
$template = '{foo}:{foo|upper|raw}';
$expected = '&lt;img&gt;:<IMG>';
$tmpl_obj = new Template($template);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment