endpoint = $endpoint; $this->isEUNE = $isEUNE; if ($isEUNE){ $this->host = "https://eun1.api.riotgames.com"; } } public function useRouting(): void { $this->host = "https://europe.api.riotgames.com"; $this->usesRouting = true; } 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(&$successWithEUNE=false) { $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->isEUNE && !$this->usesRouting) { $this->isEUNE = true; $this->host = "https://eun1.api.riotgames.com"; return $this->run($successWithEUNE); } $successWithEUNE = $this->isEUNE; return json_decode($result); } }