1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* (c) Christian Gripp <[email protected]> |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Core23\SetlistFm\Builder; |
11
|
|
|
|
12
|
|
|
use InvalidArgumentException; |
13
|
|
|
|
14
|
|
|
final class ArtistSearchBuilder |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var array |
18
|
|
|
*/ |
19
|
|
|
private $query; |
20
|
|
|
|
21
|
|
|
private function __construct() |
22
|
|
|
{ |
23
|
|
|
$this->query = []; |
24
|
|
|
|
25
|
|
|
$this->page(1); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @return ArtistSearchBuilder |
30
|
|
|
*/ |
31
|
|
|
public static function create(): self |
32
|
|
|
{ |
33
|
|
|
return new static(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @return ArtistSearchBuilder |
38
|
|
|
*/ |
39
|
|
|
public function page(int $page): self |
40
|
|
|
{ |
41
|
|
|
$this->query['p'] = $page; |
42
|
|
|
|
43
|
|
|
return $this; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return ArtistSearchBuilder |
48
|
|
|
*/ |
49
|
|
|
public function sort(string $mode): self |
50
|
|
|
{ |
51
|
|
|
if (!\in_array($mode, ['sortName', 'relevance'], true)) { |
52
|
|
|
throw new InvalidArgumentException(sprintf('Invalid sort mode given: %s', $mode)); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$this->query['sort'] = $mode; |
56
|
|
|
|
57
|
|
|
return $this; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return ArtistSearchBuilder |
62
|
|
|
*/ |
63
|
|
|
public function withName(string $name): self |
64
|
|
|
{ |
65
|
|
|
$this->query['artistName'] = $name; |
66
|
|
|
|
67
|
|
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return ArtistSearchBuilder |
72
|
|
|
*/ |
73
|
|
|
public function withMbid(string $mbid): self |
74
|
|
|
{ |
75
|
|
|
$this->query['artistMbid'] = $mbid; |
76
|
|
|
|
77
|
|
|
return $this; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return ArtistSearchBuilder |
82
|
|
|
*/ |
83
|
|
|
public function withTmbid(int $tmid): self |
84
|
|
|
{ |
85
|
|
|
$this->query['artistTmid'] = $tmid; |
86
|
|
|
|
87
|
|
|
return $this; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function getQuery(): array |
91
|
|
|
{ |
92
|
|
|
return $this->query; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|