mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-06 07:13:11 +08:00
40 lines
1.0 KiB
PHP
40 lines
1.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Shlinkio\Shlink\Core\Domain;
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Shlinkio\Shlink\Core\Domain\Model\DomainItem;
|
|
use Shlinkio\Shlink\Core\Domain\Repository\DomainRepositoryInterface;
|
|
use Shlinkio\Shlink\Core\Entity\Domain;
|
|
|
|
use function Functional\map;
|
|
|
|
class DomainService implements DomainServiceInterface
|
|
{
|
|
private EntityManagerInterface $em;
|
|
private string $defaultDomain;
|
|
|
|
public function __construct(EntityManagerInterface $em, string $defaultDomain)
|
|
{
|
|
$this->em = $em;
|
|
$this->defaultDomain = $defaultDomain;
|
|
}
|
|
|
|
/**
|
|
* @return DomainItem[]
|
|
*/
|
|
public function listDomainsWithout(): array
|
|
{
|
|
/** @var DomainRepositoryInterface $repo */
|
|
$repo = $this->em->getRepository(Domain::class);
|
|
$domains = $repo->findDomainsWithout($this->defaultDomain);
|
|
|
|
return [
|
|
new DomainItem($this->defaultDomain, true),
|
|
...map($domains, fn (Domain $domain) => new DomainItem($domain->getAuthority(), false)),
|
|
];
|
|
}
|
|
}
|