serviceUrl === null) { throw new InvalidConfigException('serviceUrl is required'); } if ($this->baseDomain === null) { $this->baseDomain = Yii::$app->urlManager->getHostInfo(); if ($this->baseDomain === null) { throw new InvalidConfigException('Cannot automatically obtain base domain'); } } } /** * @param string $templateName * @param string $locale * @param array $params * * @return string * @throws \GuzzleHttp\Exception\GuzzleException */ public function render(string $templateName, string $locale, array $params = []): string { $request = new TemplateRequest($templateName, $locale, ArrayHelper::merge($params, [ 'assetsHost' => $this->buildBasePath(), ])); return $this->getApi()->getTemplate($request); } protected function getApi(): Api { if ($this->api === null) { $this->api = new Api($this->serviceUrl); } return $this->api; } private function buildBasePath(): string { return trim($this->baseDomain, '/') . '/' . trim($this->basePath, '/'); } }