/** * @covers LoLApi\ApiClient::setCacheProvider * @covers LoLApi\ApiClient::getCacheProvider */ public function testCacheProvider() { $apiClient = new ApiClient(ApiClient::REGION_EUW, 'test'); $this->assertInstanceOf('Doctrine\\Common\\Cache\\VoidCache', $apiClient->getCacheProvider()); $apiClient->setCacheProvider(new ArrayCache()); $this->assertInstanceOf('Doctrine\\Common\\Cache\\ArrayCache', $apiClient->getCacheProvider()); }
/** * @param string $url * @param array $queryParameters * @param bool $global * @param bool $status * * @return BaseApi * @throws \LoLApi\Exception\AbstractRateLimitException */ protected function callApiUrl($url, array $queryParameters = [], $global = false, $status = false) { $baseUrl = $global ? $this->apiClient->getGlobalUrl() : ($status ? $this->apiClient->getStatusUrl() : ''); $url = $baseUrl . str_replace('{region}', $this->apiClient->getRegion(), $url); $queryParameters = array_merge(['api_key' => $this->apiClient->getApiKey()], $queryParameters); $fullUrl = $this->buildUri($url, $queryParameters); if ($this->apiClient->getCacheProvider()->contains($fullUrl)) { return $this->buildApiResult($fullUrl, json_decode($this->apiClient->getCacheProvider()->fetch($fullUrl), true), true); } try { $response = $this->apiClient->getHttpClient()->get($url, ['query' => $queryParameters]); return $this->buildApiResult($fullUrl, json_decode((string) $response->getBody(), true), false, $response); } catch (ClientException $e) { throw (new ClientExceptionHandler())->handleClientException($e); } }