summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorLester Caine <lester@lsces.co.uk>2026-05-16 20:25:00 +0100
committerLester Caine <lester@lsces.co.uk>2026-05-16 20:25:00 +0100
commitd729e91a69c82eeeadefe0f8d3a1139ec5492e63 (patch)
tree062d92ca4a7f8dc4be979500133ca47cd1df8152 /includes
parent201dda1ed262fd49d633574936b82029b0d070d0 (diff)
downloadthemes-d729e91a69c82eeeadefe0f8d3a1139ec5492e63.tar.gz
themes-d729e91a69c82eeeadefe0f8d3a1139ec5492e63.tar.bz2
themes-d729e91a69c82eeeadefe0f8d3a1139ec5492e63.zip
Extend BitweaverExtension to allow a different route to use smarty plugins direct from php
Diffstat (limited to 'includes')
-rwxr-xr-xincludes/classes/BitweaverExtension.php28
1 files changed, 25 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])) {