You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.5 KiB
44 lines
1.5 KiB
<?php
|
|
|
|
namespace App\Services\Crawl;
|
|
|
|
use App\Models\CrawlSource;
|
|
use App\Services\Crawl\Adapters\ArxivApiAdapter;
|
|
use App\Services\Crawl\Adapters\FacultyListHtmlAdapter;
|
|
use App\Services\Crawl\Adapters\GenericNewsHtmlAdapter;
|
|
use App\Services\Crawl\Adapters\GenericPaperHtmlAdapter;
|
|
use App\Services\Crawl\Adapters\PedailyHtmlAdapter;
|
|
use App\Services\Crawl\Contracts\CrawlerAdapterInterface;
|
|
|
|
class CrawlJobDispatcher
|
|
{
|
|
public function __construct(
|
|
protected ArxivApiAdapter $arxiv,
|
|
protected PedailyHtmlAdapter $pedaily,
|
|
protected GenericNewsHtmlAdapter $genericNews,
|
|
protected GenericPaperHtmlAdapter $genericPaper,
|
|
protected FacultyListHtmlAdapter $facultyList,
|
|
) {}
|
|
|
|
/**
|
|
* @param array<string, mixed> $params
|
|
* @return list<CrawlItemDto>
|
|
*/
|
|
public function fetch(string $requestUrl, CrawlSource $source, array $params): array
|
|
{
|
|
return $this->adapter($source->adapter_code)->fetch($requestUrl, $source, $params);
|
|
}
|
|
|
|
protected function adapter(string $code): CrawlerAdapterInterface
|
|
{
|
|
return match ($code) {
|
|
'arxiv_api' => $this->arxiv,
|
|
'pedaily_html' => $this->pedaily,
|
|
'generic_news_html' => $this->genericNews,
|
|
'generic_paper_html' => $this->genericPaper,
|
|
'faculty_list_html' => $this->facultyList,
|
|
default => throw new \InvalidArgumentException("未支持的适配器:{$code}"),
|
|
};
|
|
}
|
|
}
|