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.

38 lines
1.1 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\PedailyHtmlAdapter;
use App\Services\Crawl\Contracts\CrawlerAdapterInterface;
class CrawlJobDispatcher
{
public function __construct(
protected ArxivApiAdapter $arxiv,
protected PedailyHtmlAdapter $pedaily,
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,
'faculty_list_html' => $this->facultyList,
default => throw new \InvalidArgumentException("未支持的适配器:{$code}"),
};
}
}