|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Uxmp\Core\Api\Lib; |
|
6
|
|
|
|
|
7
|
|
|
use Uxmp\Core\Component\Config\ConfigProviderInterface; |
|
8
|
|
|
use Uxmp\Core\Orm\Model\AlbumInterface; |
|
9
|
|
|
use Uxmp\Core\Orm\Model\SongInterface; |
|
10
|
|
|
|
|
11
|
|
|
final class SongListItem implements SongListItemInterface |
|
12
|
|
|
{ |
|
13
|
2 |
|
public function __construct( |
|
14
|
|
|
private ConfigProviderInterface $config, |
|
15
|
|
|
private SongInterface $song, |
|
16
|
|
|
private AlbumInterface $album |
|
17
|
|
|
) { |
|
18
|
2 |
|
} |
|
19
|
|
|
|
|
20
|
1 |
|
public function jsonSerialize() |
|
21
|
|
|
{ |
|
22
|
1 |
|
$songId = $this->song->getId(); |
|
23
|
1 |
|
$baseUrl = $this->config->getBaseUrl(); |
|
24
|
|
|
|
|
25
|
1 |
|
$artist = $this->album->getArtist(); |
|
26
|
|
|
|
|
27
|
|
|
return [ |
|
28
|
1 |
|
'id' => $songId, |
|
29
|
1 |
|
'name' => $this->song->getTitle(), |
|
30
|
1 |
|
'artistName' => $artist->getTitle(), |
|
31
|
1 |
|
'albumName' => $this->album->getTitle(), |
|
32
|
1 |
|
'trackNumber' => $this->song->getTrackNumber(), |
|
33
|
1 |
|
'playUrl' => sprintf('%s/play/%d', $baseUrl, $songId), |
|
34
|
1 |
|
'cover' => sprintf('%s/art/album/%s', $baseUrl, $this->album->getMbid()), |
|
35
|
1 |
|
'artistId' => $artist->getId(), |
|
36
|
1 |
|
'albumId' => $this->album->getId(), |
|
37
|
1 |
|
'length' => $this->song->getLength(), |
|
38
|
|
|
]; |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|