1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Cortex\Console\Console\Commands; |
6
|
|
|
|
7
|
|
|
use InvalidArgumentException; |
8
|
|
|
use Illuminate\Console\Command; |
9
|
|
|
use Symfony\Component\Console\Input\InputOption; |
10
|
|
|
use Symfony\Component\Console\Input\StringInput; |
11
|
|
|
use Illuminate\Contracts\Console\Kernel as ArtisanContract; |
12
|
|
|
|
13
|
|
|
class Artisan extends Command |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* The console command name. |
17
|
|
|
* |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $name = 'artisan'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* The console command description. |
24
|
|
|
* |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $description = 'Laravel Artisan'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* no support array. |
31
|
|
|
* |
32
|
|
|
* @var array |
33
|
|
|
*/ |
34
|
|
|
protected $notSupport = [ |
35
|
|
|
'down' => '', |
36
|
|
|
'tinker' => '', |
37
|
|
|
]; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* $artisan. |
41
|
|
|
* |
42
|
|
|
* @var \Illuminate\Contracts\Console\Kernel |
43
|
|
|
*/ |
44
|
|
|
protected $artisan; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* __construct. |
48
|
|
|
* |
49
|
|
|
* @param \Illuminate\Contracts\Console\Kernel $artisan |
50
|
|
|
*/ |
51
|
|
|
public function __construct(ArtisanContract $artisan) |
52
|
|
|
{ |
53
|
|
|
parent::__construct(); |
54
|
|
|
|
55
|
|
|
$this->artisan = $artisan; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* handle. |
60
|
|
|
* |
61
|
|
|
* @throws \InvalidArgumentException |
62
|
|
|
*/ |
63
|
|
|
public function handle() |
64
|
|
|
{ |
65
|
|
|
$command = $this->forceCommand($this->option('command')); |
66
|
|
|
|
67
|
|
|
$input = new StringInput($command); |
68
|
|
|
|
69
|
|
|
$input->setInteractive(false); |
70
|
|
|
|
71
|
|
|
if (isset($this->notSupport[$input->getFirstArgument()]) === true) { |
72
|
|
|
throw new InvalidArgumentException('Command "'.$command.'" is not supported'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$this->artisan->handle($input, $this->getOutput()); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* need focre option. |
80
|
|
|
* |
81
|
|
|
* @param string $command |
82
|
|
|
* |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
|
|
protected function forceCommand($command): string |
86
|
|
|
{ |
87
|
|
|
return ( |
88
|
|
|
starts_with($command, 'migrate') === true && starts_with($command, 'migrate:status') === false || |
|
|
|
|
89
|
|
|
starts_with($command, 'db:seed') === true |
|
|
|
|
90
|
|
|
) && mb_strpos('command', '--force') === false ? |
91
|
|
|
$command .= ' --force' : $command; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Get the console command options. |
96
|
|
|
* |
97
|
|
|
* @return array |
98
|
|
|
*/ |
99
|
|
|
protected function getOptions(): array |
100
|
|
|
{ |
101
|
|
|
return [ |
102
|
|
|
['command', null, InputOption::VALUE_OPTIONAL], |
103
|
|
|
]; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
This function has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.