|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Recca0120\Terminal\Console\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Console\Kernel as ArtisanContract; |
|
6
|
|
|
use Illuminate\Support\Str; |
|
7
|
|
|
use InvalidArgumentException; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
9
|
|
|
use Symfony\Component\Console\Input\StringInput; |
|
10
|
|
|
|
|
11
|
|
|
class Artisan extends Command |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* The console command name. |
|
15
|
|
|
* |
|
16
|
|
|
* @var string |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $name = 'artisan'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* The console command description. |
|
22
|
|
|
* |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $description = 'laravel artisan'; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* no support array. |
|
29
|
|
|
* |
|
30
|
|
|
* @var array |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $notSupport = [ |
|
33
|
|
|
'down' => '', |
|
34
|
|
|
'tinker' => '', |
|
35
|
|
|
]; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* $artisan. |
|
39
|
|
|
* |
|
40
|
|
|
* @var \Illuminate\Contracts\Console\Kernel |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $artisan; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* __construct. |
|
46
|
|
|
* |
|
47
|
|
|
* @param \Illuminate\Contracts\Console\Kernel $artisan |
|
48
|
|
|
*/ |
|
49
|
3 |
|
public function __construct(ArtisanContract $artisan) |
|
50
|
|
|
{ |
|
51
|
3 |
|
parent::__construct(); |
|
52
|
|
|
|
|
53
|
3 |
|
$this->artisan = $artisan; |
|
54
|
3 |
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Handle the command. |
|
58
|
|
|
* |
|
59
|
|
|
* @throws \InvalidArgumentException |
|
60
|
|
|
*/ |
|
61
|
3 |
|
public function handle() |
|
62
|
|
|
{ |
|
63
|
3 |
|
$command = $this->forceCommand( |
|
64
|
3 |
|
trim($this->option('command')) |
|
65
|
|
|
); |
|
66
|
|
|
|
|
67
|
3 |
|
$input = new StringInput($command); |
|
68
|
3 |
|
$input->setInteractive(false); |
|
69
|
3 |
|
if (isset($this->notSupport[$input->getFirstArgument()]) === true) { |
|
70
|
|
|
throw new InvalidArgumentException('Command "'.$command.'" is not supported'); |
|
71
|
|
|
} |
|
72
|
3 |
|
$this->artisan->handle($input, $this->getOutput()); |
|
73
|
3 |
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* need focre option. |
|
77
|
|
|
* |
|
78
|
|
|
* @param string $command |
|
79
|
|
|
* @return string |
|
80
|
|
|
*/ |
|
81
|
3 |
|
protected function forceCommand($command) |
|
82
|
|
|
{ |
|
83
|
|
|
if (( |
|
84
|
3 |
|
Str::startsWith($command, 'migrate') === true && Str::startsWith($command, 'migrate:status') === false || |
|
85
|
3 |
|
Str::startsWith($command, 'db:seed') === true |
|
86
|
3 |
|
) && strpos($command, '--force') === false) { |
|
87
|
1 |
|
$command .= ' --force'; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
if (( |
|
91
|
3 |
|
is_null($this->laravel) === false && |
|
92
|
3 |
|
version_compare($this->laravel->version(), 5.5, '>=') && |
|
93
|
3 |
|
Str::startsWith($command, 'vendor:publish') === true |
|
94
|
3 |
|
) && strpos($command, '--all') === false) { |
|
95
|
1 |
|
$command .= ' --all'; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
3 |
|
return $command; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Get the console command options. |
|
103
|
|
|
* |
|
104
|
|
|
* @return array |
|
105
|
|
|
*/ |
|
106
|
3 |
|
protected function getOptions() |
|
107
|
|
|
{ |
|
108
|
|
|
return [ |
|
109
|
3 |
|
['command', null, InputOption::VALUE_REQUIRED], |
|
110
|
|
|
]; |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|