Fixing variables being shared between plugins

If two plugins used the same hook, the variables they use aren't cleaned out in between running each of them. This is a super simple change creating a placeholder composite object that doesn't retain any changes between plugins.
This commit is contained in:
Alex Watson
2021-02-21 23:15:58 -05:00
committed by GitHub
parent 7e2598cedb
commit 6cadf82a63

View File

@@ -45,17 +45,18 @@ class HookHelper extends Base
$buffer = ''; $buffer = '';
foreach ($this->hook->getListeners($hook) as $params) { foreach ($this->hook->getListeners($hook) as $params) {
$currentVariables = $variables;
if (! empty($params['variables'])) { if (! empty($params['variables'])) {
$variables = array_merge($variables, $params['variables']); $currentVariables = array_merge($variables, $params['variables']);
} elseif (! empty($params['callable'])) { } elseif (! empty($params['callable'])) {
$result = call_user_func_array($params['callable'], $variables); $result = call_user_func_array($params['callable'], $variables);
if (is_array($result)) { if (is_array($result)) {
$variables = array_merge($variables, $result); $currentVariables = array_merge($variables, $result);
} }
} }
$buffer .= $this->template->render($params['template'], $variables); $buffer .= $this->template->render($params['template'], $currentVariables);
} }
return $buffer; return $buffer;