<?phpnamespace extend;
use lib\Hook\Hook;
class HookQueue
{
public static $HookFile = SYSTEM_ROOT . 'lib/Hook/Queue/';
public static $HookList = [
'GoodsShow', 'GoodsHide', 'GoodsConceal', 'GoodsDel',
'GoodsSet', 'GoodsDetails', 'GoodsAdd', 'GoodsPrecisionSet',
'GoodsNumberCopyModify', 'GoodsCopy', 'GoodsModifyRemark',
'GoodsBatchFreightTemEdit', 'GoodsSetInventory', 'GoodsSort',
'GoodsPriceFluctuate', 'GreatFareIncreaseRule', 'AmendRuleFareIncrease',
'ClassAdd', 'ClassDel', 'ClassPaySet', 'ClassStateSet', 'ClassSort',
'ClassShow', 'ClassHide', 'WithdrawNew', 'WithdrawDel', 'WithdrawAudit',
'KarmaRecharge', 'BalanceRecharge', 'PaySuccess', 'BalanceOver',
'WorkOrderNew', 'WorkOrderReply', 'WorkOrderEnd', 'UserModifyInform',
'UserLogout', 'UserLogin', 'UserRegister', 'UserInvite', 'UserLevelUp',
'UserSignIn', 'PayMoney', 'PayPoints', 'ConfirmReceipt', 'OrderAdd',
'OrderFinish', 'CartDel', 'CartAdd', 'AppraiseAudit', 'AppraiseNew',
'FakaLater', 'SalfordDelivery', 'HiddenContentShipment', 'DeliveryPagodaMainframe',
'HostLogin', 'HostExitLogin', 'HostRenew', 'DeleteHostSpace', 'ActiveHostSpace',
'ArticleSeek', 'ArticleList', 'RenewUserRight', 'EndUninstallPlugin', 'StartUninstallPlugin',
'PluginInstalSuccess', 'OrderDockingFailure'
];
public static function execute($Name, $Data = [])
{
global $conf;
if (!strstr($Name, empty($conf['SynchroHookList']) ? '1' : $conf['SynchroHookList']) && !in_array($Name, self::$HookList)) {
return false;
}
$Data['TimeDelay'] = time();
mkdirs(self::$HookFile);
$FileName = RandomNumber();
if (file_put_contents(self::$HookFile . $FileName, json_encode([
'Name' => $Name,
'Data' => $Data
]))) {
return true;
}
return false;
}
public static function PerformTask()
{
mkdirs(self::$HookFile);
$List = for_dir(self::$HookFile);
if (count($List) === 0) {
return false;
}
require_once __DIR__ . '/../lib/Hook/Hook.php';
foreach ($List as $FileName) {
$PathFile = self::$HookFile . $FileName;
if (!is_file($PathFile)) {
continue;
}
$Json = file_get_contents($PathFile);
@unlink($PathFile);
if (!$Json) {
continue;
}
if (!$Json = json_decode($Json, true)) {
continue;
}
Hook::execute($Json['Name'], $Json['Data'], 1, 2);
unset($Json);
}
return true;
}
}