Skip to content

Instantly share code, notes, and snippets.

@thekid
Created December 31, 2011 16:11
Show Gist options
  • Select an option

  • Save thekid/1544449 to your computer and use it in GitHub Desktop.

Select an option

Save thekid/1544449 to your computer and use it in GitHub Desktop.
XP Framework: Patch for Issue #95
diff --git a/core/src/main/php/util/PropertyManager.class.php b/core/src/main/php/util/PropertyManager.class.php
index 444f335..75cd0db 100644
--- a/core/src/main/php/util/PropertyManager.class.php
+++ b/core/src/main/php/util/PropertyManager.class.php
@@ -127,19 +127,25 @@
*
* @param string name
* @return util.PropertyAccess
+ * @throws lang.ElementNotFoundException
*/
public function getProperties($name) {
$found= array();
-
foreach ($this->provider as $path) {
if ($path->provides($name)) {
$found[]= $path->fetch($name);
}
}
- if (0 == sizeof($found)) return NULL;
- if (1 == sizeof($found)) return $found[0];
- return new CompositeProperties($found);
+ switch (sizeof($found)) {
+ case 1: return $found[0];
+ case 0: raise('lang.ElementNotFoundException', sprintf(
+ 'Canot find properties "%s" in any of %s',
+ $name,
+ xp::stringOf($this->provider)
+ ));
+ default: return new CompositeProperties($found);
+ }
}
}
?>
diff --git a/core/src/test/php/net/xp_framework/unittest/util/PropertyManagerTest.class.php b/core/src/test/php/net/xp_framework/unittest/util/PropertyManagerTest.class.php
index 609ce4c..bbd3b3e 100755
--- a/core/src/test/php/net/xp_framework/unittest/util/PropertyManagerTest.class.php
+++ b/core/src/test/php/net/xp_framework/unittest/util/PropertyManagerTest.class.php
@@ -221,5 +221,26 @@ key="overwritten value"'));
$this->assertInstanceOf('util.Properties', $fixture->getProperties('example'));
}
+
+ /**
+ * Test getProperties()
+ *
+ */
+ #[@test]
+ public function getExistantProperties() {
+ $p= $this->preconfigured()->getProperties('example');
+ $this->assertInstanceOf('util.Properties', $p);
+ $this->assertTrue($p->exists(), 'Should return an existant Properties instance');
+
+ }
+
+ /**
+ * Test getProperties()
+ *
+ */
+ #[@test, @expect('lang.ElementNotFoundException')]
+ public function getNonExistantProperties() {
+ $this->preconfigured()->getProperties('does-not-exist');
+ }
}
?>
diff --git a/tools/src/main/php/xp/command/Runner.class.php b/tools/src/main/php/xp/command/Runner.class.php
index 6c15704..9a54586 100644
--- a/tools/src/main/php/xp/command/Runner.class.php
+++ b/tools/src/main/php/xp/command/Runner.class.php
@@ -293,33 +293,36 @@
} else {
$type= $method->getParameter(0)->getType()->getName();
}
- switch ($type) {
- case 'rdbms.DBConnection': {
- $args= array($cm->getByHost($inject['name'], 0));
- break;
- }
+ try {
+ switch ($type) {
+ case 'rdbms.DBConnection': {
+ $args= array($cm->getByHost($inject['name'], 0));
+ break;
+ }
- case 'util.Properties': {
- $args= array($pm->getProperties($inject['name']));
- break;
- }
+ case 'util.Properties': {
+ $args= array($pm->getProperties($inject['name']));
+ break;
+ }
- case 'util.log.LogCategory': {
- $args= array($l->getCategory($inject['name']));
- break;
- }
+ case 'util.log.LogCategory': {
+ $args= array($l->getCategory($inject['name']));
+ break;
+ }
- default: {
- self::$err->writeLine('*** Unknown injection type "'.$type.'" at method "'.$method->getName().'"');
- return 2;
+ default: {
+ self::$err->writeLine('*** Unknown injection type "'.$type.'" at method "'.$method->getName().'"');
+ return 2;
+ }
}
- }
- try {
$method->invoke($instance, $args);
} catch (TargetInvocationException $e) {
self::$err->writeLine('*** Error injecting '.$type.' '.$inject['name'].': '.$e->getCause()->compoundMessage());
return 2;
+ } catch (Throwable $e) {
+ self::$err->writeLine('*** Error injecting '.$type.' '.$inject['name'].': '.$e->compoundMessage());
+ return 2;
}
}
@thekid
Copy link
Author

thekid commented Dec 31, 2011

There's two whitespace messups in here, I'll leave it to whomever applies this to fix them after doing so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment