mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-12 01:54:41 +08:00
Added entities config for domains
This commit is contained in:
22
module/Core/src/Entity/Domain.php
Normal file
22
module/Core/src/Entity/Domain.php
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user