1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace FondBot\Toolbelt; |
6
|
|
|
|
7
|
|
|
use League\Flysystem\MountManager; |
8
|
|
|
use League\Flysystem\FilesystemInterface; |
9
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
12
|
|
|
use Symfony\Component\Console\Command\Command as SymfonyCommand; |
13
|
|
|
|
14
|
|
|
abstract class Command extends SymfonyCommand |
15
|
|
|
{ |
16
|
|
|
/** @var InputInterface */ |
17
|
|
|
protected $input; |
18
|
|
|
|
19
|
|
|
/** @var SymfonyStyle */ |
20
|
|
|
protected $output; |
21
|
|
|
|
22
|
9 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
23
|
|
|
{ |
24
|
9 |
|
$this->input = $input; |
25
|
9 |
|
$this->output = new SymfonyStyle($input, $output); |
26
|
|
|
|
27
|
9 |
|
$this->handle(); |
28
|
9 |
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Get argument value. |
32
|
|
|
* |
33
|
|
|
* @param string $name |
34
|
|
|
* |
35
|
|
|
* @return mixed |
36
|
|
|
* |
37
|
|
|
* @throws \Symfony\Component\Console\Exception\InvalidArgumentException |
38
|
|
|
*/ |
39
|
4 |
|
protected function getArgument(string $name) |
40
|
|
|
{ |
41
|
4 |
|
return $this->input->getArgument($name); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Get option value. |
46
|
|
|
* |
47
|
|
|
* @param string $name |
48
|
|
|
* |
49
|
|
|
* @return mixed |
50
|
|
|
* |
51
|
|
|
* @throws \Symfony\Component\Console\Exception\InvalidArgumentException |
52
|
|
|
*/ |
53
|
1 |
|
protected function getOption(string $name) |
54
|
|
|
{ |
55
|
1 |
|
return $this->input->getOption($name); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Write a message. |
60
|
|
|
* |
61
|
|
|
* @param string $message |
62
|
|
|
*/ |
63
|
2 |
|
protected function line(string $message): void |
64
|
|
|
{ |
65
|
2 |
|
$this->output->writeln($message); |
66
|
2 |
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Display success message. |
70
|
|
|
* |
71
|
|
|
* @param string $message |
72
|
|
|
*/ |
73
|
2 |
|
protected function success(string $message): void |
74
|
|
|
{ |
75
|
2 |
|
$this->output->success($message); |
76
|
2 |
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Display info message. |
80
|
|
|
* |
81
|
|
|
* @param string $message |
82
|
|
|
*/ |
83
|
1 |
|
protected function info(string $message): void |
84
|
|
|
{ |
85
|
1 |
|
$this->output->writeln('<info>'.$message.'</info>'); |
86
|
1 |
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Display warning message. |
90
|
|
|
* |
91
|
|
|
* @param string $message |
92
|
|
|
*/ |
93
|
|
|
protected function warning(string $message): void |
94
|
|
|
{ |
95
|
|
|
$this->output->writeln('<warning>'.$message.'</warning>'); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Display error message. |
100
|
|
|
* |
101
|
|
|
* @param string $message |
102
|
|
|
*/ |
103
|
2 |
|
protected function error(string $message): void |
104
|
|
|
{ |
105
|
2 |
|
$this->output->writeln('<error>'.$message.'</error>'); |
106
|
2 |
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Prompt the user for input. |
110
|
|
|
* |
111
|
|
|
* @param string $message |
112
|
|
|
* |
113
|
|
|
* @return string |
114
|
|
|
*/ |
115
|
1 |
|
protected function input(string $message): string |
116
|
|
|
{ |
117
|
1 |
|
return $this->output->ask($message); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Display confirmation input. |
122
|
|
|
* |
123
|
|
|
* @param string $message |
124
|
|
|
* |
125
|
|
|
* @return bool |
126
|
|
|
*/ |
127
|
1 |
|
protected function confirm(string $message): bool |
128
|
|
|
{ |
129
|
1 |
|
return $this->output->confirm($message, false); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Get filesystem instance. |
134
|
|
|
* |
135
|
|
|
* @return FilesystemInterface |
136
|
|
|
* |
137
|
|
|
* @throws \League\Flysystem\FilesystemNotFoundException |
138
|
|
|
* @throws \Psr\Container\ContainerExceptionInterface |
139
|
|
|
*/ |
140
|
1 |
|
protected function filesystem(): FilesystemInterface |
141
|
|
|
{ |
142
|
|
|
/** @var MountManager $manager */ |
143
|
1 |
|
$manager = resolve(MountManager::class); |
144
|
|
|
|
145
|
1 |
|
return $manager->getFilesystem('local'); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Handle command. |
150
|
|
|
*/ |
151
|
|
|
abstract public function handle(): void; |
152
|
|
|
} |
153
|
|
|
|