|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Uxmp\Core\Api\Lib; |
|
6
|
|
|
|
|
7
|
|
|
use JsonSerializable; |
|
8
|
|
|
use Uxmp\Core\Component\Config\ConfigProviderInterface; |
|
9
|
|
|
use Uxmp\Core\Orm\Model\AlbumInterface; |
|
10
|
|
|
use Uxmp\Core\Orm\Model\SongInterface; |
|
11
|
|
|
|
|
12
|
|
|
final class SongListItem implements JsonSerializable |
|
13
|
|
|
{ |
|
14
|
2 |
|
public function __construct( |
|
15
|
|
|
private readonly ConfigProviderInterface $config, |
|
16
|
|
|
private readonly SongInterface $song, |
|
17
|
|
|
private readonly AlbumInterface $album |
|
18
|
|
|
) { |
|
19
|
2 |
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @return array{ |
|
|
|
|
|
|
23
|
|
|
* id: int, |
|
24
|
|
|
* name: string, |
|
25
|
|
|
* artistName: null|string, |
|
26
|
|
|
* albumName: null|string, |
|
27
|
|
|
* trackNumber: int, |
|
28
|
|
|
* playUrl: string, |
|
29
|
|
|
* cover: string, |
|
30
|
|
|
* artistId: int, |
|
31
|
|
|
* albumId: int, |
|
32
|
|
|
* length: int, |
|
33
|
|
|
* year: int|null |
|
34
|
|
|
* } |
|
35
|
|
|
*/ |
|
36
|
1 |
|
public function jsonSerialize(): array |
|
37
|
|
|
{ |
|
38
|
1 |
|
$songId = $this->song->getId(); |
|
39
|
1 |
|
$albumId = $this->album->getId(); |
|
40
|
1 |
|
$baseUrl = $this->config->getBaseUrl(); |
|
41
|
|
|
|
|
42
|
1 |
|
$artist = $this->album->getArtist(); |
|
43
|
|
|
|
|
44
|
1 |
|
return [ |
|
45
|
1 |
|
'id' => $songId, |
|
46
|
1 |
|
'name' => $this->song->getTitle(), |
|
47
|
1 |
|
'artistName' => $artist->getTitle(), |
|
48
|
1 |
|
'albumName' => $this->album->getTitle(), |
|
49
|
1 |
|
'trackNumber' => $this->song->getTrackNumber(), |
|
50
|
1 |
|
'playUrl' => sprintf('%s/play/%d', $baseUrl, $songId), |
|
51
|
1 |
|
'cover' => sprintf('%s/art/album/%d', $baseUrl, $albumId), |
|
52
|
1 |
|
'artistId' => $artist->getId(), |
|
53
|
1 |
|
'albumId' => $albumId, |
|
54
|
1 |
|
'length' => $this->song->getLength(), |
|
55
|
1 |
|
'year' => $this->song->getYear(), |
|
56
|
1 |
|
]; |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|