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>Running external command:</comment> $this->command $argString"; |
29
|
|
|
} |
30
|
|
|
|
31
|
18 |
|
public function run(): bool |
32
|
|
|
{ |
33
|
18 |
|
$Process = new Process(empty($this->arguments) |
|
|
|
|
34
|
12 |
|
? $this->command |
35
|
18 |
|
: array_merge([$this->command], $this->arguments)); |
36
|
18 |
|
$Process->setTimeout(null); |
37
|
|
|
|
38
|
18 |
|
$isVerbose = $this->artisanCommand->getOutput()->isVerbose(); |
|
|
|
|
39
|
|
|
|
40
|
18 |
|
if ($isVerbose) { |
41
|
|
|
$this->artisanCommand->getOutput()->newLine(); |
|
|
|
|
42
|
|
|
if (Process::isTtySupported()) { |
43
|
|
|
$Process->setTty(true); |
44
|
|
|
} elseif (Process::isPtySupported()) { |
45
|
|
|
$Process->setPty(true); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$Process->run($isVerbose ? function ($type, $buffer) { |
50
|
|
|
if (Process::ERR === $type) { |
51
|
|
|
$this->artisanCommand->error($buffer); |
|
|
|
|
52
|
|
|
} else { |
53
|
|
|
$this->artisanCommand->line($buffer); |
|
|
|
|
54
|
|
|
} |
55
|
18 |
|
} : null); |
56
|
|
|
|
57
|
18 |
|
$error = $Process->getErrorOutput(); |
58
|
18 |
|
$exitCode = $Process->getExitCode(); |
59
|
|
|
|
60
|
18 |
|
if ($error and $exitCode > 0) { |
61
|
6 |
|
throw new RuntimeException(trim($error)); |
62
|
|
|
} |
63
|
|
|
|
64
|
12 |
|
return ! $exitCode; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
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.