invoke filter

This commit is contained in:
Lorenz
2024-12-26 20:11:14 +01:00
committed by Fabien Potencier
parent 9d1397afa4
commit 8b432758f6
2 changed files with 29 additions and 0 deletions
+15
View File
@@ -266,6 +266,7 @@ final class CoreExtension extends AbstractExtension
// iteration and runtime
new TwigFilter('default', [self::class, 'default'], ['node_class' => DefaultFilter::class]),
new TwigFilter('keys', [self::class, 'keys']),
new TwigFilter('invoke', [self::class, 'invoke']),
];
}
@@ -915,6 +916,20 @@ final class CoreExtension extends AbstractExtension
return array_keys($array);
}
/**
* Invokes a callable
*
* @param callable $callable
* @param ...$arguments
* @return mixed
*
* @internal
*/
public static function invoke(callable $callable, ...$arguments): mixed
{
return $callable(...$arguments);
}
/**
* Reverses a variable.
*
+14
View File
@@ -0,0 +1,14 @@
--TEST--
"invoke" filter
--TEMPLATE--
{% set func = x => 'Hello '~x %}
{{ func|invoke('World') }}
{% set func2 = (x, y) => x+y %}
{{ func2|invoke(3, 2) }}
--DATA--
return []
--CONFIG--
return []
--EXPECT--
Hello World
5