diff options
Diffstat (limited to 'classes/pluginhost.php')
-rwxr-xr-x | classes/pluginhost.php | 75 |
1 files changed, 30 insertions, 45 deletions
diff --git a/classes/pluginhost.php b/classes/pluginhost.php index 952d4df77..4b85bc216 100755 --- a/classes/pluginhost.php +++ b/classes/pluginhost.php @@ -1,49 +1,42 @@ <?php class PluginHost { - // TODO: class properties can be switched to PHP typing if/when the minimum PHP_VERSION is raised to 7.4.0+ - /** @var PDO|null */ - private $pdo = null; + private ?PDO $pdo = null; /** * separate handle for plugin data so transaction while saving wouldn't clash with possible main * tt-rss code transactions; only initialized when first needed - * - * @var PDO|null */ - private $pdo_data = null; + private ?PDO $pdo_data = null; /** @var array<string, array<int, array<int, Plugin>>> hook types -> priority levels -> Plugins */ - private $hooks = []; + private array $hooks = []; /** @var array<string, Plugin> */ - private $plugins = []; + private array $plugins = []; /** @var array<string, array<string, Plugin>> handler type -> method type -> Plugin */ - private $handlers = []; + private array $handlers = []; /** @var array<string, array{'description': string, 'suffix': string, 'arghelp': string, 'class': Plugin}> command type -> details array */ - private $commands = []; + private array $commands = []; /** @var array<string, array<string, mixed>> plugin name -> (potential profile array) -> key -> value */ - private $storage = []; + private array $storage = []; /** @var array<int, array<int, array{'id': int, 'title': string, 'sender': Plugin, 'icon': string}>> */ - private $feeds = []; + private array $feeds = []; /** @var array<string, Plugin> API method name, Plugin sender */ - private $api_methods = []; + private array $api_methods = []; /** @var array<string, array<int, array{'action': string, 'description': string, 'sender': Plugin}>> */ - private $plugin_actions = []; + private array $plugin_actions = []; - /** @var int|null */ - private $owner_uid = null; + private ?int $owner_uid = null; - /** @var bool */ - private $data_loaded = false; + private bool $data_loaded = false; - /** @var PluginHost|null */ - private static $instance = null; + private static ?PluginHost $instance = null; const API_VERSION = 2; const PUBLIC_METHOD_DELIMITER = "--"; @@ -203,6 +196,9 @@ class PluginHost { /** @see Plugin::hook_post_logout() */ const HOOK_POST_LOGOUT = "hook_post_logout"; + /** @see Plugin::hook_loginform_additional_buttons() */ + const HOOK_LOGINFORM_ADDITIONAL_BUTTONS = "hook_loginform_additional_buttons"; + const KIND_ALL = 1; const KIND_SYSTEM = 2; const KIND_USER = 3; @@ -409,7 +405,7 @@ class PluginHost { $tmp = []; foreach (array_keys($this->hooks[$type]) as $prio) { - $tmp = array_merge($tmp, $this->hooks[$type][$prio]); + array_push($tmp, ...$this->hooks[$type][$prio]); } return $tmp; @@ -422,7 +418,7 @@ class PluginHost { */ function load_all(int $kind, int $owner_uid = null, bool $skip_init = false): void { - $plugins = array_merge(glob("plugins/*"), glob("plugins.local/*")); + $plugins = [...(glob("plugins/*") ?: []), ...(glob("plugins.local/*") ?: [])]; $plugins = array_filter($plugins, "is_dir"); $plugins = array_map("basename", $plugins); @@ -539,10 +535,7 @@ class PluginHost { $method = strtolower($method); if ($this->is_system($sender)) { - if (!isset($this->handlers[$handler])) { - $this->handlers[$handler] = []; - } - + $this->handlers[$handler] ??= []; $this->handlers[$handler][$method] = $sender; } } @@ -645,8 +638,7 @@ class PluginHost { owner_uid= ? AND name = ?"); $sth->execute([$this->owner_uid, $plugin]); - if (!isset($this->storage[$plugin])) - $this->storage[$plugin] = []; + $this->storage[$plugin] ??= []; $content = serialize($this->storage[$plugin]); @@ -677,14 +669,8 @@ class PluginHost { if ($profile_id) { $idx = get_class($sender); - if (!isset($this->storage[$idx])) { - $this->storage[$idx] = []; - } - - if (!isset($this->storage[$idx][$profile_id])) { - $this->storage[$idx][$profile_id] = []; - } - + $this->storage[$idx] ??= []; + $this->storage[$idx][$profile_id] ??= []; $this->storage[$idx][$profile_id][$name] = $value; $this->save_data(get_class($sender)); @@ -699,9 +685,7 @@ class PluginHost { function set(Plugin $sender, string $name, $value): void { $idx = get_class($sender); - if (!isset($this->storage[$idx])) - $this->storage[$idx] = []; - + $this->storage[$idx] ??= []; $this->storage[$idx][$name] = $value; $this->save_data(get_class($sender)); @@ -713,8 +697,7 @@ class PluginHost { function set_array(Plugin $sender, array $params): void { $idx = get_class($sender); - if (!isset($this->storage[$idx])) - $this->storage[$idx] = []; + $this->storage[$idx] ??= []; foreach ($params as $name => $value) $this->storage[$idx][$name] = $value; @@ -852,11 +835,13 @@ class PluginHost { function add_filter_action(Plugin $sender, string $action_name, string $action_desc): void { $sender_class = get_class($sender); - if (!isset($this->plugin_actions[$sender_class])) - $this->plugin_actions[$sender_class] = []; + $this->plugin_actions[$sender_class] ??= []; - array_push($this->plugin_actions[$sender_class], - array("action" => $action_name, "description" => $action_desc, "sender" => $sender)); + $this->plugin_actions[$sender_class][] = [ + "action" => $action_name, + "description" => $action_desc, + "sender" => $sender, + ]; } /** |