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\Contracts\Runner as RunnerContract; |
13
|
|
|
|
14
|
|
|
class Run implements RunnerContract |
15
|
|
|
{ |
16
|
|
|
protected $artisanCommand; |
17
|
|
|
|
18
|
|
|
private $errorMessages = []; |
19
|
|
|
|
20
|
174 |
|
public function __construct(Command $artisanCommand) |
21
|
|
|
{ |
22
|
174 |
|
$this->artisanCommand = $artisanCommand; |
23
|
174 |
|
} |
24
|
|
|
|
25
|
168 |
|
public function errorMessages(): array |
26
|
|
|
{ |
27
|
168 |
|
return $this->errorMessages; |
28
|
|
|
} |
29
|
|
|
|
30
|
174 |
|
private function run(Action $action) |
31
|
|
|
{ |
32
|
174 |
|
$action(); |
33
|
|
|
|
34
|
168 |
|
if ($action->failed()) { |
35
|
12 |
|
$this->errorMessages[] = $action->errorMessage(); |
36
|
|
|
} |
37
|
|
|
|
38
|
168 |
|
return $this; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function doneWithErrors(): bool |
42
|
|
|
{ |
43
|
|
|
return ! empty($this->errorMessages); |
44
|
|
|
} |
45
|
|
|
|
46
|
18 |
|
public function artisan(string $command, array $arguments = []): RunnerContract |
47
|
|
|
{ |
48
|
18 |
|
return $this->run(new Artisan($this->artisanCommand, $command, $arguments)); |
49
|
|
|
} |
50
|
|
|
|
51
|
66 |
|
public function publish($providers, bool $force = false): RunnerContract |
52
|
|
|
{ |
53
|
66 |
|
return $this->run(new Publish($this->artisanCommand, $providers, $force)); |
54
|
|
|
} |
55
|
|
|
|
56
|
6 |
|
public function publishForce($providers): RunnerContract |
57
|
|
|
{ |
58
|
6 |
|
return $this->publish($providers, true); |
59
|
|
|
} |
60
|
|
|
|
61
|
18 |
|
public function external(string $command, ...$arguments): RunnerContract |
62
|
|
|
{ |
63
|
18 |
|
return $this->run(new External($this->artisanCommand, $command, $arguments)); |
64
|
|
|
} |
65
|
|
|
|
66
|
12 |
|
public function callable(callable $function, ...$arguments): RunnerContract |
67
|
|
|
{ |
68
|
12 |
|
return $this->run(new Callback($this->artisanCommand, $function, $arguments)); |
69
|
|
|
} |
70
|
|
|
|
71
|
48 |
|
public function dispatch($job): RunnerContract |
72
|
|
|
{ |
73
|
48 |
|
return $this->run(new Dispatch($this->artisanCommand, $job)); |
74
|
|
|
} |
75
|
|
|
|
76
|
18 |
|
public function dispatchNow($job): RunnerContract |
77
|
|
|
{ |
78
|
18 |
|
return $this->run(new Dispatch($this->artisanCommand, $job, true)); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|