From 06d1a1b96c02ef717b533ca4b23084f2cb3433c6 Mon Sep 17 00:00:00 2001 From: Olivier Scherler Date: Fri, 23 Jan 2015 11:37:17 +0100 Subject: [PATCH 1/2] Allow to use external autoloaded classes by specifying a full namespace. --- src/Liip/RMT/Config/Handler.php | 6 ++++++ test/Liip/RMT/Tests/Unit/Config/HandlerTest.php | 14 +++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Liip/RMT/Config/Handler.php b/src/Liip/RMT/Config/Handler.php index 6dd307fe..9af5c101 100644 --- a/src/Liip/RMT/Config/Handler.php +++ b/src/Liip/RMT/Config/Handler.php @@ -179,6 +179,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); } diff --git a/test/Liip/RMT/Tests/Unit/Config/HandlerTest.php b/test/Liip/RMT/Tests/Unit/Config/HandlerTest.php index c3e77b96..e574c0f9 100644 --- a/test/Liip/RMT/Tests/Unit/Config/HandlerTest.php +++ b/test/Liip/RMT/Tests/Unit/Config/HandlerTest.php @@ -221,7 +221,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()) ); } } From 698667fc3461086c2e4678186c5114f9020c0829 Mon Sep 17 00:00:00 2001 From: Olivier Scherler Date: Fri, 23 Jan 2015 11:41:14 +0100 Subject: [PATCH 2/2] Allow loading of a bootstrap file to autoload your own classes. --- src/Liip/RMT/Config/Handler.php | 6 ++++++ test/Liip/RMT/Tests/Unit/Config/HandlerTest.php | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/Liip/RMT/Config/Handler.php b/src/Liip/RMT/Config/Handler.php index 9af5c101..7ac40eae 100644 --- a/src/Liip/RMT/Config/Handler.php +++ b/src/Liip/RMT/Config/Handler.php @@ -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(), @@ -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]; diff --git a/test/Liip/RMT/Tests/Unit/Config/HandlerTest.php b/test/Liip/RMT/Tests/Unit/Config/HandlerTest.php index e574c0f9..8e3628ba 100644 --- a/test/Liip/RMT/Tests/Unit/Config/HandlerTest.php +++ b/test/Liip/RMT/Tests/Unit/Config/HandlerTest.php @@ -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(), @@ -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(), @@ -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(), @@ -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(),