<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Core\Hook; use ModStart\Core\Exception\BizException; class ModStartHook { private static $listeners = array(); public static function subscribe($glP3G, $wePiP) { if (!is_array($glP3G)) { $glP3G = array($glP3G); } foreach ($glP3G as $P1uVJ) { if (!isset(self::$listeners[$P1uVJ])) { self::$listeners[$P1uVJ] = array(); } self::$listeners[$P1uVJ][] = $wePiP; } } public static function get($glP3G = '') { if (empty($glP3G)) { return self::$listeners; } return array_key_exists($glP3G, self::$listeners) ? self::$listeners[$glP3G] : array(); } public static function fire($glP3G, &$mattM = null, $DNodY = null) { goto ppTI2; wpeag: foreach (static::get($glP3G) as $oMJcb => $wePiP) { $VPJ9O[$oMJcb] = self::call($wePiP, $glP3G, $mattM, $DNodY); } goto VTFK0; VTFK0: return $VPJ9O; goto jotIJ; ppTI2: $VPJ9O = array(); goto wpeag; jotIJ: } public static function fireInView($glP3G, &$mattM = null, $DNodY = null) { return join('', self::fire($glP3G, $mattM, $DNodY)); } private static function call($wePiP, $glP3G = '', &$mattM = null, $DNodY = null) { if ($wePiP instanceof \Closure) { $j9Bnb = call_user_func_array($wePiP, array(&$mattM, $DNodY)); } elseif (is_array($wePiP)) { list($wePiP, $UVOMF) = $wePiP; $j9Bnb = call_user_func_array(array(&$wePiP, $UVOMF), array(&$mattM, $DNodY)); } else { if (is_object($wePiP)) { $UVOMF = "on{$glP3G}"; $j9Bnb = call_user_func_array(array(&$wePiP, $UVOMF), array(&$mattM, $DNodY)); } elseif (strpos($wePiP, '::')) { $j9Bnb = call_user_func_array($wePiP, array(&$mattM, $DNodY)); } else { BizException::throws('ModStartHook call error'); } } return $j9Bnb; } }