1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* (c) Christian Gripp <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Core23\LastFm\Model; |
13
|
|
|
|
14
|
|
|
final class ArtistInfo |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
private $name; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string|null |
23
|
|
|
*/ |
24
|
|
|
private $mbid; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var Image[] |
28
|
|
|
*/ |
29
|
|
|
private $image; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string|null |
33
|
|
|
*/ |
34
|
|
|
private $url; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var int |
38
|
|
|
*/ |
39
|
|
|
private $playcount; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var string|null |
43
|
|
|
*/ |
44
|
|
|
private $bioSummary; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var string|null |
48
|
|
|
*/ |
49
|
|
|
private $bioContent; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var int |
53
|
|
|
*/ |
54
|
|
|
private $tagcount; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var Tag[] |
58
|
|
|
*/ |
59
|
|
|
private $tags; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param Image[] $image |
63
|
|
|
* @param Tag[] $tags |
64
|
|
|
*/ |
65
|
|
|
public function __construct( |
66
|
|
|
string $name, |
67
|
|
|
?string $mbid, |
68
|
|
|
array $image, |
69
|
|
|
?string $url, |
70
|
|
|
int $playcount, |
71
|
|
|
?string $bioSummary, |
72
|
|
|
?string $bioContent, |
73
|
|
|
int $tagcount, |
74
|
|
|
array $tags |
75
|
|
|
) { |
76
|
|
|
$this->name = $name; |
77
|
|
|
$this->mbid = $mbid; |
78
|
|
|
$this->image = $image; |
79
|
|
|
$this->url = $url; |
80
|
|
|
$this->playcount = $playcount; |
81
|
|
|
$this->bioSummary = $bioSummary; |
82
|
|
|
$this->bioContent = $bioContent; |
83
|
|
|
$this->tagcount = $tagcount; |
84
|
|
|
$this->tags = $tags; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function getName(): string |
88
|
|
|
{ |
89
|
|
|
return $this->name; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function getMbid(): ?string |
93
|
|
|
{ |
94
|
|
|
return $this->mbid; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return Image[] |
99
|
|
|
*/ |
100
|
|
|
public function getImage(): array |
101
|
|
|
{ |
102
|
|
|
return $this->image; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function getUrl(): ?string |
106
|
|
|
{ |
107
|
|
|
return $this->url; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function getPlaycount(): int |
111
|
|
|
{ |
112
|
|
|
return $this->playcount; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function getBioSummary(): ?string |
116
|
|
|
{ |
117
|
|
|
return $this->bioSummary; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function getBioContent(): ?string |
121
|
|
|
{ |
122
|
|
|
return $this->bioContent; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function getTagcount(): int |
126
|
|
|
{ |
127
|
|
|
return $this->tagcount; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @return Tag[] |
132
|
|
|
*/ |
133
|
|
|
public function getTags(): array |
134
|
|
|
{ |
135
|
|
|
return $this->tags; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @return ArtistInfo |
140
|
|
|
*/ |
141
|
|
|
public static function fromApi(array $data): self |
142
|
|
|
{ |
143
|
|
|
$images = self::createImagesFromApi($data); |
144
|
|
|
$tags = self::createTagsFromApi($data); |
145
|
|
|
|
146
|
|
|
return new self( |
147
|
|
|
$data['name'], |
148
|
|
|
$data['mbid'] ?? null, |
149
|
|
|
$images, |
150
|
|
|
$data['url'] ?? null, |
151
|
|
|
isset($data['playcount']) ? (int) $data['playcount'] : 0, |
152
|
|
|
$data['bio']['summary'] ?? null, |
153
|
|
|
$data['bio']['content'] ?? null, |
154
|
|
|
isset($data['tagcount']) ? (int) $data['tagcount'] : 0, |
155
|
|
|
$tags |
156
|
|
|
); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
private static function createImagesFromApi(array $data): array |
160
|
|
|
{ |
161
|
|
|
$images = []; |
162
|
|
|
|
163
|
|
|
if (\array_key_exists('image', $data)) { |
164
|
|
|
foreach ((array) $data['image'] as $image) { |
165
|
|
|
$images[] = new Image($image['#text']); |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
return $images; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
private static function createTagsFromApi(array $data): array |
173
|
|
|
{ |
174
|
|
|
$tags = []; |
175
|
|
|
|
176
|
|
|
if (\array_key_exists('tags', $data) && \array_key_exists('tag', $data['tags'])) { |
177
|
|
|
foreach ((array) $data['tags']['tag'] as $tag) { |
178
|
|
|
$tags[] = Tag::fromApi($tag); |
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
return $tags; |
183
|
|
|
} |
184
|
|
|
} |
185
|
|
|
|