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

2 weeks ago
<?php
namespace App\Services\Crawl;
use App\Models\CrawlSource;
use App\Services\Crawl\Adapters\ArxivApiAdapter;
use App\Services\Crawl\Adapters\FacultyListHtmlAdapter;
1 week ago
use App\Services\Crawl\Adapters\GenericNewsHtmlAdapter;
use App\Services\Crawl\Adapters\GenericPaperHtmlAdapter;
2 weeks ago
use App\Services\Crawl\Adapters\PedailyHtmlAdapter;
use App\Services\Crawl\Contracts\CrawlerAdapterInterface;
class CrawlJobDispatcher
{
public function __construct(
protected ArxivApiAdapter $arxiv,
protected PedailyHtmlAdapter $pedaily,
1 week ago
protected GenericNewsHtmlAdapter $genericNews,
protected GenericPaperHtmlAdapter $genericPaper,
2 weeks ago
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,
1 week ago
'generic_news_html' => $this->genericNews,
'generic_paper_html' => $this->genericPaper,
2 weeks ago
'faculty_list_html' => $this->facultyList,
default => throw new \InvalidArgumentException("未支持的适配器:{$code}"),
};
}
}