1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MadWeb\Initializer\Actions; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use RuntimeException; |
7
|
|
|
use Symfony\Component\Process\Process; |
8
|
|
|
|
9
|
|
|
class External extends Action |
10
|
|
|
{ |
11
|
|
|
private $command; |
12
|
|
|
|
13
|
|
|
private $arguments; |
14
|
|
|
|
15
|
18 |
|
public function __construct(Command $artisanCommand, string $command, array $arguments = []) |
16
|
|
|
{ |
17
|
18 |
|
parent::__construct($artisanCommand); |
18
|
|
|
|
19
|
18 |
|
$this->artisanCommand = $artisanCommand; |
|
|
|
|
20
|
18 |
|
$this->command = $command; |
21
|
18 |
|
$this->arguments = $arguments; |
22
|
18 |
|
} |
23
|
|
|
|
24
|
18 |
|
public function title(): string |
25
|
|
|
{ |
26
|
18 |
|
$argString = implode(' ', $this->arguments); |
27
|
|
|
|
28
|
18 |
|
return "<comment>Run external command:</comment> $this->command $argString"; |
29
|
|
|
} |
30
|
|
|
|
31
|
18 |
|
public function run(): bool |
32
|
|
|
{ |
33
|
18 |
|
$Process = $this->createProcess(); |
34
|
18 |
|
$Process->setTimeout(null); |
35
|
|
|
|
36
|
18 |
|
$isVerbose = $this->artisanCommand->getOutput()->isVerbose(); |
|
|
|
|
37
|
|
|
|
38
|
18 |
|
if ($isVerbose) { |
39
|
|
|
$this->artisanCommand->getOutput()->newLine(); |
|
|
|
|
40
|
|
|
if (Process::isTtySupported()) { |
41
|
|
|
$Process->setTty(true); |
42
|
|
|
} elseif (Process::isPtySupported()) { |
43
|
|
|
$Process->setPty(true); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$Process->run($isVerbose ? function ($type, $buffer) { |
48
|
|
|
if (Process::ERR === $type) { |
49
|
|
|
$this->artisanCommand->error($buffer); |
|
|
|
|
50
|
|
|
} else { |
51
|
|
|
$this->artisanCommand->line($buffer); |
|
|
|
|
52
|
|
|
} |
53
|
18 |
|
} : null); |
54
|
|
|
|
55
|
18 |
|
$error = $Process->getErrorOutput(); |
56
|
18 |
|
$exitCode = $Process->getExitCode(); |
57
|
|
|
|
58
|
18 |
|
if ($error and $exitCode > 0) { |
59
|
6 |
|
throw new RuntimeException(trim($error)); |
60
|
|
|
} |
61
|
|
|
|
62
|
12 |
|
return ! $exitCode; |
63
|
|
|
} |
64
|
|
|
|
65
|
18 |
|
private function createProcess(): Process |
66
|
|
|
{ |
67
|
18 |
|
if (empty($this->arguments)) { |
68
|
12 |
|
return Process::fromShellCommandline($this->command); |
69
|
|
|
} |
70
|
|
|
|
71
|
6 |
|
return new Process(array_merge([$this->command], $this->arguments)); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.