Tpl::register_modifier(): make name optional and allow to register multiple modifiers in one call
This commit is contained in:
parent
d642f3c9dd
commit
46ce4edce0
1 changed files with 19 additions and 3 deletions
22
src/Tpl.php
22
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<callable> $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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue