Files
Mangarr/src/Service/Scraper/ScraperFactory.php
ext.jeremy.guillot@maxicoffee.domains 5f15d14ae1 Convertion des images webp et png vers jpeg
2024-09-30 22:16:20 +02:00

26 lines
628 B
PHP

<?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());
}
}