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