Ensured base path is honored when stringifying short URLs with a custom domain

This commit is contained in:
Alejandro Celaya
2021-02-01 23:18:19 +01:00
parent 4b4a859722
commit 8fa0c95f5a
3 changed files with 25 additions and 5 deletions

View File

@@ -7,13 +7,17 @@ namespace Shlinkio\Shlink\Core\ShortUrl\Helper;
use Laminas\Diactoros\Uri;
use Shlinkio\Shlink\Core\Entity\ShortUrl;
use function sprintf;
class ShortUrlStringifier implements ShortUrlStringifierInterface
{
private array $domainConfig;
private string $basePath;
public function __construct(array $domainConfig)
public function __construct(array $domainConfig, string $basePath = '')
{
$this->domainConfig = $domainConfig;
$this->basePath = $basePath;
}
public function stringify(ShortUrl $shortUrl): string
@@ -31,6 +35,6 @@ class ShortUrlStringifier implements ShortUrlStringifierInterface
return $this->domainConfig['hostname'] ?? '';
}
return $domain->getAuthority();
return sprintf('%s%s', $domain->getAuthority(), $this->basePath);
}
}