diff --git a/src/Extension/UrlExtension.php b/src/Extension/UrlExtension.php index 9ddc9eb..691d5dc 100644 --- a/src/Extension/UrlExtension.php +++ b/src/Extension/UrlExtension.php @@ -16,20 +16,26 @@ PATTERN; protected string $urlBase; + protected string $appUrl; + protected string $assetToken; protected array $routes; protected array $routesTarget; + protected bool $forceSSL = false; + public array $tokens = [ "url" , "route", "asset", "slug" ]; #[\Deprecated] protected bool $enforceExistingArguments = true; - public function __construct(string $urlBase = "", string $assetToken = "") { + public function __construct(string $urlBase = "", string $assetToken = "", string $appUrl = "", bool $forceSSL = false) { $this->urlBase = trim($urlBase, "/"); $this->assetToken = $assetToken; + $this->appUrl = $appUrl; + $this->forceSSL = $forceSSL; } public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token, array $options = []) : string @@ -169,7 +175,7 @@ PATTERN; protected function scheme() : string { - return ( $this->isHttps() ? "https" : "http" ) . "://"; + return ( $this->forceSSL || $this->isHttps() ? "https" : "http" ) . "://"; } protected function base() : string @@ -188,7 +194,9 @@ PATTERN; protected function domain() : string { - return strtolower($_SERVER['HTTP_HOST']); + $port = $this->isDefaultPort() ? "" : ":" . $_SERVER['SERVER_PORT']; + + return strtolower($this->appUrl ? $this->appUrl . $port : $_SERVER['HTTP_HOST']); } protected function isDefaultPort() : bool