1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Shlinkio\Shlink\CLI\Command\Domain; |
6
|
|
|
|
7
|
|
|
use Shlinkio\Shlink\CLI\Util\ExitCodes; |
8
|
|
|
use Shlinkio\Shlink\CLI\Util\ShlinkTable; |
9
|
|
|
use Shlinkio\Shlink\Core\Domain\DomainServiceInterface; |
10
|
|
|
use Shlinkio\Shlink\Core\Entity\Domain; |
11
|
|
|
use Symfony\Component\Console\Command\Command; |
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
14
|
|
|
|
15
|
|
|
use function Functional\map; |
16
|
|
|
|
17
|
|
|
class ListDomainsCommand extends Command |
18
|
|
|
{ |
19
|
|
|
public const NAME = 'domain:list'; |
20
|
|
|
|
21
|
|
|
private DomainServiceInterface $domainService; |
22
|
|
|
private string $defaultDomain; |
23
|
|
|
|
24
|
1 |
|
public function __construct(DomainServiceInterface $domainService, string $defaultDomain) |
25
|
|
|
{ |
26
|
1 |
|
parent::__construct(); |
27
|
1 |
|
$this->domainService = $domainService; |
28
|
1 |
|
$this->defaultDomain = $defaultDomain; |
29
|
1 |
|
} |
30
|
|
|
|
31
|
1 |
|
protected function configure(): void |
32
|
|
|
{ |
33
|
|
|
$this |
34
|
1 |
|
->setName(self::NAME) |
35
|
1 |
|
->setDescription('List all domains that have been ever used for some short URL'); |
36
|
1 |
|
} |
37
|
|
|
|
38
|
1 |
|
protected function execute(InputInterface $input, OutputInterface $output): ?int |
39
|
|
|
{ |
40
|
1 |
|
$regularDomains = $this->domainService->listDomainsWithout($this->defaultDomain); |
41
|
|
|
|
42
|
1 |
|
ShlinkTable::fromOutput($output)->render(['Domain', 'Is default'], [ |
43
|
1 |
|
[$this->defaultDomain, 'Yes'], |
44
|
1 |
|
...map($regularDomains, fn (Domain $domain) => [$domain->getAuthority(), 'No']), |
45
|
|
|
]); |
46
|
|
|
|
47
|
1 |
|
return ExitCodes::EXIT_SUCCESS; |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|