diff --git a/src/Extension/UrlExtension.php b/src/Extension/UrlExtension.php index 91eceec..82082b6 100644 --- a/src/Extension/UrlExtension.php +++ b/src/Extension/UrlExtension.php @@ -17,7 +17,7 @@ PATTERN; protected string $urlBase; - protected string $appUrl; + protected array $appUrl; protected string $assetToken; @@ -32,7 +32,7 @@ PATTERN; #[\Deprecated] protected bool $enforceExistingArguments = true; - public function __construct(string $urlBase = "", string $assetToken = "", string $appUrl = "", bool $forceSSL = false) { + public function __construct(string $urlBase = "", string $assetToken = "", array $appUrl = [], bool $forceSSL = false) { $this->urlBase = trim($urlBase, "/"); $this->assetToken = $assetToken; $this->appUrl = $appUrl; @@ -202,7 +202,18 @@ PATTERN; $port = $this->isDefaultPort() ? "" : ":" . $_SERVER['SERVER_PORT']; } - return strtolower($this->appUrl ? $this->appUrl . $port : $_SERVER['HTTP_HOST']); + return strtolower($this->appUrl($port) ?: $_SERVER['HTTP_HOST']); + } + + protected function appUrl(string $port) : string + { + $domain = strtolower($_SERVER['HTTP_HOST']); + + if (in_array($domain, $this->appUrl)) { + return $domain . $port; + } + + return $this->appUrl[0] . $port; } protected function isDefaultPort() : bool