Files
Mangarr/tests/Domain/Scraping/Adapter/InMemoryScraperFactory.php
ext.jeremy.guillot@maxicoffee.domains 3170a7c60e feat: analyse import + all tests fixed
2025-10-15 16:14:15 +02:00

61 lines
1.5 KiB
PHP

<?php
namespace App\Tests\Domain\Scraping\Adapter;
use App\Domain\Scraping\Domain\Contract\Service\ScraperFactoryInterface;
use App\Domain\Scraping\Domain\Contract\Service\ScraperInterface;
class InMemoryScraperFactory implements ScraperFactoryInterface
{
/** @var array<string, ScraperInterface> */
private array $scrapers = [];
public function createScraper(string $source): ScraperInterface
{
if (!isset($this->scrapers[$source])) {
$this->scrapers[$source] = new InMemoryScraperAdapter();
}
return $this->scrapers[$source];
}
public function getBestScraper(): ScraperInterface
{
return $this->createScraper('best');
}
public function getFallbackScraper(): ScraperInterface
{
return $this->createScraper('fallback');
}
public function getScraperWithFallback(string $preferredType): ScraperInterface
{
if (isset($this->scrapers[$preferredType])) {
return $this->scrapers[$preferredType];
}
return $this->getFallbackScraper();
}
public function getSupportedTypes(): array
{
return array_keys($this->scrapers);
}
public function isSupported(string $type): bool
{
return isset($this->scrapers[$type]);
}
public function addScraper(string $source, ScraperInterface $scraper): void
{
$this->scrapers[$source] = $scraper;
}
public function clear(): void
{
$this->scrapers = [];
}
}