/
ApacheModuleEnableCommand.php
87 lines (70 loc) · 2.22 KB
/
ApacheModuleEnableCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
namespace Droid\Plugin\Apache\Command;
use RuntimeException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Droid\Lib\Plugin\Command\CheckableTrait;
class ApacheModuleEnableCommand extends AbstractApacheCommand
{
use CheckableTrait;
protected $enabledDir = 'mods-enabled';
protected $availableDir = 'mods-available';
public function configure()
{
$this
->setName('apache:enmod')
->setDescription('Enable Apache modules.')
->addArgument(
'module-name',
InputArgument::REQUIRED,
'Enable the named module.'
)
;
$this->configureCheckMode();
}
public function execute(InputInterface $input, OutputInterface $output)
{
$this->activateCheckMode($input);
$confname = $this->getConfName($input->getArgument('module-name'));
$confFilename = $this->getConfFilename($input->getArgument('module-name'));
if (! $this->available($confFilename)) {
throw new RuntimeException(
sprintf('I am not aware of a module named "%s".', $confname)
);
}
if ($this->enabled($confFilename)) {
$output->writeLn(
sprintf(
'The module "%s" is already enabled. Nothing to do.',
$confname
)
);
$this->reportChange($output);
return 0;
}
$this->markChange();
if (! $this->checkMode() && ! $this->enable($confFilename)) {
throw new RuntimeException(
sprintf('I cannot enable module "%s".', $confname)
);
}
$output->writeLn(
sprintf(
'I %s "%s".',
$this->checkMode() ? 'would enable' : 'have enabled',
$confname
)
);
$this->reportChange($output);
return 0;
}
protected function getAvailableDir()
{
return $this->availableDir;
}
protected function getEnabledDir()
{
return $this->enabledDir;
}
}