<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Module\Vendor\QuickRun\Crawl; abstract class AbstractCrawler { protected $queue = null; protected $handlers = array(); protected $delay = array('min' => 0, 'max' => 0); public function setDelay($HdNOT, $z9LBW = null) { goto L83hV; f9jK4: $this->delay['min'] = $HdNOT; goto yjP0x; L83hV: if (null === $z9LBW) { $z9LBW = $HdNOT; } goto f9jK4; yjP0x: $this->delay['max'] = $z9LBW; goto MbUOP; MbUOP: } public function init() { if (null == $this->queue) { $this->queue = new ArrayQueue(); } } public function register($cjIr1, $np3EX, $of6Ll = null) { $this->handlers[$cjIr1] = array($np3EX, $of6Ll); } public function dispatch($cjIr1, $quZRe = array(), $MkmbZ = null) { $this->queue->append($cjIr1, $quZRe, $MkmbZ); } public function onFinish() { } public function name() { return class_basename(static::class); } public function logInfo($ZjKo3, $MGhSY = null) { goto Ad2IU; T6J9b: $ao23C[] = '[' . $this->name() . ']'; goto HO9Tp; Ad2IU: $ao23C = array(); goto KZqRA; KZqRA: $ao23C[] = date('Y-m-d H:i:s'); goto T6J9b; EvEt8: echo join(' - ', $ao23C) . '
'; goto NnuIJ; HO9Tp: $ao23C[] = $ZjKo3; goto zAOeF; zAOeF: if (null != $MGhSY) { if (is_string($MGhSY)) { $ao23C[] = $MGhSY; } else { $ao23C[] = json_encode($MGhSY, JSON_UNESCAPED_UNICODE); } } goto EvEt8; NnuIJ: } public function logError($ZjKo3, $MGhSY = null) { goto lPSV5; zrQVE: echo join(' - ', $ao23C) . '
'; goto UCp2E; Njg4f: $ao23C[] = '[' . $this->name() . ']'; goto ucoLr; lPSV5: $ao23C = array(); goto Cjyp9; iFj0e: if (null != $MGhSY) { $ao23C[] = json_encode($MGhSY, JSON_UNESCAPED_UNICODE); } goto zrQVE; Cjyp9: $ao23C[] = date('Y-m-d H:i:s'); goto Njg4f; ucoLr: $ao23C[] = $ZjKo3; goto iFj0e; UCp2E: } public function run() { while (true) { $rrcVP = $this->queue->poll(); if (empty($rrcVP)) { goto LLfL6; LLfL6: $this->onFinish(); goto slPeN; AxD8F: break; goto O2eCs; slPeN: $this->logInfo('End'); goto AxD8F; O2eCs: } if (!isset($this->handlers[$rrcVP['handler']])) { $this->logError("Handler {$rrcVP['handler']} not registered", $rrcVP['param']); continue; } $np3EX = $this->handlers[$rrcVP['handler']][0]; $of6Ll = $this->handlers[$rrcVP['handler']][1]; $MkmbZ = $rrcVP['id']; if ($MkmbZ === null) { if (is_string($rrcVP['param']) || is_numeric($rrcVP['param'])) { $MkmbZ = $rrcVP['param']; } else { if (is_array($rrcVP['param'])) { goto v6Xst; MsbDE: $MkmbZ = join(',', $oZBhJ); goto dKuWc; qxU1s: foreach ($rrcVP['param'] as $ynzcc => $nfRLq) { if (is_string($nfRLq) || is_numeric($nfRLq)) { } else { $nfRLq = json_encode($nfRLq, JSON_UNESCAPED_UNICODE); } $oZBhJ[] = "{$ynzcc}:{$nfRLq}"; } goto MsbDE; v6Xst: $oZBhJ = array(); goto qxU1s; dKuWc: } else { $MkmbZ = json_encode($rrcVP['param'], JSON_UNESCAPED_UNICODE); } } } try { call_user_func_array($np3EX, array($this, $rrcVP['param'], $rrcVP['id'])); $this->logInfo("Execute {$rrcVP['handler']} {$MkmbZ}"); } catch (\Exception $se7TW) { goto s07LS; s07LS: var_dump($rrcVP); goto LKBtM; tfCkz: if (null !== $of6Ll) { try { $of6Ll($this, $rrcVP['param'], $rrcVP['id']); } catch (\Exception $se7TW) { $this->logInfo("Execute Fail for Error Handler {$rrcVP['handler']} {$MkmbZ}", $se7TW->getMessage()); } } goto zJ3x4; LKBtM: $this->logInfo("Execute {$rrcVP['handler']} {$MkmbZ}", $se7TW->getMessage()); goto tfCkz; zJ3x4: } if ($this->delay['max'] > 0) { usleep(rand($this->delay['min'], $this->delay['max']) * 1000); } } } public abstract function setup(); }