Issues (197)

src/Commands/DisableCommand.php (1 issue)

Severity
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\InputArgument;
8
9
class DisableCommand extends Command
10
{
11
    /**
12
     * The console command name.
13
     *
14
     * @var string
15
     */
16
    protected $name = 'domain:disable';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Disable the specified domain.';
24
25
    /**
26
     * Execute the console command.
27
     */
28
    public function handle(): int
29
    {
30
        $this->components->info('Disabling domain ...');
31
32
        if ($name = $this->argument('domain') ) {
33
            $this->disable($name);
34
35
            return 0;
36
        }
37
38
        $this->disableAll();
39
40
        return 0;
41
    }
42
43
    /**
44
     * disableAll
45
     *
46
     * @return void
47
     */
48
    public function disableAll()
49
    {
50
        /** @var Domains $domains */
51
        $domains = $this->laravel['domains']->all();
52
53
        foreach ($domains as $domain) {
54
            $this->disable($domain);
55
        }
56
    }
57
58
    /**
59
     * disable
60
     *
61
     * @param string $name
62
     * @return void
63
     */
64
    public function disable($name)
65
    {
66
        if ($name instanceof Domain) {
0 ignored issues
show
$name is never a sub-type of Salah3id\Domains\Domain.
Loading history...
67
            $domain = $name;
68
        }else {
69
            $domain = $this->laravel['domains']->findOrFail($name);
70
        }
71
72
        if ($domain->isEnabled()) {
73
            $domain->disable();
74
75
            $this->components->info("Domain [{$domain}] disabled successful.");
76
        } else {
77
            $this->components->warn("Domain [{$domain}] has already disabled.");
78
        }
79
80
    }
81
82
    /**
83
     * Get the console command arguments.
84
     *
85
     * @return array
86
     */
87
    protected function getArguments()
88
    {
89
        return [
90
            ['domain', InputArgument::OPTIONAL, 'Domain name.'],
91
        ];
92
    }
93
}
94