新增:事件监听器,监听支持站点列表获取成功之后

This commit is contained in:
david 2022-10-04 20:30:49 +08:00
parent c95a39d317
commit 72b355b37f
5 changed files with 67 additions and 5 deletions

View File

@ -16,7 +16,9 @@ use IYUU\Client\transmission\transmission;
use IYUU\Library\IFile;
use IYUU\Library\Table;
use IYUU\Reseed\Events\ClientLinkSuccessEvent;
use IYUU\Reseed\Events\SupportSitesSuccessEvent;
use IYUU\Reseed\Listener\ClientLinkSuccessListener;
use IYUU\Reseed\Listener\SupportSitesSuccessListener;
/**
* IYUUAutoReseed辅种类
@ -109,7 +111,7 @@ class AutoReseed
*/
protected static $temp = [];
/**
* 站点
* 站点(云端下发的站点列表)
* @var array
*/
private static $sites = [];
@ -137,6 +139,7 @@ class AutoReseed
//初始化事件调度器
$listener = [
new ClientLinkSuccessListener,
new SupportSitesSuccessListener,
];
static::$EventDispatcher = new EventDispatcher($listener);
@ -272,6 +275,11 @@ class AutoReseed
die('网络故障或远端服务器无响应,请稍后再试!!!' . PHP_EOL . '如果多次出现此提示,请修改您设置的执行周期(请勿整点、半点执行),错峰辅种。');
}
self::$sites = array_column($sites, null, 'id');
//触发事件
$event = new SupportSitesSuccessEvent(self::$sites);
self::$EventDispatcher->dispatch($event);
// 初始化辅种检查规则 2020年12月12日新增
array_walk(self::$sites, function (&$v, $k) {
if (empty($v['reseed_check'])) {
@ -580,7 +588,7 @@ class AutoReseed
break;
}
// 提取种子地址
$regex = "/download.php\?hash\=(.*?)[\"|\']/i"; // 提取种子hash的正则表达式
$regex = "/download.php\?hash=(.*?)[\"|']/i"; // 提取种子hash的正则表达式
if (preg_match($regex, $details_html, $matchs)) {
// 拼接种子地址
$_url = str_replace($remove, $matchs[1], $_url);
@ -622,7 +630,7 @@ class AutoReseed
break;
}
// 提取cuhash
$regex = "/cuhash\=(.*?)[\"|\']/i"; // 提取种子cuhash的正则表达式
$regex = "/cuhash=(.*?)[\"|']/i"; // 提取种子cuhash的正则表达式
if (preg_match($regex, $html, $matchs)) {
self::$_sites[$siteName]['cuhash'] = $matchs[1];
} else {

View File

@ -44,4 +44,4 @@ class ClientLinkSuccessEvent
{
return $this->links;
}
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace IYUU\Reseed\Events;
/**
* 事件:支持站点列表获取成功之后
*/
class SupportSitesSuccessEvent
{
/**
* @var array
*/
private $sites;
/**
* @param array $sites
*/
public function __construct(array $sites)
{
$this->sites = $sites;
}
/**
* @return array
*/
public function getSites(): array
{
return $this->sites;
}
}

View File

@ -19,6 +19,6 @@ class ClientLinkSuccessListener implements EventListenerInterface
public function process(object $event): void
{
// TODO: Implement process() method.
echo '事件监听器执行:' . __METHOD__;
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace IYUU\Reseed\Listener;
use app\common\event\EventListenerInterface;
use IYUU\Reseed\Events\SupportSitesSuccessEvent;
/**
* 事件监听器:监听支持站点列表获取成功之后
*/
class SupportSitesSuccessListener implements EventListenerInterface
{
public function events(): array
{
return [
SupportSitesSuccessEvent::class,
];
}
public function process(object $event): void
{
echo '事件监听器执行:' . __METHOD__;
}
}