1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Conveyor package. |
5
|
|
|
* |
6
|
|
|
* (c) Jeroen Fiege <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Webcreate\Conveyor\Console; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Console\Application as BaseApplication; |
15
|
|
|
use Symfony\Component\Console\Input\ArgvInput; |
16
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
17
|
|
|
use Symfony\Component\Console\Input\InputOption; |
18
|
|
|
use Symfony\Component\Console\Output\ConsoleOutput; |
19
|
|
|
use Symfony\Component\Console\Output\ConsoleOutputInterface; |
20
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
21
|
|
|
use Webcreate\Conveyor\Conveyor; |
22
|
|
|
use Webcreate\Conveyor\IO\ConsoleIO; |
23
|
|
|
|
24
|
|
|
class Application extends BaseApplication |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var Conveyor |
28
|
|
|
*/ |
29
|
|
|
protected $conveyor; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var bool |
33
|
|
|
*/ |
34
|
|
|
protected $originalAutoExit; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param Conveyor $conveyor |
38
|
|
|
*/ |
39
|
2 |
|
public function __construct(Conveyor $conveyor) |
40
|
|
|
{ |
41
|
2 |
|
$this->conveyor = $conveyor; |
42
|
|
|
|
43
|
2 |
|
if (function_exists('date_default_timezone_set') && function_exists('date_default_timezone_get')) { |
44
|
2 |
|
date_default_timezone_set(@date_default_timezone_get()); |
45
|
|
|
} |
46
|
|
|
|
47
|
2 |
|
parent::__construct(); |
48
|
2 |
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return Conveyor |
52
|
|
|
*/ |
53
|
2 |
|
public function getConveyor() |
54
|
|
|
{ |
55
|
2 |
|
return $this->conveyor; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @inheritdoc |
60
|
|
|
*/ |
61
|
2 |
|
protected function getDefaultCommands() |
62
|
|
|
{ |
63
|
2 |
|
$commands = parent::getDefaultCommands(); |
64
|
2 |
|
$commands[] = new \Webcreate\Conveyor\Command\VersionsCommand(); |
65
|
2 |
|
$commands[] = new \Webcreate\Conveyor\Command\BuildCommand(); |
66
|
2 |
|
$commands[] = new \Webcreate\Conveyor\Command\SimulateCommand(); |
67
|
2 |
|
$commands[] = new \Webcreate\Conveyor\Command\DeployCommand(); |
68
|
2 |
|
$commands[] = new \Webcreate\Conveyor\Command\UndeployCommand(); |
69
|
2 |
|
$commands[] = new \Webcreate\Conveyor\Command\DiffCommand(); |
70
|
2 |
|
$commands[] = new \Webcreate\Conveyor\Command\InitCommand(); |
71
|
2 |
|
$commands[] = new \Webcreate\Conveyor\Command\ValidateCommand(); |
72
|
2 |
|
$commands[] = new \Webcreate\Conveyor\Command\StatusCommand(); |
73
|
|
|
|
74
|
2 |
|
if ('phar:' === substr(__FILE__, 0, 5)) { |
75
|
|
|
$commands[] = new \Webcreate\Conveyor\Command\UpdateCommand(); |
76
|
|
|
} |
77
|
|
|
|
78
|
2 |
|
return $commands; |
|
|
|
|
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @inheritdoc |
83
|
|
|
*/ |
84
|
2 |
|
protected function getDefaultInputDefinition() |
85
|
|
|
{ |
86
|
2 |
|
$inputDefinition = parent::getDefaultInputDefinition(); |
87
|
2 |
|
$inputDefinition->addOption( |
88
|
2 |
|
new InputOption('--configuration', '-c', InputOption::VALUE_REQUIRED, 'Configuration file override') |
89
|
|
|
); |
90
|
|
|
|
91
|
2 |
|
return $inputDefinition; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @inheritdoc |
96
|
|
|
*/ |
97
|
|
|
public function getName() |
98
|
|
|
{ |
99
|
|
|
return 'Conveyor'; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @inheritdoc |
104
|
|
|
*/ |
105
|
|
|
public function getVersion() |
106
|
|
|
{ |
107
|
|
|
$versionFilename = 'VERSION'; |
108
|
|
|
|
109
|
|
|
if ('phar:' === substr(__FILE__, 0, 5)) { |
110
|
|
|
$versionFile = 'phar://conveyor.phar/' . $versionFilename; |
111
|
|
|
} else { |
112
|
|
|
$versionFile = __DIR__ . '/../../../../' . $versionFilename; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
return trim(file_get_contents($versionFile)); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @inheritdoc |
120
|
|
|
*/ |
121
|
|
|
public function run(InputInterface $input = null, OutputInterface $output = null) |
|
|
|
|
122
|
|
|
{ |
123
|
|
|
$this->setCatchExceptions(false); |
124
|
|
|
|
125
|
|
|
if (null === $input) { |
126
|
|
|
$input = new ArgvInput(); |
|
|
|
|
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
if (null === $output) { |
130
|
|
|
$output = new ConsoleOutput(); |
|
|
|
|
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
try { |
134
|
|
|
$statusCode = parent::run($input, $output); |
135
|
|
|
} catch (\Exception $e) { |
136
|
|
|
$container = $this->getConveyor()->getContainer(); |
137
|
|
|
|
138
|
|
|
if (null !== $container) { |
139
|
|
|
/** @var $logger \Monolog\Logger */ |
140
|
|
|
$logger = $this->getConveyor()->getContainer()->get('logger'); |
141
|
|
|
|
142
|
|
|
$message = sprintf( |
143
|
|
|
'%s: %s (uncaught exception) at %s line %s while running console command `%s`', |
144
|
|
|
get_class($e), |
145
|
|
|
$e->getMessage(), |
146
|
|
|
$e->getFile(), |
147
|
|
|
$e->getLine(), |
148
|
|
|
$this->getCommandName($input) |
149
|
|
|
); |
150
|
|
|
$logger->addCritical($message); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
if ($output instanceof ConsoleOutputInterface) { |
154
|
|
|
$this->renderException($e, $output->getErrorOutput()); |
155
|
|
|
} else { |
156
|
|
|
$this->renderException($e, $output); |
157
|
|
|
} |
158
|
|
|
$statusCode = $e->getCode(); |
159
|
|
|
|
160
|
|
|
$statusCode = is_numeric($statusCode) && $statusCode ? $statusCode : 1; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
if ($this->originalAutoExit) { |
164
|
|
|
if ($statusCode > 255) { |
165
|
|
|
$statusCode = 255; |
166
|
|
|
} |
167
|
|
|
// @codeCoverageIgnoreStart |
168
|
|
|
exit($statusCode); |
|
|
|
|
169
|
|
|
// @codeCoverageIgnoreEnd |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
return $statusCode; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @inheritdoc |
177
|
|
|
*/ |
178
|
|
|
public function doRun(InputInterface $input, OutputInterface $output) |
179
|
|
|
{ |
180
|
|
|
$io = new ConsoleIO($input, $output, $this->getHelperSet()); |
|
|
|
|
181
|
|
|
$conveyor = $this->getConveyor(); |
182
|
|
|
|
183
|
|
|
// retrieve the config file option really early so we can still make changes before the di container |
184
|
|
|
// gets compiled |
185
|
|
|
$configFile = $input->getParameterOption(array('--configuration', '-c')); |
186
|
|
|
if ($configFile) { |
187
|
|
|
$conveyor->setConfigFile($configFile); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
$conveyor->boot($io); |
191
|
|
|
|
192
|
|
|
parent::doRun($input, $output); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @inheritdoc |
197
|
|
|
*/ |
198
|
|
|
public function setAutoExit($bool) |
199
|
|
|
{ |
200
|
|
|
// parent property is private, so we need to intercept it in a setter |
201
|
|
|
$this->originalAutoExit = (bool) $bool; |
202
|
|
|
|
203
|
|
|
parent::setAutoExit($bool); |
204
|
|
|
} |
205
|
|
|
} |
206
|
|
|
|