summaryrefslogtreecommitdiff
path: root/classes/pluginhost.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-02-08 16:14:48 +0300
committerAndrew Dolgov <[email protected]>2021-02-08 16:14:48 +0300
commit3b52cea8110541e1e5d8cb06198c11a2ed074b1c (patch)
tree763304f562f8787fa2e56291d032832981b5c436 /classes/pluginhost.php
parent1d5c8ee50082dd0221055969283b27f2b09b3bb4 (diff)
move some old-style handlers to new callback ones
Diffstat (limited to 'classes/pluginhost.php')
-rwxr-xr-xclasses/pluginhost.php42
1 files changed, 40 insertions, 2 deletions
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) {