KT-personal-website/app/Fetching/ApiFeed.php

27 lines
630 B
PHP
Raw Normal View History

2024-10-22 12:26:08 +02:00
<?php
namespace App\Fetching;
use App\Utils\Debug;
class ApiFeed {
public $json;
/**
* Loads JSON data from a URL and decodes it.
*
* @param string $url The URL to load JSON data from.
* @return object The object instance.
*/
public function load(string $url): object {
try {
$client = new \GuzzleHttp\Client();
$response = $client->request('GET', $url);
$this->json = json_decode($response->getBody(), true);
return $this;
} catch (\Exception $e) {
echo 'Catch in : ', $e->getMessage(), "\n";
}
}
}