1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Cortex\Console\Services; |
6
|
|
|
|
7
|
|
|
use Illuminate\Http\Request; |
8
|
|
|
use Cortex\Console\Console\Commands\Artisan; |
9
|
|
|
use Symfony\Component\Console\Input\StringInput; |
10
|
|
|
use Symfony\Component\Console\Output\BufferedOutput; |
11
|
|
|
use Symfony\Component\Console\Formatter\OutputFormatter; |
12
|
|
|
use Illuminate\Console\Application as ConsoleApplication; |
13
|
|
|
|
14
|
|
|
class Terminal extends ConsoleApplication |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Resolve an array of commands through the application. |
18
|
|
|
* |
19
|
|
|
* @param array|mixed $commands |
20
|
|
|
* |
21
|
|
|
* @return static|\Illuminate\Console\Application |
|
|
|
|
22
|
|
|
*/ |
23
|
|
|
public function resolveCommands($commands) |
24
|
|
|
{ |
25
|
|
|
return in_array(Artisan::class, $commands) ? parent::resolveCommands($commands) : $this; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Run an Artisan console command by name. |
30
|
|
|
* |
31
|
|
|
* @param string $command |
32
|
|
|
* @param array $parameters |
33
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $outputBuffer |
|
|
|
|
34
|
|
|
* |
35
|
|
|
* @throws \Exception |
36
|
|
|
* |
37
|
|
|
* @return int |
38
|
|
|
*/ |
39
|
|
|
public function call($command, array $parameters = [], $outputBuffer = null): int |
40
|
|
|
{ |
41
|
|
|
$class = $outputBuffer ?: new BufferedOutput(); |
42
|
|
|
|
43
|
|
|
if ($this->request()->ajax() === true) { |
44
|
|
|
$this->lastOutput = new $class(BufferedOutput::VERBOSITY_NORMAL, true, new OutputFormatter(true)); |
45
|
|
|
$this->setCatchExceptions(true); |
46
|
|
|
} else { |
47
|
|
|
$this->lastOutput = new $class(); |
48
|
|
|
$this->setCatchExceptions(false); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$parameters = collect($parameters)->prepend($command); |
52
|
|
|
$input = new StringInput($parameters->implode(' ')); |
53
|
|
|
|
54
|
|
|
$input->setInteractive(false); |
55
|
|
|
|
56
|
|
|
$result = $this->run($input, $this->lastOutput); |
57
|
|
|
|
58
|
|
|
$this->setCatchExceptions(true); |
59
|
|
|
|
60
|
|
|
return $result; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Request. |
65
|
|
|
* |
66
|
|
|
* @return \Illuminate\Http\Request |
67
|
|
|
*/ |
68
|
|
|
protected function request() |
69
|
|
|
{ |
70
|
|
|
return $this->laravel['request'] ?: Request::capture(); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.