koel/app/Services/ApplicationInformationService.php

35 lines
897 B
PHP
Raw Normal View History

<?php
namespace App\Services;
use GuzzleHttp\Client;
use Illuminate\Contracts\Cache\Repository as Cache;
use Illuminate\Log\Logger;
2020-12-22 21:11:22 +01:00
use Throwable;
class ApplicationInformationService
{
2018-08-30 12:42:47 +07:00
private const CACHE_KEY = 'latestKoelVersion';
2022-07-29 08:47:10 +02:00
public function __construct(private Client $client, private Cache $cache, private Logger $logger)
{
}
/**
* Get the latest version number of Koel from GitHub.
*/
2018-08-30 12:37:24 +07:00
public function getLatestVersionNumber(): string
{
2021-06-05 12:47:56 +02:00
return $this->cache->remember(self::CACHE_KEY, now()->addDay(), function (): string {
try {
2021-06-05 12:47:56 +02:00
return json_decode($this->client->get('https://api.github.com/repos/koel/koel/tags')->getBody())[0]
->name;
2020-12-22 21:11:22 +01:00
} catch (Throwable $e) {
$this->logger->error($e);
return koel_version();
}
});
}
}