endpoint = $endpoint; } public function useRouting(): void { $this->host = "https://europe.api.riotgames.com"; } public function setHeaders($headers): void { $this->headers = $headers; } public function setQueries($queries): void { $this->queries = $queries; } protected function getHeaderString(): string { $api_key = getenv("RIOT_API_KEY"); $header = "X-Riot-Token: $api_key\r\n"; foreach ($this->headers as $key => $value) { $header .= "$key: $value\r\n"; } return $header; } private function getFinalURL(): string { $queryString = "?"; foreach ($this->queries as $key => $value) { $queryString .= "$key=$value&"; } $url = $this->host . "/" . $this->endpoint . $queryString; return str_replace(" ", "", $url); } public function run() { $opts = [ "http" => [ "method" => "GET", "header" => $this->getHeaderString() ] ]; $context = stream_context_create($opts); $url = $this->getFinalURL(); $result = @file_get_contents($url, false, $context); $this->responseHeader = $http_response_header; preg_match_all("/HTTP\/\d\.\d\s+(\d+)\s+/", $this->responseHeader[0], $matches); $this->responseCode = intval($matches[1][0]); if ($this->responseCode == 404 && !$this->triedEUNE) { $this->host = "https://eun1.api.riotgames.com"; $this->triedEUNE = true; return $this->run(); } return json_decode($result); } }