Skip to content

Commit

Permalink
Detect modules by the .load config extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
boite committed Nov 12, 2016
1 parent 47da5b9 commit ce4113f
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 38 deletions.
8 changes: 4 additions & 4 deletions src/Command/AbstractApacheCommand.php
Expand Up @@ -28,14 +28,14 @@ public function __construct(
abstract protected function getEnabledDir();
abstract protected function getAvailableDir();

protected function getConfName($argument)
protected function getConfName($argument, $extension = '.conf')
{
return $this->normaliser->normaliseConfName($argument);
return $this->normaliser->normaliseConfName($argument, $extension);
}

protected function getConfFilename($argument)
protected function getConfFilename($argument, $extension = '.conf')
{
return $this->normaliser->normaliseConfFilename($argument);
return $this->normaliser->normaliseConfFilename($argument, $extension);
}

protected function available($confFilename)
Expand Down
4 changes: 2 additions & 2 deletions src/Command/ApacheModuleDisableCommand.php
Expand Up @@ -35,8 +35,8 @@ public function execute(InputInterface $input, OutputInterface $output)
{
$this->activateCheckMode($input);

$confname = $this->getConfName($input->getArgument('module-name'));
$confFilename = $this->getConfFilename($input->getArgument('module-name'));
$confname = $this->getConfName($input->getArgument('module-name'), '.load');
$confFilename = $this->getConfFilename($input->getArgument('module-name'), '.load');

if (! $this->available($confFilename)) {
throw new RuntimeException(
Expand Down
4 changes: 2 additions & 2 deletions src/Command/ApacheModuleEnableCommand.php
Expand Up @@ -35,8 +35,8 @@ public function execute(InputInterface $input, OutputInterface $output)
{
$this->activateCheckMode($input);

$confname = $this->getConfName($input->getArgument('module-name'));
$confFilename = $this->getConfFilename($input->getArgument('module-name'));
$confname = $this->getConfName($input->getArgument('module-name'), '.load');
$confFilename = $this->getConfFilename($input->getArgument('module-name'), '.load');

if (! $this->available($confFilename)) {
throw new RuntimeException(
Expand Down
14 changes: 8 additions & 6 deletions src/Util/Normaliser.php
Expand Up @@ -4,18 +4,20 @@

class Normaliser
{
public function normaliseConfName($confName)
public function normaliseConfName($confName, $extension = '.conf')
{
if (substr($confName, -5, 5) === '.conf') {
return substr($confName, 0, -5);
$ext_len = strlen($extension);
if (substr($confName, 0-$ext_len, $ext_len) === $extension) {
return substr($confName, 0, 0-$ext_len);
}
return $confName;
}

public function normaliseConfFilename($confName)
public function normaliseConfFilename($confName, $extension = '.conf')
{
if (substr($confName, -5, 5) != '.conf') {
return $confName . '.conf';
$ext_len = strlen($extension);
if (substr($confName, 0-$ext_len, $ext_len) != $extension) {
return $confName . $extension;
}
return $confName;
}
Expand Down
22 changes: 11 additions & 11 deletions test/Command/ApacheModuleDisableCommandTest.php
Expand Up @@ -74,7 +74,7 @@ public function testApacheModDisableThrowsRuntimeExceptionWithUnknownModule()
'stat',
'-c',
'%F',
'/etc/apache2/mods-available/not_a_module.conf',
'/etc/apache2/mods-available/not_a_module.load',
)
)
;
Expand Down Expand Up @@ -108,13 +108,13 @@ public function testApacheModDisableExitsWhenModuleIsAlreadyDisabled()
'stat',
'-c',
'%F',
'/etc/apache2/mods-available/a_module.conf',
'/etc/apache2/mods-available/a_module.load',
)),
array(array(
'stat',
'-c',
'%F',
'/etc/apache2/mods-enabled/a_module.conf',
'/etc/apache2/mods-enabled/a_module.load',
))
)
;
Expand Down Expand Up @@ -164,17 +164,17 @@ public function testApacheModDisableThrowsRuntimeExceptionWhenFailsToDisable()
'stat',
'-c',
'%F',
'/etc/apache2/mods-available/a_module.conf',
'/etc/apache2/mods-available/a_module.load',
)),
array(array(
'stat',
'-c',
'%F',
'/etc/apache2/mods-enabled/a_module.conf',
'/etc/apache2/mods-enabled/a_module.load',
)),
array(array(
'unlink',
'/etc/apache2/mods-enabled/a_module.conf',
'/etc/apache2/mods-enabled/a_module.load',
))
)
;
Expand Down Expand Up @@ -214,17 +214,17 @@ public function testApacheModDisableWillDisableEnabledModule()
'stat',
'-c',
'%F',
'/etc/apache2/mods-available/a_module.conf',
'/etc/apache2/mods-available/a_module.load',
)),
array(array(
'stat',
'-c',
'%F',
'/etc/apache2/mods-enabled/a_module.conf',
'/etc/apache2/mods-enabled/a_module.load',
)),
array(array(
'unlink',
'/etc/apache2/mods-enabled/a_module.conf',
'/etc/apache2/mods-enabled/a_module.load',
))
)
;
Expand Down Expand Up @@ -270,13 +270,13 @@ public function testApacheModDisableWillReportOnlyInCheckMode()
'stat',
'-c',
'%F',
'/etc/apache2/mods-available/a_module.conf'
'/etc/apache2/mods-available/a_module.load'
)),
array(array(
'stat',
'-c',
'%F',
'/etc/apache2/mods-enabled/a_module.conf'
'/etc/apache2/mods-enabled/a_module.load'
))
)
;
Expand Down
26 changes: 13 additions & 13 deletions test/Command/ApacheModuleEnableCommandTest.php
Expand Up @@ -74,7 +74,7 @@ public function testApacheModEnableThrowsRuntimeExceptionWithUnknownModule()
'stat',
'-c',
'%F',
'/etc/apache2/mods-available/not_a_module.conf'
'/etc/apache2/mods-available/not_a_module.load'
)
)
;
Expand Down Expand Up @@ -108,13 +108,13 @@ public function testApacheModEnableExitsWhenModuleIsAlreadyEnabled()
'stat',
'-c',
'%F',
'/etc/apache2/mods-available/a_module.conf',
'/etc/apache2/mods-available/a_module.load',
)),
array(array(
'stat',
'-c',
'%F',
'/etc/apache2/mods-enabled/a_module.conf',
'/etc/apache2/mods-enabled/a_module.load',
))
)
;
Expand Down Expand Up @@ -164,19 +164,19 @@ public function testApacheModEnableThrowsRuntimeExceptionWhenFailsToEnable()
'stat',
'-c',
'%F',
'/etc/apache2/mods-available/a_module.conf',
'/etc/apache2/mods-available/a_module.load',
)),
array(array(
'stat',
'-c',
'%F',
'/etc/apache2/mods-enabled/a_module.conf',
'/etc/apache2/mods-enabled/a_module.load',
)),
array(array(
'ln',
'-s',
'/etc/apache2/mods-available/a_module.conf',
'/etc/apache2/mods-enabled/a_module.conf',
'/etc/apache2/mods-available/a_module.load',
'/etc/apache2/mods-enabled/a_module.load',
))
)
;
Expand Down Expand Up @@ -216,19 +216,19 @@ public function testApacheModEnableWillEnableDisabledModule()
'stat',
'-c',
'%F',
'/etc/apache2/mods-available/a_module.conf',
'/etc/apache2/mods-available/a_module.load',
)),
array(array(
'stat',
'-c',
'%F',
'/etc/apache2/mods-enabled/a_module.conf',
'/etc/apache2/mods-enabled/a_module.load',
)),
array(array(
'ln',
'-s',
'/etc/apache2/mods-available/a_module.conf',
'/etc/apache2/mods-enabled/a_module.conf',
'/etc/apache2/mods-available/a_module.load',
'/etc/apache2/mods-enabled/a_module.load',
))
)
;
Expand Down Expand Up @@ -274,13 +274,13 @@ public function testApacheModEnableWillReportOnlyInCheckMode()
'stat',
'-c',
'%F',
'/etc/apache2/mods-available/a_module.conf',
'/etc/apache2/mods-available/a_module.load',
)),
array(array(
'stat',
'-c',
'%F',
'/etc/apache2/mods-enabled/a_module.conf',
'/etc/apache2/mods-enabled/a_module.load',
))
)
;
Expand Down
12 changes: 12 additions & 0 deletions test/Util/NormaliserTest.php
Expand Up @@ -19,6 +19,10 @@ public function testNormaliseConfNameStripsExtension()
'foo_module',
$this->norm->normaliseConfName('foo_module.conf')
);
$this->assertSame(
'foo_module',
$this->norm->normaliseConfName('foo_module.extension', '.extension')
);
$this->assertSame(
'foo_module',
$this->norm->normaliseConfName('foo_module')
Expand All @@ -31,9 +35,17 @@ public function testNormaliseConfFilenameAddsExtension()
'foo_module.conf',
$this->norm->normaliseConfFilename('foo_module')
);
$this->assertSame(
'foo_module.extension',
$this->norm->normaliseConfFilename('foo_module', '.extension')
);
$this->assertSame(
'foo_module.conf',
$this->norm->normaliseConfFilename('foo_module.conf')
);
$this->assertSame(
'foo_module.extension',
$this->norm->normaliseConfFilename('foo_module.extension', '.extension')
);
}
}

0 comments on commit ce4113f

Please sign in to comment.