diff options
| author | Lester Caine <lester@lsces.co.uk> | 2026-05-16 20:25:00 +0100 |
|---|---|---|
| committer | Lester Caine <lester@lsces.co.uk> | 2026-05-16 20:25:00 +0100 |
| commit | d729e91a69c82eeeadefe0f8d3a1139ec5492e63 (patch) | |
| tree | 062d92ca4a7f8dc4be979500133ca47cd1df8152 | |
| parent | 201dda1ed262fd49d633574936b82029b0d070d0 (diff) | |
| download | themes-d729e91a69c82eeeadefe0f8d3a1139ec5492e63.tar.gz themes-d729e91a69c82eeeadefe0f8d3a1139ec5492e63.tar.bz2 themes-d729e91a69c82eeeadefe0f8d3a1139ec5492e63.zip | |
Extend BitweaverExtension to allow a different route to use smarty plugins direct from php
| -rwxr-xr-x | includes/classes/BitweaverExtension.php | 28 | ||||
| -rw-r--r-- | smartyplugins/modifier.telephone_e164.php | 2 |
2 files changed, 27 insertions, 3 deletions
diff --git a/includes/classes/BitweaverExtension.php b/includes/classes/BitweaverExtension.php index 3d6ce08..4e4c5ba 100755 --- a/includes/classes/BitweaverExtension.php +++ b/includes/classes/BitweaverExtension.php @@ -46,10 +46,14 @@ class BitweaverExtension extends Base { $basename = basename($file); $functionName = str_replace('function.', '', $basename); $functionName = str_replace('.php', '', $functionName); - $this->callbacks[$functionName]['name'] = 'Smarty\\smarty_function_' . $functionName; + $callable = 'Bitweaver\\Plugins\\smarty_function_' . $functionName; + if (!is_callable($callable)) { + $callable = 'smarty_function_' . $functionName; + } + $this->callbacks[$functionName]['name'] = $callable; $this->callbacks[$functionName]['loaded'] = true; - if ( is_callable('Bitweaver\\Plugins\\smarty_function_' . $functionName )) { - $gBitSmarty->registerPlugin ('function', $functionName, 'Bitweaver\\Plugins\\smarty_function_' . $functionName ); + if ( is_callable( $callable )) { + $gBitSmarty->registerPlugin('function', $functionName, $callable); } } } @@ -70,6 +74,9 @@ class BitweaverExtension extends Base { $functionName = str_replace('modifier.', '', $basename); $functionName = str_replace('.php', '', $functionName); $callable = 'Bitweaver\\Plugins\\smarty_modifier_' . $functionName; + if (!is_callable($callable)) { + $callable = 'smarty_modifier_' . $functionName; + } $this->callbacks[$functionName]['name'] = $callable; $this->callbacks[$functionName]['loaded'] = true; if ( is_callable( $callable )) { @@ -78,6 +85,21 @@ class BitweaverExtension extends Base { } } + public function __call(string $name, array $arguments) { + if (str_starts_with($name, 'smarty_modifier_')) { + $modifierName = substr($name, strlen('smarty_modifier_')); + if (isset($this->callbacks[$modifierName])) { + return ($this->callbacks[$modifierName]['name'])(...$arguments); + } + } elseif (str_starts_with($name, 'smarty_function_')) { + $functionName = substr($name, strlen('smarty_function_')); + if (isset($this->callbacks[$functionName])) { + return ($this->callbacks[$functionName]['name'])(...$arguments); + } + } + throw new \BadMethodCallException("Method {$name} does not exist on " . static::class); + } + public function getModifierCompiler(string $modifier): ?\Smarty\Compile\Modifier\ModifierCompilerInterface { if (isset($this->modifiers[$modifier])) { diff --git a/smartyplugins/modifier.telephone_e164.php b/smartyplugins/modifier.telephone_e164.php index c82b292..432fafb 100644 --- a/smartyplugins/modifier.telephone_e164.php +++ b/smartyplugins/modifier.telephone_e164.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty |
