Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class StaticData
- {
- private $apiHost = 'http://ddragon.leagueoflegends.com';
- private $apiURLs = [
- 'versions' => [
- 'url' => '/realms/na.json'
- ],
- 'items' => [
- 'url' => '/cdn/{version}/data/en_US/item.json'
- ],
- 'runes' => [
- 'url' => '/cdn/{version}/data/en_US/rune.json'
- ],
- 'masteries' => [
- 'url' => '/cdn/{version}/data/en_US/mastery.json'
- ],
- 'champions' => [
- 'url' => '/cdn/{version}/data/en_US/champion.json'
- ],
- 'profileIcons' => [
- 'url' => '/cdn/{version}/data/en_US/profileicon.json'
- ],
- 'summonerSpells' => [
- 'url' => '/cdn/{version}/data/en_US/summoner.json'
- ],
- ];
- private $imageURLs = [
- 'champions' => [
- 'url' => '/cdn/{version}/img/champion/{img}.png',
- 'version' => 'champion',
- ],
- 'items' => [
- 'url' => '/cdn/{version}/img/item/{img}.png',
- 'version' => 'item',
- ],
- 'profileIcons' => [
- 'url' => '/cdn/{version}/img/profileicon/{img}.png',
- 'version' => 'profile_icon',
- ],
- 'summonerSpells' => [
- 'url' => '/cdn/{version}/img/spell/{img}.png',
- 'version' => 'summoner',
- ],
- 'masteries' => [
- 'url' => '/cdn/{version}/img/mastery/{img}.png',
- 'version' => 'mastery',
- ],
- 'runes' => [
- 'url' => '/cdn/{version}/img/rune/{img}.png',
- 'version' => 'rune',
- ],
- 'sprite' => [
- 'url' => '/cdn/{version}/img/sprite/{img}.png',
- ],
- ];
- public function __call ($function, $args = NULL)
- {
- if (!array_key_exists($function, $this->apiURLs))
- throw new Exception ("La fonction n'existe pas");
- $url = $this->apiHost . $this->apiURLs[$function]['url'];
- if ($function != 'versions')
- $url = str_replace('{version}', $args[0], $url);
- $apiOut = Unirest::get($url);
- switch($apiOut->code)
- {
- case 200:
- return $apiOut->body;
- break;
- default:
- case 404: // Page Not Found
- case 400: // Bad Request
- case 401: // Bad URL
- case 500: // Internal Server Error
- return array("error" => $apiOut->code);
- break;
- }
- }
- public function getStaticImage ($type, $img, $sprite = false)
- {
- $url = $this->apiHost . $this->imageURLs[($sprite ? 'sprite' : $type)]['url'];
- $version = $this->getVersion($this->imageURLs[$type]['version']);
- $url = str_replace('{version}', $version, $url);
- $url = str_replace('{img}', $img, $url);
- return $url;
- }
- private function getVersion ($version)
- {
- return $this->versions()->n->$version;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement