26 lines
715 B
PHP
26 lines
715 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Services\Parsers;
|
||
|
|
|
||
|
|
class BelgaHomepageParser
|
||
|
|
{
|
||
|
|
private const ARTICLE_URL_TEMPLATE = 'https://www.belganewsagency.eu/press-releases/%s/';
|
||
|
|
|
||
|
|
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();
|
||
|
|
}
|
||
|
|
}
|