1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MadWeb\Initializer; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use MadWeb\Initializer\Actions\Action; |
7
|
|
|
use MadWeb\Initializer\Actions\Artisan; |
8
|
|
|
use MadWeb\Initializer\Actions\Callback; |
9
|
|
|
use MadWeb\Initializer\Actions\Dispatch; |
10
|
|
|
use MadWeb\Initializer\Actions\External; |
11
|
|
|
use MadWeb\Initializer\Actions\Publish; |
12
|
|
|
use MadWeb\Initializer\Actions\PublishTag; |
13
|
|
|
use MadWeb\Initializer\Contracts\Runner as RunnerContract; |
14
|
|
|
|
15
|
|
|
class Run implements RunnerContract |
16
|
|
|
{ |
17
|
|
|
protected $artisanCommand; |
18
|
|
|
|
19
|
|
|
protected $options; |
20
|
|
|
|
21
|
|
|
private $errorMessages = []; |
22
|
|
|
|
23
|
210 |
|
public function __construct(Command $artisanCommand, $options) |
24
|
|
|
{ |
25
|
210 |
|
$this->artisanCommand = $artisanCommand; |
26
|
210 |
|
$this->options = $options; |
27
|
210 |
|
} |
28
|
|
|
|
29
|
198 |
|
public function errorMessages(): array |
30
|
|
|
{ |
31
|
198 |
|
return $this->errorMessages; |
32
|
|
|
} |
33
|
|
|
|
34
|
204 |
|
private function run(Action $action) |
35
|
|
|
{ |
36
|
204 |
|
$action(); |
37
|
|
|
|
38
|
192 |
|
if ($action->failed()) { |
39
|
12 |
|
$this->errorMessages[] = $action->errorMessage(); |
40
|
|
|
} |
41
|
|
|
|
42
|
192 |
|
return $this; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function doneWithErrors(): bool |
46
|
|
|
{ |
47
|
|
|
return ! empty($this->errorMessages); |
48
|
|
|
} |
49
|
|
|
|
50
|
18 |
|
public function artisan(string $command, array $arguments = []): RunnerContract |
51
|
|
|
{ |
52
|
18 |
|
return $this->run(new Artisan($this->artisanCommand, $command, $arguments)); |
53
|
|
|
} |
54
|
|
|
|
55
|
72 |
|
public function publish($providers, bool $force = false): RunnerContract |
56
|
|
|
{ |
57
|
72 |
|
return $this->run(new Publish($this->artisanCommand, $providers, $force)); |
58
|
|
|
} |
59
|
|
|
|
60
|
6 |
|
public function publishForce($providers): RunnerContract |
61
|
|
|
{ |
62
|
6 |
|
return $this->publish($providers, true); |
63
|
|
|
} |
64
|
|
|
|
65
|
24 |
|
public function publishTag($tag, bool $force = false): RunnerContract |
66
|
|
|
{ |
67
|
24 |
|
return $this->run(new PublishTag($this->artisanCommand, $tag, $force)); |
68
|
|
|
} |
69
|
|
|
|
70
|
12 |
|
public function publishTagForce($tag): RunnerContract |
71
|
|
|
{ |
72
|
12 |
|
return $this->publishTag($tag, true); |
73
|
|
|
} |
74
|
|
|
|
75
|
18 |
|
public function external(string $command, ...$arguments): RunnerContract |
76
|
|
|
{ |
77
|
18 |
|
return $this->run(new External($this->artisanCommand, $command, $arguments)); |
78
|
|
|
} |
79
|
|
|
|
80
|
12 |
|
public function callable(callable $function, ...$arguments): RunnerContract |
81
|
|
|
{ |
82
|
12 |
|
return $this->run(new Callback($this->artisanCommand, $function, $arguments)); |
83
|
|
|
} |
84
|
|
|
|
85
|
48 |
|
public function dispatch($job): RunnerContract |
86
|
|
|
{ |
87
|
48 |
|
return $this->run(new Dispatch($this->artisanCommand, $job)); |
88
|
|
|
} |
89
|
|
|
|
90
|
18 |
|
public function dispatchNow($job): RunnerContract |
91
|
|
|
{ |
92
|
18 |
|
return $this->run(new Dispatch($this->artisanCommand, $job, true)); |
93
|
|
|
} |
94
|
|
|
|
95
|
6 |
|
public function getOption(string $option): bool |
96
|
|
|
{ |
97
|
6 |
|
return in_array($option, $this->options); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|