|
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 function func_get_args; |
|
17
|
|
|
use Illuminate\Console\Command as BaseCommand; |
|
18
|
|
|
use Illuminate\Console\Scheduling\Schedule; |
|
19
|
|
|
use LaravelZero\Framework\Providers\CommandRecorder\CommandRecorderRepository; |
|
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
|
38 |
|
public function schedule(Schedule $schedule) |
|
|
|
|
|
|
39
|
|
|
{ |
|
40
|
38 |
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* {@inheritdoc} |
|
44
|
|
|
*/ |
|
45
|
38 |
|
public function setLaravel($laravel): void |
|
46
|
|
|
{ |
|
47
|
38 |
|
parent::setLaravel($this->app = $laravel); |
|
48
|
38 |
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Performs the given task, outputs and |
|
52
|
|
|
* returns the result. |
|
53
|
|
|
*/ |
|
54
|
15 |
|
public function task(string $title = '', $task = null): bool |
|
55
|
|
|
{ |
|
56
|
15 |
|
return $this->__call('task', func_get_args()); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/* |
|
60
|
|
|
* Displays the given string as title. |
|
61
|
|
|
*/ |
|
62
|
1 |
|
public function title(string $title): Command |
|
63
|
|
|
{ |
|
64
|
1 |
|
$size = strlen($title); |
|
65
|
1 |
|
$spaces = str_repeat(' ', $size); |
|
66
|
|
|
|
|
67
|
1 |
|
$this->output->newLine(); |
|
68
|
1 |
|
$this->output->writeln("<bg=blue;fg=white>$spaces$spaces$spaces</>"); |
|
69
|
1 |
|
$this->output->writeln("<bg=blue;fg=white>$spaces$title$spaces</>"); |
|
70
|
1 |
|
$this->output->writeln("<bg=blue;fg=white>$spaces$spaces$spaces</>"); |
|
71
|
1 |
|
$this->output->newLine(); |
|
72
|
|
|
|
|
73
|
1 |
|
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
|
38 |
|
public function setHidden($hidden) |
|
102
|
|
|
{ |
|
103
|
38 |
|
parent::setHidden($this->hidden = $hidden); |
|
104
|
|
|
|
|
105
|
38 |
|
return $this; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Prompt the user for input. |
|
110
|
|
|
* |
|
111
|
|
|
* @param string $question |
|
112
|
|
|
* @param string|null $default |
|
113
|
|
|
* @param array|string|null $validationRule |
|
114
|
|
|
* @return mixed |
|
115
|
|
|
*/ |
|
116
|
1 |
|
public function ask($question, $default = null, $validationRule = null) |
|
117
|
|
|
{ |
|
118
|
1 |
|
if (! class_exists(\Illuminate\Validation\Validator::class) || ! $this->app->bound('validator')) { |
|
|
|
|
|
|
119
|
1 |
|
throw new \RuntimeException('The "illuminate/validation" package is required to use validation rules'); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
$validator = null; |
|
123
|
|
|
if ($validationRule) { |
|
124
|
|
|
$validator = function ($answer) use ($question, $validationRule) { |
|
125
|
|
|
\Illuminate\Support\Facades\Validator::make([$question => $answer], [ |
|
126
|
|
|
$question => $validationRule, |
|
127
|
|
|
])->validate(); |
|
128
|
|
|
}; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
return $this->output->ask($question, $default, $validator); |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.