Permalink
Browse files

FIX Handle namespaced classes in Object::parse_class_spec()

  • Loading branch information...
1 parent 618a3d0 commit 94be5c6d8749ed969e9d1ebda69237f9282e943a @simonwelsh simonwelsh committed Dec 18, 2012
Showing with 17 additions and 0 deletions.
  1. +7 −0 core/Object.php
  2. +10 −0 tests/core/ObjectTest.php
View
@@ -164,12 +164,19 @@ public static function parse_class_spec($classSpec) {
// 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
@@ -361,6 +361,16 @@ public function testParseClassSpec() {
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')
+ );
}
}

0 comments on commit 94be5c6

Please sign in to comment.