Files
watchstate/src/Backends/Plex/Action/GetVersion.php
2023-12-17 00:08:47 +03:00

52 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Backends\Plex\Action;
use App\Backends\Common\CommonTrait;
use App\Backends\Common\Context;
use App\Backends\Common\Response;
use Psr\Log\LoggerInterface;
use Psr\SimpleCache\CacheInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
final class GetVersion
{
use CommonTrait;
private string $action = 'plex.getVersion';
public function __construct(
protected HttpClientInterface $http,
protected LoggerInterface $logger,
protected CacheInterface $cache
) {
}
/**
* Get Backend unique identifier.
*
* @param Context $context
* @param array $opts optional options.
*
* @return Response
*/
public function __invoke(Context $context, array $opts = []): Response
{
return $this->tryResponse(
context: $context,
fn: function () use ($context, $opts) {
$info = (new GetInfo($this->http, $this->logger, $this->cache))(context: $context, opts: $opts);
if (false === $info->status) {
return $info;
}
return new Response(status: true, response: ag($info->response, 'version'));
},
action: $this->action
);
}
}