|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Salah3id\Domains\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
|
6
|
|
|
use Salah3id\Domains\Domain; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
8
|
|
|
|
|
9
|
|
|
class ListCommand extends Command |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* The console command name. |
|
13
|
|
|
* |
|
14
|
|
|
* @var string |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $name = 'domain:list'; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* The console command description. |
|
20
|
|
|
* |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $description = 'Show list of all domains.'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Execute the console command. |
|
27
|
|
|
*/ |
|
28
|
|
|
public function handle(): int |
|
29
|
|
|
{ |
|
30
|
|
|
$this->components->twoColumnDetail('<fg=gray>Status / Name</>', '<fg=gray>Path / priority</>'); |
|
31
|
|
|
collect($this->getRows())->each(function ($row) { |
|
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
$this->components->twoColumnDetail("[{$row[1]}] {$row[0]}", "{$row[3]} [{$row[2]}]"); |
|
34
|
|
|
}); |
|
35
|
|
|
|
|
36
|
|
|
return 0; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Get table rows. |
|
41
|
|
|
* |
|
42
|
|
|
* @return array |
|
43
|
|
|
*/ |
|
44
|
|
|
public function getRows() |
|
45
|
|
|
{ |
|
46
|
|
|
$rows = []; |
|
47
|
|
|
|
|
48
|
|
|
/** @var Domain $domain */ |
|
49
|
|
|
foreach ($this->getDomains() as $domain) { |
|
50
|
|
|
$rows[] = [ |
|
51
|
|
|
$domain->getName(), |
|
52
|
|
|
$domain->isEnabled() ? '<fg=green>Enabled</>' : '<fg=red>Disabled</>', |
|
53
|
|
|
$domain->get('priority'), |
|
54
|
|
|
$domain->getPath(), |
|
55
|
|
|
]; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
return $rows; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function getDomains() |
|
62
|
|
|
{ |
|
63
|
|
|
switch ($this->option('only')) { |
|
64
|
|
|
case 'enabled': |
|
65
|
|
|
return $this->laravel['domains']->getByStatus(1); |
|
66
|
|
|
|
|
67
|
|
|
break; |
|
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
case 'disabled': |
|
70
|
|
|
return $this->laravel['domains']->getByStatus(0); |
|
71
|
|
|
|
|
72
|
|
|
break; |
|
73
|
|
|
|
|
74
|
|
|
case 'priority': |
|
75
|
|
|
return $this->laravel['domains']->getPriority($this->option('direction')); |
|
76
|
|
|
|
|
77
|
|
|
break; |
|
78
|
|
|
|
|
79
|
|
|
default: |
|
80
|
|
|
return $this->laravel['domains']->all(); |
|
81
|
|
|
|
|
82
|
|
|
break; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Get the console command options. |
|
88
|
|
|
* |
|
89
|
|
|
* @return array |
|
90
|
|
|
*/ |
|
91
|
|
|
protected function getOptions() |
|
92
|
|
|
{ |
|
93
|
|
|
return [ |
|
94
|
|
|
['only', 'o', InputOption::VALUE_OPTIONAL, 'Types of domains will be displayed.', null], |
|
95
|
|
|
['direction', 'd', InputOption::VALUE_OPTIONAL, 'The direction of ordering.', 'asc'], |
|
96
|
|
|
]; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|