<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Core\Hook; use ModStart\Core\Exception\BizException; class ModStartHook { private static $listeners = array(); public static function subscribe($L4owo, $KYuru) { if (!is_array($L4owo)) { $L4owo = array($L4owo); } foreach ($L4owo as $ZpLX1) { if (!isset(self::$listeners[$ZpLX1])) { self::$listeners[$ZpLX1] = array(); } self::$listeners[$ZpLX1][] = $KYuru; } } public static function get($L4owo = '') { if (empty($L4owo)) { return self::$listeners; } return array_key_exists($L4owo, self::$listeners) ? self::$listeners[$L4owo] : array(); } public static function fire($L4owo, &$oK4I3 = null, $uzYuq = null) { goto HR_CT; SOg6g: foreach (static::get($L4owo) as $dwwIV => $KYuru) { $Of2_w[$dwwIV] = self::call($KYuru, $L4owo, $oK4I3, $uzYuq); } goto sHxUN; sHxUN: return $Of2_w; goto o2noS; HR_CT: $Of2_w = array(); goto SOg6g; o2noS: } public static function fireInView($L4owo, &$oK4I3 = null, $uzYuq = null) { return join('', self::fire($L4owo, $oK4I3, $uzYuq)); } private static function call($KYuru, $L4owo = '', &$oK4I3 = null, $uzYuq = null) { if ($KYuru instanceof \Closure) { $h2tHc = call_user_func_array($KYuru, array(&$oK4I3, $uzYuq)); } elseif (is_array($KYuru)) { list($KYuru, $HkVnj) = $KYuru; $h2tHc = call_user_func_array(array(&$KYuru, $HkVnj), array(&$oK4I3, $uzYuq)); } else { if (is_object($KYuru)) { $HkVnj = "on{$L4owo}"; $h2tHc = call_user_func_array(array(&$KYuru, $HkVnj), array(&$oK4I3, $uzYuq)); } elseif (strpos($KYuru, '::')) { $h2tHc = call_user_func_array($KYuru, array(&$oK4I3, $uzYuq)); } else { BizException::throws('ModStartHook call error'); } } return $h2tHc; } }