diff --git a/dist/prober.php b/dist/prober.php index bde3a025..914fa4a5 100644 --- a/dist/prober.php +++ b/dist/prober.php @@ -310,8 +310,8 @@ function fillNetworkStats(data) { HTML; } } -namespace InnStudio\Prober\Events; class EventsApi { private static $PRIORITY_ID = 'priority'; private static $CALLBACK_ID = 'callback'; private static $events = array(); public static function on($name, $callback, $priority = 10) { if ( ! isset(self::$events[$name])) { self::$events[$name] = array(); } self::$events[$name][] = array( self::$PRIORITY_ID => $priority, self::$CALLBACK_ID => $callback, ); } public static function emit($name, $returns = null) { $events = isset(self::$events[$name]) ? self::$events[$name] : false; if ( ! $events) { return $returns; } $sortArr = \array_map(function ($filter) { return $filter[self::$PRIORITY_ID]; }, $events); \array_multisort( $sortArr, \SORT_ASC, \SORT_NUMERIC, $events ); foreach ($events as $filter) { $args = \func_get_args(); unset($args[0]); $returns = \call_user_func_array($filter[self::$CALLBACK_ID], $args); } return $returns; } } -namespace InnStudio\Prober\MyInfo; use InnStudio\Prober\Events\EventsApi; use InnStudio\Prober\Helper\HelperApi; use InnStudio\Prober\I18n\I18nApi; class MyInfo { private $ID = 'myInfo'; public function __construct() { EventsApi::on('mods', array($this, 'filter'), 900); } public function filter($mods) { $mods[$this->ID] = array( 'title' => I18nApi::_('My information'), 'tinyTitle' => I18nApi::_('Mine'), 'display' => array($this, 'display'), ); return $mods; } public function display() { return \implode('', \array_map(function (array $item) { return << $priority, self::$CALLBACK_ID => $callback, ); } public static function emit() { $args = \func_get_args(); $name = $args[0]; $return = isset($args[1]) ? $args[1] : null; unset($args[0],$args[1]); $events = isset(self::$events[$name]) ? self::$events[$name] : false; if ( ! $events) { return $return; } $sortArr = array(); foreach ($events as $k => $filter) { $sortArr[$k] = $filter[self::$PRIORITY_ID]; } \array_multisort($sortArr, $events); foreach ($events as $filter) { $return = \call_user_func_array($filter[self::$CALLBACK_ID], array($return, $args)); } return $return; } } +namespace InnStudio\Prober\MyInfo; use InnStudio\Prober\Events\EventsApi; use InnStudio\Prober\Helper\HelperApi; use InnStudio\Prober\I18n\I18nApi; class MyInfo { private $ID = 'myInfo'; public function __construct() { EventsApi::on('mods', array($this, 'filter'), 900); } public function filter(array $mods) { $mods[$this->ID] = array( 'title' => I18nApi::_('My information'), 'tinyTitle' => I18nApi::_('Mine'), 'display' => array($this, 'display'), ); return $mods; } public function display() { return \implode('', \array_map(function (array $item) { return <<