Moved code to convert a ShortUrl into a full link as string to the entity itself

This commit is contained in:
Alejandro Celaya
2019-09-30 20:01:36 +02:00
parent 7b1857dcda
commit 1085809fa5
5 changed files with 21 additions and 38 deletions

View File

@@ -8,6 +8,7 @@ use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Shlinkio\Shlink\Common\Entity\AbstractEntity;
use Shlinkio\Shlink\Core\Model\ShortUrlMeta;
use Zend\Diactoros\Uri;
use function count;
@@ -135,7 +136,14 @@ class ShortUrl extends AbstractEntity
return $this->maxVisits !== null && $this->getVisitsCount() >= $this->maxVisits;
}
public function domain(string $fallback = ''): string
public function toString(array $domainConfig): string
{
return (string) (new Uri())->withPath($this->shortCode)
->withScheme($domainConfig['schema'] ?? 'http')
->withHost($this->resolveDomain($domainConfig['hostname'] ?? ''));
}
private function resolveDomain(string $fallback = ''): string
{
if ($this->domain === null) {
return $fallback;