1
|
|
|
<?php |
2
|
|
|
namespace Pbxg33k\MusicInfo\Service; |
3
|
|
|
|
4
|
|
|
use GuzzleHttp\ClientInterface; |
5
|
|
|
use Pbxg33k\MusicInfo\Exception\ServiceConfigurationException; |
6
|
|
|
use Pbxg33k\MusicInfo\Model\IMusicService; |
7
|
|
|
use Pbxg33k\MusicInfo\Model\IMusicServiceEndpoint; |
8
|
|
|
|
9
|
|
|
class BaseService implements IMusicService |
10
|
|
|
{ |
11
|
|
|
const ERR_METHOD_NOT_IMPLEMENTED = "Method not implemented"; |
12
|
|
|
/** |
13
|
|
|
* @var ClientInterface |
14
|
|
|
*/ |
15
|
|
|
protected $client; |
16
|
|
|
|
17
|
|
|
protected $apiClient; |
18
|
|
|
|
19
|
|
|
protected $config; |
20
|
|
|
|
21
|
|
|
protected $initialized = false; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @return ClientInterface |
25
|
|
|
*/ |
26
|
|
|
public function getClient() |
27
|
|
|
{ |
28
|
|
|
return $this->client; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param ClientInterface $client |
33
|
|
|
* |
34
|
|
|
* @return BaseService |
35
|
|
|
*/ |
36
|
19 |
|
public function setClient(ClientInterface $client) |
37
|
|
|
{ |
38
|
19 |
|
$this->client = $client; |
39
|
|
|
|
40
|
19 |
|
return $this; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return mixed |
45
|
|
|
*/ |
46
|
13 |
|
public function getApiClient() |
47
|
|
|
{ |
48
|
13 |
|
return $this->apiClient; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param mixed $apiClient |
53
|
|
|
* |
54
|
|
|
* @return BaseService |
55
|
|
|
*/ |
56
|
13 |
|
public function setApiClient($apiClient) |
57
|
|
|
{ |
58
|
13 |
|
$this->apiClient = $apiClient; |
59
|
|
|
|
60
|
13 |
|
return $this; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return mixed |
65
|
|
|
*/ |
66
|
13 |
|
public function getConfig() |
67
|
|
|
{ |
68
|
13 |
|
return $this->config; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param mixed $config |
73
|
|
|
* |
74
|
|
|
* @return BaseService |
75
|
|
|
*/ |
76
|
19 |
|
public function setConfig($config = null) |
77
|
|
|
{ |
78
|
19 |
|
$this->config = $config; |
79
|
|
|
|
80
|
19 |
|
return $this; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return boolean |
85
|
|
|
*/ |
86
|
10 |
|
public function isInitialized() |
87
|
|
|
{ |
88
|
10 |
|
return $this->initialized; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param boolean $initialized |
93
|
|
|
* |
94
|
|
|
* @return BaseService |
95
|
|
|
*/ |
96
|
13 |
|
public function setInitialized($initialized) |
97
|
|
|
{ |
98
|
13 |
|
$this->initialized = $initialized; |
99
|
|
|
|
100
|
13 |
|
return $this; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Service specific initializer |
106
|
|
|
* |
107
|
|
|
* Construct your API client in this method. |
108
|
|
|
* It is set to be the method that is called by Symfony's Service Loader |
109
|
|
|
* |
110
|
|
|
* @param array $config |
111
|
|
|
* |
112
|
|
|
* @return void |
113
|
|
|
* @throws ServiceConfigurationException |
114
|
|
|
*/ |
115
|
|
|
public function init($config = []) |
116
|
|
|
{ |
117
|
|
|
throw new ServiceConfigurationException(self::ERR_METHOD_NOT_IMPLEMENTED); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* |
122
|
|
|
* @throws ServiceConfigurationException |
123
|
|
|
* @return IMusicServiceEndpoint |
124
|
|
|
*/ |
125
|
|
|
public function artist() |
126
|
|
|
{ |
127
|
|
|
throw new ServiceConfigurationException(self::ERR_METHOD_NOT_IMPLEMENTED); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* |
132
|
|
|
* @throws ServiceConfigurationException |
133
|
|
|
* @return IMusicServiceEndpoint |
134
|
|
|
*/ |
135
|
|
|
public function album() |
136
|
|
|
{ |
137
|
|
|
throw new ServiceConfigurationException(self::ERR_METHOD_NOT_IMPLEMENTED); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* |
142
|
|
|
* @throws ServiceConfigurationException |
143
|
|
|
* @return IMusicServiceEndpoint |
144
|
|
|
*/ |
145
|
|
|
public function song() |
146
|
|
|
{ |
147
|
|
|
throw new ServiceConfigurationException(self::ERR_METHOD_NOT_IMPLEMENTED); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* |
152
|
|
|
* @throws ServiceConfigurationException |
153
|
|
|
* @return IMusicServiceEndpoint |
154
|
|
|
*/ |
155
|
|
|
public function track() |
156
|
|
|
{ |
157
|
|
|
throw new ServiceConfigurationException(self::ERR_METHOD_NOT_IMPLEMENTED); |
158
|
|
|
} |
159
|
|
|
} |