Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow namespaced and autoloaded custom actions #94

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Liip/RMT/Config/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function __construct($rawConfig = null, $projectRoot = null)
public function getDefaultConfig()
{
return array(
"bootstrap" => null,
"vcs" => null,
"prerequisites" => array(),
"pre-release-actions" => array(),
Expand Down Expand Up @@ -83,6 +84,11 @@ protected function normalize($config)
// Validate the config entry
$this->validateRootElements($config);

// Load the bootstrap file if present
if ($config['bootstrap'] !== null) {
require $this->projectRoot.DIRECTORY_SEPARATOR.$config['bootstrap'];
}

// For single value elements, normalize all class name and options, remove null entry
foreach (array("vcs", "version-generator", "version-persister") as $configKey) {
$value = $config[$configKey];
Expand Down Expand Up @@ -179,6 +185,12 @@ protected function findClass($name, $sectionName)
throw new \Liip\RMT\Exception("Impossible to open [$file] please review your config");
}
}
elseif (strpos($name, '\\') !== false ) {
// If the name contains a backslash, assume it's a full namespaced class and load it as-is
// If the class has no namespace, it can be prefixed with a backslash to trigger this behaviour

return $name;
}

return $this->findInternalClass($name, $sectionName);
}
Expand Down
18 changes: 17 additions & 1 deletion test/Liip/RMT/Tests/Unit/Config/HandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public function testMerge()
$method->setAccessible(true);

$this->assertEquals($method->invokeArgs($configHandler, array()), array(
'bootstrap' => null,
'vcs' => null,
'prerequisites' => array(),
'pre-release-actions' => array(),
Expand All @@ -143,6 +144,7 @@ public function testMerge()
'version-persister' => 'foo',
));
$this->assertEquals($method->invokeArgs($configHandler, array('dev')), array(
'bootstrap' => null,
'vcs' => null,
'prerequisites' => array(),
'pre-release-actions' => array(),
Expand All @@ -168,6 +170,7 @@ public function testMergeOptions()
$method->setAccessible(true);

$this->assertEquals($method->invokeArgs($configHandler, array()), array(
'bootstrap' => null,
'vcs' => null,
'prerequisites' => array(),
'pre-release-actions' => array(),
Expand All @@ -176,6 +179,7 @@ public function testMergeOptions()
'version-persister' => 'foo',
));
$this->assertEquals($method->invokeArgs($configHandler, array('dev')), array(
'bootstrap' => null,
'vcs' => null,
'prerequisites' => array(),
'pre-release-actions' => array(),
Expand Down Expand Up @@ -221,7 +225,19 @@ public function getDataForTestingGetClassAndOptions()
array('vcs', array('name' => 'git'), 'Liip\RMT\VCS\Git', array()),
// vcs: {name: git, opt1: val1}
array('vcs', array('name' => 'git', 'opt1' => 'val1'), 'Liip\RMT\VCS\Git', array('opt1' => 'val1')),
array('prerequisites_1', 'vcs-clean-check', 'Liip\RMT\Prerequisite\VcsCleanCheck', array())
array('prerequisites_1', 'vcs-clean-check', 'Liip\RMT\Prerequisite\VcsCleanCheck', array()),
// vcs: Foo\Bar
array('vcs', 'Foo\Bar', 'Foo\Bar', array()),
// vcs: Foo
array('vcs', 'Foo', 'Liip\RMT\VCS\Foo', array()),
// vcs: \Foo
array('vcs', '\Foo', '\Foo', array()),
// pre-release-actions: Foo\Bar
array('pre-release-actions', 'Foo\Bar', 'Foo\Bar', array()),
// pre-release-actions: Foo
array('pre-release-actions', 'Foo', 'Liip\RMT\Action\FooAction', array()),
// pre-release-actions: \Foo
array('pre-release-actions', '\Foo', '\Foo', array())
);
}
}