Server IP : 66.29.132.124 / Your IP : 3.133.149.244 Web Server : LiteSpeed System : Linux business141.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : wavevlvu ( 1524) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/wavevlvu/book24.ng/modules/Core/Helpers/ |
Upload File : |
<?php namespace Modules\Core\Helpers; class HookManager { protected static $inst; /** * Holds all registered actions. * * @var ActionManager */ protected $action; /** * Holds all registered filters. * * @var FilterManager */ protected $filter; /** * Construct the class. */ public function __construct() { $this->action = new ActionManager(); $this->filter = new FilterManager(); } /** * Get the action instance. * * @return ActionManager */ public function getAction() { return $this->action; } /** * Get the action instance. * * @return FilterManager */ public function getFilter() { return $this->filter; } /** * Add an action. * * @param string $hook Hook name * @param mixed $callback Function to execute * @param int $priority Priority of the action * @param int $arguments Number of arguments to accept */ public function addAction($hook, $callback, $priority = 20, $arguments = 1) { $this->action->listen($hook, $callback, $priority, $arguments); } /** * Remove an action. * * @param string $hook Hook name * @param mixed $callback Function to execute * @param int $priority Priority of the action */ public function removeAction($hook, $callback, $priority = 20) { $this->action->remove($hook, $callback, $priority); } /** * Remove all actions. * * @param string $hook Hook name */ public function removeAllActions($hook = null) { $this->action->removeAll($hook); } /** * Adds a filter. * * @param string $hook Hook name * @param mixed $callback Function to execute * @param int $priority Priority of the action * @param int $arguments Number of arguments to accept */ public function addFilter($hook, $callback, $priority = 20, $arguments = 1) { $this->filter->listen($hook, $callback, $priority, $arguments); } /** * Remove a filter. * * @param string $hook Hook name * @param mixed $callback Function to execute * @param int $priority Priority of the action */ public function removeFilter($hook, $callback, $priority = 20) { $this->filter->remove($hook, $callback, $priority); } /** * Remove all filters. * * @param string $hook Hook name */ public function removeAllFilters($hook = null) { $this->filter->removeAll($hook); } /** * Set a new action. * * Actions never return anything. It is merely a way of executing code at a specific time in your code. * * You can add as many parameters as you'd like. * * @param string $action Name of hook * @param mixed $parameter1 A parameter * @param mixed $parameter2 Another parameter * * @return void */ public function action() { $args = func_get_args(); $hook = $args[0]; unset($args[0]); $args = array_values($args); $this->action->fire($hook, $args); } /** * Set a new filter. * * Filters should always return something. The first parameter will always be the default value. * * You can add as many parameters as you'd like. * * @param string $action Name of hook * @param mixed $value The original filter value * @param mixed $parameter1 A parameter * @param mixed $parameter2 Another parameter * * @return void */ public function filter() { $args = func_get_args(); $hook = $args[0]; unset($args[0]); $args = array_values($args); return $this->filter->fire($hook, $args); } public static function inst(){ if(!self::$inst) self::$inst = new self(); return self::$inst; } }