2017-06-17 02:19:42 +02:00
|
|
|
<?php
|
2020-10-15 00:19:31 +02:00
|
|
|
|
2021-07-19 07:53:45 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2021-08-11 17:31:02 +02:00
|
|
|
namespace App\Entity\Api\NowPlaying;
|
2017-06-17 02:19:42 +02:00
|
|
|
|
2021-08-11 17:31:02 +02:00
|
|
|
use App\Entity\Api\ResolvableUrlInterface;
|
2021-12-29 01:53:56 +01:00
|
|
|
use OpenApi\Attributes as OA;
|
2019-07-25 18:21:04 +02:00
|
|
|
use Psr\Http\Message\UriInterface;
|
2017-06-17 02:19:42 +02:00
|
|
|
|
2021-12-29 01:53:56 +01:00
|
|
|
#[OA\Schema(schema: 'Api_NowPlaying', type: 'object')]
|
2019-03-21 12:02:34 +01:00
|
|
|
class NowPlaying implements ResolvableUrlInterface
|
2017-06-17 02:19:42 +02:00
|
|
|
{
|
2021-12-29 01:53:56 +01:00
|
|
|
#[OA\Property]
|
2020-03-30 23:27:35 +02:00
|
|
|
public Station $station;
|
2017-06-17 02:19:42 +02:00
|
|
|
|
2021-12-29 01:53:56 +01:00
|
|
|
#[OA\Property]
|
2021-08-11 17:31:02 +02:00
|
|
|
public Listeners $listeners;
|
2017-06-18 04:11:01 +02:00
|
|
|
|
2021-12-29 01:53:56 +01:00
|
|
|
#[OA\Property]
|
2021-08-11 17:31:02 +02:00
|
|
|
public Live $live;
|
2018-02-03 22:54:12 +01:00
|
|
|
|
2021-12-29 01:53:56 +01:00
|
|
|
#[OA\Property]
|
2021-08-11 17:31:02 +02:00
|
|
|
public ?CurrentSong $now_playing = null;
|
2017-06-17 02:19:42 +02:00
|
|
|
|
2021-12-29 01:53:56 +01:00
|
|
|
#[OA\Property]
|
2020-08-16 16:54:01 +02:00
|
|
|
public ?StationQueue $playing_next = null;
|
2017-06-17 02:19:42 +02:00
|
|
|
|
2021-12-29 01:53:56 +01:00
|
|
|
/** @var SongHistory[] */
|
|
|
|
#[OA\Property]
|
2020-07-08 09:03:50 +02:00
|
|
|
public array $song_history = [];
|
2017-06-17 02:19:42 +02:00
|
|
|
|
2021-12-29 01:53:56 +01:00
|
|
|
#[OA\Property(
|
|
|
|
description: 'Whether the stream is currently online.',
|
|
|
|
example: true
|
|
|
|
)]
|
2021-03-01 00:28:17 +01:00
|
|
|
public bool $is_online = false;
|
|
|
|
|
2021-12-29 01:53:56 +01:00
|
|
|
#[OA\Property(
|
|
|
|
description: 'Debugging information about where the now playing data comes from.',
|
|
|
|
enum: ['hit', 'database', 'station']
|
|
|
|
)]
|
2020-03-30 23:27:35 +02:00
|
|
|
public ?string $cache = null;
|
2017-09-07 05:53:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update any variable items in the feed.
|
|
|
|
*/
|
2019-07-26 06:54:25 +02:00
|
|
|
public function update(): void
|
2017-09-07 05:53:25 +02:00
|
|
|
{
|
2021-07-19 07:53:45 +02:00
|
|
|
$this->now_playing?->recalculate();
|
2017-09-07 05:53:25 +02:00
|
|
|
}
|
2018-02-12 13:46:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an array representation of this object.
|
|
|
|
*
|
2020-10-15 00:19:31 +02:00
|
|
|
* @return mixed[]
|
2018-02-12 13:46:03 +01:00
|
|
|
*/
|
|
|
|
public function toArray(): array
|
|
|
|
{
|
2020-07-08 09:03:50 +02:00
|
|
|
return json_decode(json_encode($this, JSON_THROW_ON_ERROR), true, 512, JSON_THROW_ON_ERROR);
|
2018-02-12 13:46:03 +01:00
|
|
|
}
|
2018-10-05 01:12:12 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Iterate through sub-items and re-resolve any Uri instances to reflect base URL changes.
|
|
|
|
*
|
2019-07-25 18:21:04 +02:00
|
|
|
* @param UriInterface $base
|
2018-10-05 01:12:12 +02:00
|
|
|
*/
|
2019-07-25 18:21:04 +02:00
|
|
|
public function resolveUrls(UriInterface $base): void
|
2018-10-05 01:12:12 +02:00
|
|
|
{
|
2022-05-08 20:05:02 +02:00
|
|
|
$this->station->resolveUrls($base);
|
2018-10-06 06:13:30 +02:00
|
|
|
|
2019-03-21 11:54:37 +01:00
|
|
|
if ($this->now_playing instanceof ResolvableUrlInterface) {
|
2019-07-25 18:21:04 +02:00
|
|
|
$this->now_playing->resolveUrls($base);
|
2018-10-06 06:13:30 +02:00
|
|
|
}
|
2019-03-21 11:54:37 +01:00
|
|
|
|
|
|
|
if ($this->playing_next instanceof ResolvableUrlInterface) {
|
2019-07-25 18:21:04 +02:00
|
|
|
$this->playing_next->resolveUrls($base);
|
2018-10-06 06:13:30 +02:00
|
|
|
}
|
2018-10-05 01:12:12 +02:00
|
|
|
|
2019-09-04 20:00:51 +02:00
|
|
|
foreach ($this->song_history as $history_obj) {
|
2019-03-21 11:54:37 +01:00
|
|
|
if ($history_obj instanceof ResolvableUrlInterface) {
|
2019-07-25 18:21:04 +02:00
|
|
|
$history_obj->resolveUrls($base);
|
2019-03-21 11:54:37 +01:00
|
|
|
}
|
2018-10-05 01:12:12 +02:00
|
|
|
}
|
|
|
|
}
|
2018-08-05 00:05:14 +02:00
|
|
|
}
|