From 3b52cea8110541e1e5d8cb06198c11a2ed074b1c Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 8 Feb 2021 16:14:48 +0300 Subject: move some old-style handlers to new callback ones --- classes/pluginhost.php | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'classes/pluginhost.php') diff --git a/classes/pluginhost.php b/classes/pluginhost.php index 7e5f6029c..673053b9e 100755 --- a/classes/pluginhost.php +++ b/classes/pluginhost.php @@ -135,7 +135,7 @@ class PluginHost { $method = strtolower($hook); foreach ($this->get_hooks($hook) as $plugin) { - Debug::log("invoking: " . get_class($plugin) . "->$hook()", Debug::$LOG_VERBOSE); + //Debug::log("invoking: " . get_class($plugin) . "->$hook()", Debug::$LOG_VERBOSE); try { $plugin->$method(...$args); @@ -147,6 +147,26 @@ class PluginHost { } } + function run_hooks_until($hook, $check, ...$args) { + $method = strtolower($hook); + + foreach ($this->get_hooks($hook) as $plugin) { + try { + $result = $plugin->$method(...$args); + + if ($result == $check) + return true; + + } catch (Exception $ex) { + user_error($ex, E_USER_WARNING); + } catch (Error $err) { + user_error($err, E_USER_WARNING); + } + } + + return false; + } + function run_hooks_callback($hook, $callback, ...$args) { $method = strtolower($hook); @@ -154,7 +174,25 @@ class PluginHost { //Debug::log("invoking: " . get_class($plugin) . "->$hook()", Debug::$LOG_VERBOSE); try { - $callback($plugin->$method(...$args), $plugin); + if ($callback($plugin->$method(...$args), $plugin)) + break; + } catch (Exception $ex) { + user_error($ex, E_USER_WARNING); + } catch (Error $err) { + user_error($err, E_USER_WARNING); + } + } + } + + function chain_hooks_callback($hook, $callback, &...$args) { + $method = strtolower($hook); + + foreach ($this->get_hooks($hook) as $plugin) { + //Debug::log("invoking: " . get_class($plugin) . "->$hook()", Debug::$LOG_VERBOSE); + + try { + if ($callback($plugin->$method(...$args), $plugin)) + break; } catch (Exception $ex) { user_error($ex, E_USER_WARNING); } catch (Error $err) { -- cgit v1.2.3