|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use App\Exceptions\PorterNotSetUp; |
|
6
|
|
|
use App\Porter; |
|
7
|
|
|
use App\PorterLibrary; |
|
8
|
|
|
use App\Support\Console\Cli; |
|
9
|
|
|
use App\Support\Console\DockerCompose\CliCommandFactory; |
|
10
|
|
|
use LaravelZero\Framework\Commands\Command; |
|
11
|
|
|
use NunoMaduro\LaravelConsoleMenu\Menu; |
|
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @method Menu menu(string $title, array $options) |
|
17
|
|
|
*/ |
|
18
|
|
|
abstract class BaseCommand extends Command |
|
19
|
|
|
{ |
|
20
|
|
|
/** @var \App\Support\Console\Cli */ |
|
21
|
|
|
protected $cli; |
|
22
|
|
|
|
|
23
|
|
|
/** @var CliCommandFactory */ |
|
24
|
|
|
protected $dockerCompose; |
|
25
|
|
|
|
|
26
|
|
|
/** @var Porter */ |
|
27
|
|
|
protected $porter; |
|
28
|
|
|
|
|
29
|
|
|
/** @var PorterLibrary */ |
|
30
|
|
|
protected $porterLibrary; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* If true, the command will not run unless the setup process has been run. |
|
34
|
|
|
* |
|
35
|
|
|
* @var bool |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $porterMustBeSetUp = true; |
|
38
|
|
|
|
|
39
|
210 |
|
public function __construct( |
|
40
|
|
|
Cli $cli, |
|
41
|
|
|
CliCommandFactory $dockerCompose, |
|
42
|
|
|
Porter $porter, |
|
43
|
|
|
PorterLibrary $porterLibrary |
|
44
|
|
|
) { |
|
45
|
210 |
|
parent::__construct(); |
|
46
|
|
|
|
|
47
|
210 |
|
$this->cli = $cli; |
|
48
|
210 |
|
$this->dockerCompose = $dockerCompose; |
|
49
|
210 |
|
$this->porter = $porter; |
|
50
|
210 |
|
$this->porterLibrary = $porterLibrary; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Execute the console command. |
|
55
|
|
|
* |
|
56
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input |
|
57
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
|
58
|
|
|
* |
|
59
|
|
|
* @throws PorterNotSetUp |
|
60
|
|
|
* |
|
61
|
|
|
* @return mixed |
|
62
|
|
|
*/ |
|
63
|
45 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
64
|
|
|
{ |
|
65
|
45 |
|
$this->checkPorterIsSetUp(); |
|
66
|
|
|
|
|
67
|
44 |
|
return parent::execute($input, $output); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Ensure that Porter has been set up if necessary before continuing. |
|
72
|
|
|
* |
|
73
|
|
|
* @throws PorterNotSetUp |
|
74
|
|
|
*/ |
|
75
|
45 |
|
private function checkPorterIsSetUp() |
|
76
|
|
|
{ |
|
77
|
45 |
|
if ($this->porterMustBeSetUp && !$this->porterLibrary->alreadySetUp()) { |
|
78
|
1 |
|
throw new PorterNotSetUp('Porter must be set up to run this command. Run \'porter begin\' first.'); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|