<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Core\Hook; use ModStart\Core\Exception\BizException; class ModStartHook { private static $listeners = array(); public static function subscribe($ZZMEd, $SfKKZ) { if (!is_array($ZZMEd)) { $ZZMEd = array($ZZMEd); } foreach ($ZZMEd as $Esk0p) { if (!isset(self::$listeners[$Esk0p])) { self::$listeners[$Esk0p] = array(); } self::$listeners[$Esk0p][] = $SfKKZ; } } public static function get($ZZMEd = '') { if (empty($ZZMEd)) { return self::$listeners; } return array_key_exists($ZZMEd, self::$listeners) ? self::$listeners[$ZZMEd] : array(); } public static function fire($ZZMEd, &$ACVUe = null, $sFmvK = null) { goto PCeAu; PCeAu: $K5pxT = array(); goto pjv6_; pjv6_: foreach (static::get($ZZMEd) as $l6tBV => $SfKKZ) { $K5pxT[$l6tBV] = self::call($SfKKZ, $ZZMEd, $ACVUe, $sFmvK); } goto PqJuX; PqJuX: return $K5pxT; goto Ht8Ak; Ht8Ak: } public static function fireInView($ZZMEd, &$ACVUe = null, $sFmvK = null) { return join('', self::fire($ZZMEd, $ACVUe, $sFmvK)); } private static function call($SfKKZ, $ZZMEd = '', &$ACVUe = null, $sFmvK = null) { if ($SfKKZ instanceof \Closure) { $WqCf1 = call_user_func_array($SfKKZ, array(&$ACVUe, $sFmvK)); } elseif (is_array($SfKKZ)) { list($SfKKZ, $pK00s) = $SfKKZ; $WqCf1 = call_user_func_array(array(&$SfKKZ, $pK00s), array(&$ACVUe, $sFmvK)); } else { if (is_object($SfKKZ)) { $pK00s = "on{$ZZMEd}"; $WqCf1 = call_user_func_array(array(&$SfKKZ, $pK00s), array(&$ACVUe, $sFmvK)); } elseif (strpos($SfKKZ, '::')) { $WqCf1 = call_user_func_array($SfKKZ, array(&$ACVUe, $sFmvK)); } else { BizException::throws('ModStartHook call error'); } } return $WqCf1; } }