fedi-feed-router/app/Services/Parsers/BelgaHomepageParser.php

29 lines
765 B
PHP
Raw Normal View History

<?php
namespace App\Services\Parsers;
class BelgaHomepageParser
{
private const ARTICLE_URL_TEMPLATE = 'https://www.belganewsagency.eu/press-releases/%s/';
/**
* @return array<int, string>
*/
public static function extractArticleUrls(string $json): array
{
$decoded = json_decode($json, true);
if (! is_array($decoded) || ! isset($decoded['data']) || ! is_array($decoded['data'])) {
return [];
}
return collect($decoded['data'])
->pluck('id')
->filter(fn($id) => is_int($id) || (is_string($id) && ctype_digit($id)))
->map(fn($id) => sprintf(self::ARTICLE_URL_TEMPLATE, $id))
->unique()
->values()
->toArray();
}
}