From 46ce4edce0ac6ffc93f49d48e7b72a51854333ab Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Mon, 16 Dec 2024 17:53:11 +0100 Subject: [PATCH] Tpl::register_modifier(): make name optional and allow to register multiple modifiers in one call --- src/Tpl.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Tpl.php b/src/Tpl.php index 76a57e4..b72f3d8 100644 --- a/src/Tpl.php +++ b/src/Tpl.php @@ -334,11 +334,27 @@ class Tpl { /** * Register a modifier usable from template files - * @param string $name The modifier name - * @param callable $callable The modifier function + * @param string|callable|array $name_or_callable The modifier name (or modifier callable) + * @param callable|null $callable The modifier callable (optional) * @return void */ - public static function register_modifier($name, $callable) { + public static function register_modifier($name_or_callable, $callable=null) { + if (is_array($name_or_callable) && is_null($callable) && !is_callable($name_or_callable)) { + foreach($name_or_callable as $callable) + self :: register_modifier($callable); + return; + } + $name = ( + $callable? + $name_or_callable: + ( + is_array($name_or_callable)? + $name_or_callable[1]: + $name_or_callable + ) + ); + $callable = $callable ?? $name_or_callable; + Log::debug("Register callable %s as modifier %s", format_callable($callable), $name); self :: $smarty -> registerPlugin("modifier", $name, $callable); }