From bd168808b221c73fe25e4562c642baa742f98754 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Thu, 4 Mar 2021 05:58:07 +0100 Subject: [PATCH] Make Chrly's domain configurable --- .env.dist | 1 + api/config/config-test.php | 2 +- common/components/SkinsSystemApi.php | 8 ++++++-- common/config/config-test.php | 2 +- common/config/config.php | 5 ++++- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.env.dist b/.env.dist index 7f1847e..6b2a010 100644 --- a/.env.dist +++ b/.env.dist @@ -13,6 +13,7 @@ JWT_PRIVATE_PEM_LOCATION= JWT_PUBLIC_PEM_LOCATION= ## External services +CHRLY_HOST=skinsystem.ely.by RECAPTCHA_PUBLIC= RECAPTCHA_SECRET= SENTRY_DSN= diff --git a/api/config/config-test.php b/api/config/config-test.php index 35b7823..acce9a6 100644 --- a/api/config/config-test.php +++ b/api/config/config-test.php @@ -26,7 +26,7 @@ return [ }; }, common\components\SkinsSystemApi::class => function() { - return new class extends common\components\SkinsSystemApi { + return new class('http://chrly.ely.by') extends common\components\SkinsSystemApi { public function textures(string $username): ?array { return [ 'SKIN' => [ diff --git a/common/components/SkinsSystemApi.php b/common/components/SkinsSystemApi.php index eb2a580..bdd4d22 100644 --- a/common/components/SkinsSystemApi.php +++ b/common/components/SkinsSystemApi.php @@ -10,10 +10,14 @@ use Yii; // TODO: convert to complete Chrly client library class SkinsSystemApi { - private const BASE_DOMAIN = 'http://skinsystem.ely.by'; + private string $baseDomain; private ?ClientInterface $client = null; + public function __construct(string $baseDomain) { + $this->baseDomain = $baseDomain; + } + /** * @param string $username * @throws \GuzzleHttp\Exception\GuzzleException @@ -69,7 +73,7 @@ class SkinsSystemApi { } private function buildUrl(string $url): string { - return static::BASE_DOMAIN . $url; + return $this->baseDomain . $url; } private function getClient(): ClientInterface { diff --git a/common/config/config-test.php b/common/config/config-test.php index ecea105..4ba070a 100644 --- a/common/config/config-test.php +++ b/common/config/config-test.php @@ -7,7 +7,7 @@ return [ ], 'components' => [ 'cache' => [ - 'class' => \yii\caching\FileCache::class, + 'class' => yii\caching\FileCache::class, ], 'security' => [ // It's allows us to increase tests speed by decreasing password hashing algorithm complexity diff --git a/common/config/config.php b/common/config/config.php index 1cdef7b..2289530 100644 --- a/common/config/config.php +++ b/common/config/config.php @@ -19,7 +19,10 @@ return [ 'singletons' => [ GuzzleHttp\ClientInterface::class => GuzzleHttp\Client::class, Ely\Mojang\Api::class => Ely\Mojang\Api::class, - common\components\SkinsSystemApi::class => common\components\SkinsSystemApi::class, + common\components\SkinsSystemApi::class => [ + 'class' => common\components\SkinsSystemApi::class, + '__construct()' => 'http://' . (getenv('CHRLY_HOST') ?: 'skinsystem.ely.by'), + ], ], ], 'components' => [