FIX Handle namespaced classes in Object::parse_class_spec()

This commit is contained in:
Simon Welsh 2012-12-18 15:00:45 +13:00
parent 618a3d0314
commit 94be5c6d87
2 changed files with 17 additions and 0 deletions

View File

@ -164,12 +164,19 @@ abstract class Object {
// Keep track of the current bucket that we're putting data into
$bucket = &$args;
$bucketStack = array();
$had_ns = false;
foreach($tokens as $token) {
$tName = is_array($token) ? $token[0] : $token;
// Get the class naem
if($class == null && is_array($token) && $token[0] == T_STRING) {
$class = $token[1];
} elseif(is_array($token) && $token[0] == T_NS_SEPARATOR) {
$class .= $token[1];
$had_ns = true;
} elseif ($had_ns && is_array($token) && $token[0] == T_STRING) {
$class .= $token[1];
$had_ns = false;
// Get arguments
} else if(is_array($token)) {
switch($token[0]) {

View File

@ -361,6 +361,16 @@ class ObjectTest extends SapphireTest {
Object::parse_class_spec(
"Enum(array('Accepted', 'Pending', 'Declined', array('UnsubmittedA','UnsubmittedB')), 'Unsubmitted')")
);
// Namespaced class
$this->assertEquals(
array('Test\MyClass', array()),
Object::parse_class_spec('Test\MyClass')
);
// Fully qualified namespaced class
$this->assertEquals(
array('\Test\MyClass', array()),
Object::parse_class_spec('\Test\MyClass')
);
}
}