<?php
 class vB_Utility_Hook_Live { use vB_Utility_Trait_NoSerialize; private $hook_classes = []; private $active_hooks = []; public function __construct($hook_classes) { $this->hook_classes = $this->sortHooks($hook_classes); } public function invoke($hook_name, $params) { if (isset($this->active_hooks[$hook_name])) { return; } $this->active_hooks[$hook_name] = true; foreach ($this->hook_classes AS $hook_class) { if (method_exists($hook_class, $hook_name)) { $hook_class::{$hook_name}($params); } } unset($this->active_hooks[$hook_name]); } private function sortHooks($hook_classes) { $hook_orders = []; foreach ($hook_classes AS $hook_class) { if (class_exists($hook_class)) { $order = isset($hook_class::$order) ? $hook_class::$order : 10; $hook_orders[$order][] = $hook_class; } } ksort($hook_orders); $new_hook_classes = []; foreach ($hook_orders AS $order) { foreach ($order AS $class) { $new_hook_classes[] = $class; } } return $new_hook_classes; } } 