|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Deployee\Plugins\Install\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Deployee\Components\Config\ConfigInterface; |
|
6
|
|
|
use Deployee\Components\Environment\EnvironmentInterface; |
|
7
|
|
|
use Deployee\Plugins\Install\Events\RunInstallCommandEvent; |
|
8
|
|
|
use Symfony\Component\Console\Command\Command; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
11
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher; |
|
12
|
|
|
|
|
13
|
|
|
class InstallCommand extends Command |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var EnvironmentInterface |
|
17
|
|
|
*/ |
|
18
|
|
|
private $env; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var ConfigInterface |
|
22
|
|
|
*/ |
|
23
|
|
|
private $config; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var EventDispatcher |
|
27
|
|
|
*/ |
|
28
|
|
|
private $eventDispatcher; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param EnvironmentInterface $env |
|
32
|
|
|
*/ |
|
33
|
|
|
public function setEnv(EnvironmentInterface $env) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->env = $env; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param ConfigInterface $config |
|
40
|
|
|
*/ |
|
41
|
|
|
public function setConfig(ConfigInterface $config) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->config = $config; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param EventDispatcher $eventDispatcher |
|
48
|
|
|
*/ |
|
49
|
|
|
public function setEventDispatcher(EventDispatcher $eventDispatcher) |
|
50
|
|
|
{ |
|
51
|
|
|
$this->eventDispatcher = $eventDispatcher; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @inheritdoc |
|
56
|
|
|
*/ |
|
57
|
|
|
public function configure() |
|
58
|
|
|
{ |
|
59
|
|
|
parent::configure(); |
|
60
|
|
|
$this->setName('install'); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param InputInterface $input |
|
65
|
|
|
* @param OutputInterface $output |
|
66
|
|
|
*/ |
|
67
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
68
|
|
|
{ |
|
69
|
|
|
$output->writeln('Running install'); |
|
70
|
|
|
|
|
71
|
|
|
$path = $this->config->get('deploy_definition_path', 'definitions'); |
|
72
|
|
|
$path = strpos($path, '/') !== 0 && strpos($path, ':') !== 1 |
|
73
|
|
|
? $this->env->getWorkDir() . DIRECTORY_SEPARATOR . $path |
|
74
|
|
|
: $path; |
|
75
|
|
|
|
|
76
|
|
|
if(!is_dir($path)){ |
|
77
|
|
|
$output->writeln(sprintf('Directory %s does not exist', $path)); |
|
78
|
|
|
exit(255); |
|
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
$this->eventDispatcher->dispatch(RunInstallCommandEvent::class, new RunInstallCommandEvent()); |
|
82
|
|
|
|
|
83
|
|
|
$output->writeln('Finished installing'); |
|
84
|
|
|
} |
|
85
|
|
|
} |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.