From 3bde676217e0e7caeec4818697646ecfdedbbb8e Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Fri, 23 Dec 2016 01:50:34 +0300 Subject: [PATCH] =?UTF-8?q?#276:=20=D0=B5=D1=81=D0=BB=D0=B8=20=D1=81=D0=B8?= =?UTF-8?q?=D1=81=D1=82=D0=B5=D0=BC=D0=B0=20=D1=81=D0=BA=D0=B8=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2=20=D0=BD=D0=B5=D0=B4=D0=BE=D1=81=D1=82=D1=83=D0=BF=D0=BD?= =?UTF-8?q?=D0=B0,=20=D1=82=D0=BE=20=D0=B3=D0=B5=D0=BD=D0=B5=D1=80=D0=B8?= =?UTF-8?q?=D1=80=D1=83=D0=B5=D0=BC=20=D0=BE=D1=82=D0=B2=D0=B5=D1=82=20?= =?UTF-8?q?=D1=81=D0=B0=D0=BC=D0=BE=D1=81=D1=82=D0=BE=D1=8F=D1=82=D0=B5?= =?UTF-8?q?=D0=BB=D1=8C=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/components/SkinSystem/Api.php | 15 ++++++++++----- common/models/Textures.php | 23 ++++++++++++++++++++--- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/common/components/SkinSystem/Api.php b/common/components/SkinSystem/Api.php index 14bbfd1..4237eac 100644 --- a/common/components/SkinSystem/Api.php +++ b/common/components/SkinSystem/Api.php @@ -8,21 +8,26 @@ class Api { const BASE_DOMAIN = 'http://skinsystem.ely.by'; - public function textures($username) : array { + /** + * @param string $username + * @throws \GuzzleHttp\Exception\GuzzleException + * + * @return array + */ + public function textures(string $username): array { $response = $this->getClient()->get($this->getBuildUrl('/textures/' . $username)); - $textures = json_decode($response->getBody(), true); - return $textures; + return json_decode($response->getBody(), true); } - protected function getBuildUrl(string $url) : string { + protected function getBuildUrl(string $url): string { return self::BASE_DOMAIN . $url; } /** * @return GuzzleClient */ - protected function getClient() : GuzzleClient { + protected function getClient(): GuzzleClient { return Yii::$app->guzzle; } diff --git a/common/models/Textures.php b/common/models/Textures.php index 3bb3333..85ec58c 100644 --- a/common/models/Textures.php +++ b/common/models/Textures.php @@ -4,6 +4,8 @@ namespace common\models; use common\components\SkinSystem\Api as SkinSystemApi; use DateInterval; use DateTime; +use GuzzleHttp\Exception\RequestException; +use Yii; class Textures { @@ -57,9 +59,20 @@ class Textures { } } - public function getTextures() { - $api = new SkinSystemApi(); - return $api->textures($this->account->username); + public function getTextures(): array { + try { + $textures = $this->getSkinsystemApi()->textures($this->account->username); + } catch (RequestException $e) { + Yii::warning('Cannot get textures from skinsystem.ely.by. Exception message is ' . $e->getMessage()); + $textures = [ + 'SKIN' => [ + 'url' => 'http://skins.minecraft.net/MinecraftSkins/' . $this->account->username . '.png', + 'hash' => md5(uniqid('random, please', true)), + ], + ]; + } + + return $textures; } public static function encrypt(array $data) { @@ -70,4 +83,8 @@ class Textures { return json_decode(base64_decode($string), $assoc); } + protected function getSkinsystemApi(): SkinSystemApi { + return new SkinSystemApi(); + } + }