/** * Check whether a cache has expired or not * * @param integer $timestamp * @param DLCompare\LoLApiBundle\Api\Method $method * @return boolean */ public function isExpired($timestamp, Method $method) { if ($method->getCacheMaxAge() === false) { return false; } $now = time(); $expires = $timestamp + $method->getCacheMaxAge(); return $now > $expires; }
/** * Builds the url for the given webservice call * * @param DLCompare\LoLApiBundle\Api\Service\ServiceInterface $service * @param array $arguments * @param array $querystring * @return string * * @throws \LogicException */ protected function buildUrl(ServiceInterface $service, Method $method, array $arguments = array(), array $querystring = array()) { $url = "https://{region}.api.pvp.net/" . $service->getPrefix() . '/' . $method->getSuffix() . '?api_key=' . self::$api_key; $url = str_replace('{region}', $this->region, $url); $url = str_replace('{version}', $service->getVersion(), $url); foreach ($arguments as $key => $value) { $url = str_replace('{' . $key . '}', $value, $url); } $nok = preg_match_all("|{([\\w]+)}|U", $url, $missing, PREG_SET_ORDER); if ($nok > 0) { $params = []; foreach ($missing as $param) { $params[] = $param[0]; } throw new \LogicException('Missing parameters for this webservice : ' . implode(',', $params)); } foreach ($querystring as $key => $value) { $url .= '&' . $key . '=' . $value; } return $url; }