|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Recca0120\Terminal; |
|
4
|
|
|
|
|
5
|
|
|
use Exception; |
|
6
|
|
|
use Illuminate\Console\Application as ConsoleApplication; |
|
7
|
|
|
use Illuminate\Http\Request; |
|
8
|
|
|
use Recca0120\Terminal\Contracts\TerminalCommand; |
|
9
|
|
|
use Symfony\Component\Console\Formatter\OutputFormatter; |
|
10
|
|
|
use Symfony\Component\Console\Input\StringInput; |
|
11
|
|
|
use Symfony\Component\Console\Output\BufferedOutput; |
|
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
13
|
|
|
|
|
14
|
|
|
class Application extends ConsoleApplication |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* Run an Artisan console command by name. |
|
18
|
|
|
* |
|
19
|
|
|
* @param string $command |
|
20
|
|
|
* @param array $parameters |
|
21
|
|
|
* @param OutputInterface $outputBuffer |
|
22
|
2 |
|
* @return int |
|
23
|
|
|
* @throws Exception |
|
24
|
2 |
|
*/ |
|
25
|
1 |
|
public function call($command, array $parameters = [], $outputBuffer = null) |
|
26
|
1 |
|
{ |
|
27
|
|
|
if ($this->ajax() === true) { |
|
28
|
1 |
|
$this->lastOutput = $outputBuffer ?: new BufferedOutput(BufferedOutput::VERBOSITY_NORMAL, true, new OutputFormatter(true)); |
|
|
|
|
|
|
29
|
1 |
|
$this->setCatchExceptions(true); |
|
30
|
|
|
} else { |
|
31
|
|
|
$this->lastOutput = $outputBuffer ?: new BufferedOutput(); |
|
|
|
|
|
|
32
|
2 |
|
$this->setCatchExceptions(false); |
|
33
|
2 |
|
} |
|
34
|
2 |
|
|
|
35
|
|
|
$command .= ' '.implode(' ', $parameters); |
|
36
|
2 |
|
$input = new StringInput($command); |
|
37
|
|
|
$input->setInteractive(false); |
|
38
|
2 |
|
$result = $this->run($input, $this->lastOutput); |
|
39
|
|
|
$this->setCatchExceptions(true); |
|
40
|
2 |
|
|
|
41
|
|
|
return $result; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Resolve an array of commands through the application. |
|
46
|
|
|
* |
|
47
|
|
|
* @param array|mixed $commands |
|
48
|
|
|
* @return $this |
|
49
|
2 |
|
*/ |
|
50
|
|
|
public function resolveCommands($commands) |
|
51
|
2 |
|
{ |
|
52
|
1 |
|
return parent::resolveCommands(array_filter($commands, static function ($command) { |
|
53
|
2 |
|
return is_subclass_of($command, TerminalCommand::class); |
|
54
|
|
|
})); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* ajax. |
|
59
|
|
|
* |
|
60
|
|
|
* @return bool |
|
61
|
2 |
|
*/ |
|
62
|
|
|
private function ajax() |
|
63
|
2 |
|
{ |
|
64
|
|
|
$request = $this->laravel['request'] ?: Request::capture(); |
|
65
|
2 |
|
|
|
66
|
|
|
return $request->ajax(); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.