Added:
- Refactor MangaScraperService (not used everywhere now) - Added JavascriptScraper.php - Added alternatives slugs in Manga.php - Improvement in manga edit form
This commit is contained in:
25
src/Service/Scraper/ScraperFactory.php
Normal file
25
src/Service/Scraper/ScraperFactory.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\Scraper;
|
||||
|
||||
use App\Entity\ContentSource;
|
||||
|
||||
class ScraperFactory
|
||||
{
|
||||
private array $scrapers;
|
||||
|
||||
public function __construct(iterable $scrapers)
|
||||
{
|
||||
$this->scrapers = iterator_to_array($scrapers);
|
||||
}
|
||||
|
||||
public function createScraper(ContentSource $contentSource): ScraperInterface
|
||||
{
|
||||
foreach ($this->scrapers as $scraper) {
|
||||
if ($scraper->supports($contentSource->getScrapingType())) {
|
||||
return $scraper;
|
||||
}
|
||||
}
|
||||
throw new \InvalidArgumentException('Unsupported scraping type: ' . $contentSource->getScrapingType());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user