1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* base command |
4
|
|
|
*/ |
5
|
|
|
namespace Graviton\Deployment\Command; |
6
|
|
|
|
7
|
|
|
use Graviton\Deployment\Configuration; |
8
|
|
|
use Graviton\Deployment\Deployment; |
9
|
|
|
use Graviton\Deployment\Steps\StepInterface; |
10
|
|
|
use Symfony\Component\Console\Command\Command; |
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
13
|
|
|
use Symfony\Component\Process\ProcessBuilder; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @author List of contributors <https://github.com/libgraviton/deploy-scripts/graphs/contributors> |
17
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
18
|
|
|
* @link http://swisscom.ch |
19
|
|
|
*/ |
20
|
|
|
abstract class AbstractCommand extends Command |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var array configuration settings for the application. |
24
|
|
|
*/ |
25
|
|
|
protected $configuration; |
26
|
|
|
|
27
|
|
|
/** @var StepInterface[] */ |
28
|
|
|
protected $steps; |
29
|
|
|
|
30
|
|
|
/** @var string */ |
31
|
|
|
protected $message; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Constructor. |
35
|
|
|
* |
36
|
|
|
* @param Configuration $configuration current application configuration loader. |
37
|
|
|
* @param string|null $name The name of the command; |
38
|
|
|
* passing null means it must be set in configure() |
39
|
|
|
* |
40
|
|
|
*/ |
41
|
6 |
|
public function __construct(Configuration $configuration, $name = null) |
42
|
|
|
{ |
43
|
6 |
|
parent::__construct($name); |
44
|
|
|
|
45
|
6 |
|
$this->configuration = $configuration->load(); |
46
|
6 |
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Executes the current command. |
50
|
|
|
* |
51
|
|
|
* @param InputInterface $input An InputInterface instance |
52
|
|
|
* @param OutputInterface $output Output of the command |
53
|
|
|
* |
54
|
|
|
* @return void |
55
|
|
|
*/ |
56
|
1 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
57
|
|
|
{ |
58
|
1 |
|
$output->writeln($this->getStartMessage()); |
59
|
|
|
|
60
|
1 |
|
$deployment = new Deployment(new ProcessBuilder()); |
61
|
1 |
|
$deployment->registerSteps($this->steps); |
62
|
|
|
|
63
|
1 |
|
$output->write($deployment->deploy()); |
64
|
1 |
|
$output->writeln('... done'); |
65
|
1 |
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Provides the previous defined message. |
69
|
|
|
* |
70
|
|
|
* @return string |
71
|
|
|
* |
72
|
|
|
* @throws \LogicException in case no message was set. |
73
|
|
|
*/ |
74
|
1 |
|
public function getStartMessage() |
75
|
|
|
{ |
76
|
1 |
|
if (empty($this->message)) { |
77
|
|
|
throw new \LogicException('The console message must not be empty!'); |
78
|
|
|
} |
79
|
|
|
|
80
|
1 |
|
return $this->message; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Set the content of the start message. |
85
|
|
|
* |
86
|
|
|
* @param string $message Start message. |
87
|
|
|
* |
88
|
|
|
* @return $this |
89
|
|
|
*/ |
90
|
1 |
|
public function setStartMessage($message) |
91
|
|
|
{ |
92
|
1 |
|
$this->message = $message; |
93
|
|
|
|
94
|
1 |
|
return $this; |
95
|
1 |
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Provides the defined |
99
|
|
|
* |
100
|
|
|
* @return StepInterface[] |
101
|
|
|
* |
102
|
|
|
* @throws \LogicException in case no step was set. |
103
|
|
|
*/ |
104
|
|
|
public function getStep() |
105
|
|
|
{ |
106
|
|
|
if (empty($this->steps)) { |
107
|
|
|
throw new \LogicException('The command step must not be empty!'); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
return $this->steps; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Adds a step to the set of steps to be executed. |
115
|
|
|
* |
116
|
|
|
* @param StepInterface $step Step to be executed |
117
|
|
|
* |
118
|
|
|
* @return $this |
119
|
|
|
*/ |
120
|
1 |
|
public function addStep(StepInterface $step) |
121
|
|
|
{ |
122
|
1 |
|
$this->steps[] = $step; |
123
|
|
|
|
124
|
1 |
|
return $this; |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|