2025-06-29 21:33:18 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Services\Factories;
|
|
|
|
|
|
|
|
|
|
use App\Contracts\HomepageParserInterface;
|
2025-07-05 18:26:04 +02:00
|
|
|
use App\Models\Feed;
|
2025-06-29 21:33:18 +02:00
|
|
|
|
|
|
|
|
class HomepageParserFactory
|
|
|
|
|
{
|
2025-07-05 18:26:04 +02:00
|
|
|
public static function getParserForFeed(Feed $feed): ?HomepageParserInterface
|
2025-06-29 21:33:18 +02:00
|
|
|
{
|
2026-03-08 14:18:28 +01:00
|
|
|
if (! $feed->provider) {
|
2025-07-05 18:26:04 +02:00
|
|
|
return null;
|
2025-06-29 21:33:18 +02:00
|
|
|
}
|
2025-08-10 21:47:10 +02:00
|
|
|
|
|
|
|
|
$providerConfig = config("feed.providers.{$feed->provider}");
|
2026-03-08 14:18:28 +01:00
|
|
|
if (! $providerConfig || ! isset($providerConfig['parsers']['homepage'])) {
|
2025-08-10 21:47:10 +02:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-08 14:18:28 +01:00
|
|
|
/** @var class-string<HomepageParserInterface> $parserClass */
|
2025-08-10 21:47:10 +02:00
|
|
|
$parserClass = $providerConfig['parsers']['homepage'];
|
2026-03-08 14:18:28 +01:00
|
|
|
if (! class_exists($parserClass)) {
|
2025-08-10 21:47:10 +02:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-08 14:18:28 +01:00
|
|
|
$language = $feed->language->short_code ?? 'en';
|
2026-03-07 18:02:27 +01:00
|
|
|
|
|
|
|
|
return new $parserClass($language);
|
2025-06-29 21:33:18 +02:00
|
|
|
}
|
2025-07-05 18:26:04 +02:00
|
|
|
}
|