|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* This file is part of Laravel Zero. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Nuno Maduro <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace LaravelZero\Framework\Commands; |
|
15
|
|
|
|
|
16
|
|
|
use Illuminate\Console\Command as BaseCommand; |
|
17
|
|
|
use Illuminate\Console\Scheduling\Schedule; |
|
18
|
|
|
use LaravelZero\Framework\Providers\CommandRecorder\CommandRecorderRepository; |
|
19
|
|
|
use function func_get_args; |
|
20
|
|
|
use function str_repeat; |
|
21
|
|
|
use function strlen; |
|
22
|
|
|
|
|
23
|
|
|
abstract class Command extends BaseCommand |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* Holds an instance of the app, if any. |
|
27
|
|
|
* |
|
28
|
|
|
* @var \LaravelZero\Framework\Application |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $app; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Define the command's schedule. |
|
34
|
|
|
* |
|
35
|
|
|
* @param \Illuminate\Console\Scheduling\Schedule $schedule |
|
36
|
|
|
* @return void |
|
37
|
|
|
*/ |
|
38
|
39 |
|
public function schedule(Schedule $schedule) |
|
|
|
|
|
|
39
|
|
|
{ |
|
40
|
39 |
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* {@inheritdoc} |
|
44
|
|
|
*/ |
|
45
|
39 |
|
public function setLaravel($laravel): void |
|
46
|
|
|
{ |
|
47
|
39 |
|
parent::setLaravel($this->app = $laravel); |
|
48
|
39 |
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Performs the given task, outputs and |
|
52
|
|
|
* returns the result. |
|
53
|
|
|
*/ |
|
54
|
17 |
|
public function task(string $title = '', $task = null): bool |
|
55
|
|
|
{ |
|
56
|
17 |
|
return $this->__call('task', func_get_args()); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/* |
|
60
|
|
|
* Displays the given string as title. |
|
61
|
|
|
*/ |
|
62
|
2 |
|
public function title(string $title): Command |
|
63
|
|
|
{ |
|
64
|
2 |
|
$size = strlen($title); |
|
65
|
2 |
|
$spaces = str_repeat(' ', $size); |
|
66
|
|
|
|
|
67
|
2 |
|
$this->output->newLine(); |
|
68
|
2 |
|
$this->output->writeln("<bg=blue;fg=white>$spaces$spaces$spaces</>"); |
|
69
|
2 |
|
$this->output->writeln("<bg=blue;fg=white>$spaces$title$spaces</>"); |
|
70
|
2 |
|
$this->output->writeln("<bg=blue;fg=white>$spaces$spaces$spaces</>"); |
|
71
|
2 |
|
$this->output->newLine(); |
|
72
|
|
|
|
|
73
|
2 |
|
return $this; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* {@inheritdoc} |
|
78
|
|
|
*/ |
|
79
|
1 |
|
public function call($command, array $arguments = []) |
|
80
|
|
|
{ |
|
81
|
1 |
|
resolve(CommandRecorderRepository::class)->create($command, $arguments); |
|
82
|
|
|
|
|
83
|
1 |
|
return parent::call($command, $arguments); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* {@inheritdoc} |
|
88
|
|
|
*/ |
|
89
|
|
|
public function callSilent($command, array $arguments = []) |
|
90
|
|
|
{ |
|
91
|
|
|
resolve(CommandRecorderRepository::class)->create($command, $arguments, CommandRecorderRepository::MODE_SILENT); |
|
92
|
|
|
|
|
93
|
|
|
return parent::callSilent($command, $arguments); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* {@inheritdoc} |
|
98
|
|
|
* |
|
99
|
|
|
* @see {https://github.com/laravel/framework/pull/27005} |
|
100
|
|
|
*/ |
|
101
|
39 |
|
public function setHidden($hidden) |
|
102
|
|
|
{ |
|
103
|
39 |
|
parent::setHidden($this->hidden = $hidden); |
|
104
|
|
|
|
|
105
|
39 |
|
return $this; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @param int $count |
|
110
|
|
|
* @return Command |
|
111
|
|
|
*/ |
|
112
|
|
|
public function newLine(int $count = 1) |
|
113
|
|
|
{ |
|
114
|
|
|
$this->output->newLine($count); |
|
115
|
|
|
|
|
116
|
|
|
return $this; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @param string|string[] $message |
|
121
|
|
|
* @return Command |
|
122
|
|
|
*/ |
|
123
|
|
|
public function successBlock($message) |
|
124
|
|
|
{ |
|
125
|
|
|
$this->output->success($message); |
|
126
|
|
|
|
|
127
|
|
|
return $this; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @param string|string[] $message |
|
132
|
|
|
* @return Command |
|
133
|
|
|
*/ |
|
134
|
|
|
public function warningBlock($message) |
|
135
|
|
|
{ |
|
136
|
|
|
$this->output->warning($message); |
|
137
|
|
|
|
|
138
|
|
|
return $this; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @param array $elements |
|
143
|
|
|
* @return $this |
|
144
|
|
|
*/ |
|
145
|
|
|
public function listing(array $elements) |
|
146
|
|
|
{ |
|
147
|
|
|
$this->output->listing($elements); |
|
148
|
|
|
|
|
149
|
|
|
return $this; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* @param string|string[] $message |
|
154
|
|
|
* @return $this |
|
155
|
|
|
*/ |
|
156
|
|
|
public function write($message) |
|
157
|
|
|
{ |
|
158
|
|
|
$this->output->write($message); |
|
159
|
|
|
|
|
160
|
|
|
return $this; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* @param string|string[] $message |
|
165
|
|
|
*/ |
|
166
|
|
|
public function errorBlock($message) |
|
167
|
|
|
{ |
|
168
|
|
|
$this->output->error($message); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* @return self |
|
173
|
|
|
*/ |
|
174
|
|
|
public function progressStart() |
|
175
|
|
|
{ |
|
176
|
|
|
$this->output->progressStart(); |
|
177
|
|
|
|
|
178
|
|
|
return $this; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
/** |
|
182
|
|
|
* @param int $step |
|
183
|
|
|
* @return self |
|
184
|
|
|
*/ |
|
185
|
|
|
public function progressAdvance(int $step = 1) |
|
186
|
|
|
{ |
|
187
|
|
|
$this->output->progressAdvance($step); |
|
188
|
|
|
|
|
189
|
|
|
return $this; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
public function progressFinish() |
|
193
|
|
|
{ |
|
194
|
|
|
$this->output->progressFinish(); |
|
195
|
|
|
|
|
196
|
|
|
return $this; |
|
197
|
|
|
} |
|
198
|
|
|
} |
|
199
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.