Added entities config for domains

This commit is contained in:
Alejandro Celaya
2019-09-30 19:42:27 +02:00
parent 6f38790d47
commit 7b1857dcda
6 changed files with 86 additions and 1 deletions

View File

@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace Shlinkio\Shlink\Core\Entity;
use Shlinkio\Shlink\Common\Entity\AbstractEntity;
class Domain extends AbstractEntity
{
/** @var string */
private $authority;
public function __construct(string $authority)
{
$this->authority = $authority;
}
public function getAuthority(): string
{
return $this->authority;
}
}

View File

@@ -29,6 +29,8 @@ class ShortUrl extends AbstractEntity
private $validUntil;
/** @var integer|null */
private $maxVisits;
/** @var Domain|null */
private $domain;
public function __construct(string $longUrl, ?ShortUrlMeta $meta = null)
{
@@ -42,6 +44,7 @@ class ShortUrl extends AbstractEntity
$this->validUntil = $meta->getValidUntil();
$this->maxVisits = $meta->getMaxVisits();
$this->shortCode = $meta->getCustomSlug() ?? ''; // TODO logic to calculate short code should be passed somehow
$this->domain = $meta->hasDomain() ? new Domain($meta->getDomain()) : null;
}
public function getLongUrl(): string
@@ -131,4 +134,13 @@ class ShortUrl extends AbstractEntity
{
return $this->maxVisits !== null && $this->getVisitsCount() >= $this->maxVisits;
}
public function domain(string $fallback = ''): string
{
if ($this->domain === null) {
return $fallback;
}
return $this->domain->getAuthority();
}
}