| 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 |  |  | use Psr\Cache\CacheItemPoolInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | class BaseService implements IMusicService | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     const ERR_METHOD_NOT_IMPLEMENTED = "Method not implemented"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      * @var ClientInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     protected $client; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     protected $apiClient; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     protected $config; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     protected $initialized = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * @var CacheItemPoolInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     protected $cache; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * @return ClientInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 | 1 |  |     public function getClient() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 1 |  |         return $this->client; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      * @param ClientInterface $client | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * @return BaseService | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 39 |  |     public function setClient(ClientInterface $client) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 39 |  |         $this->client = $client; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 39 |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 | 39 |  |     public function getApiClient() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 39 |  |         return $this->apiClient; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      * @param mixed $apiClient | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      * @return BaseService | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 39 |  |     public function setApiClient($apiClient) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 | 39 |  |         $this->apiClient = $apiClient; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 | 39 |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 | 39 |  |     public function getConfig() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 | 39 |  |         return $this->config; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |      * @param mixed $config | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      * @return BaseService | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 | 39 |  |     public function setConfig($config = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 | 39 |  |         $this->config = $config; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 | 39 |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      * @return CacheItemPoolInterface | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 100 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 101 | 39 |  |     public function getCache() | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 103 | 39 |  |         return $this->cache; | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |      * @param CacheItemPoolInterface $cache | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |      * @return BaseService | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 | 39 |  |     public function setCache(CacheItemPoolInterface $cache) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 | 39 |  |         $this->cache = $cache; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 | 39 |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |      * @return boolean | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 | 22 |  |     public function isInitialized() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 | 22 |  |         return $this->initialized; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |      * @param boolean $initialized | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |      * @return BaseService | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 | 39 |  |     public function setInitialized($initialized) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 | 39 |  |         $this->initialized = $initialized; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 | 39 |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |      * Service specific initializer | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |      * Construct your API client in this method. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |      * It is set to be the method that is called by Symfony's Service Loader | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |      * @param array $config | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |      * @throws ServiceConfigurationException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 | 1 |  |     public function init($config = []) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 | 1 |  |         throw new ServiceConfigurationException(self::ERR_METHOD_NOT_IMPLEMENTED); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |      * @throws ServiceConfigurationException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |      * @return IMusicServiceEndpoint | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 | 1 |  |     public function artist() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 | 1 |  |         throw new ServiceConfigurationException(self::ERR_METHOD_NOT_IMPLEMENTED); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |      * @throws ServiceConfigurationException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |      * @return IMusicServiceEndpoint | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 | 1 |  |     public function album() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 | 1 |  |         throw new ServiceConfigurationException(self::ERR_METHOD_NOT_IMPLEMENTED); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |      * @throws ServiceConfigurationException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |      * @return IMusicServiceEndpoint | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 | 1 |  |     public function song() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 | 1 |  |         throw new ServiceConfigurationException(self::ERR_METHOD_NOT_IMPLEMENTED); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |      * @throws ServiceConfigurationException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |      * @return IMusicServiceEndpoint | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 | 1 |  |     public function track() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 | 1 |  |         throw new ServiceConfigurationException(self::ERR_METHOD_NOT_IMPLEMENTED); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 195 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 196 |  |  |  |