From e55be5078337126fc6c6937c24f992fd1015eba7 Mon Sep 17 00:00:00 2001 From: Simon Welsh Date: Wed, 26 Jun 2013 15:49:00 +1200 Subject: [PATCH] FIX: ConfigStaticManifest not handling multipart namespaces Fixes #2126 --- core/manifest/ConfigStaticManifest.php | 26 ++++++++++++++----- .../manifest/ConfigStaticManifestTest.php | 18 ++++++++++++- .../ConfigStaticManifestTestNamespace.php | 10 +++++++ 3 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 tests/core/manifest/ConfigStaticManifestTest/ConfigStaticManifestTestNamespace.php diff --git a/core/manifest/ConfigStaticManifest.php b/core/manifest/ConfigStaticManifest.php index a972e88c4..5dddd9266 100644 --- a/core/manifest/ConfigStaticManifest.php +++ b/core/manifest/ConfigStaticManifest.php @@ -78,7 +78,8 @@ class SS_ConfigStaticManifest { $static = $this->statics[$class][$name]; if ($static['access'] != T_PRIVATE) { - Deprecation::notice('3.2.0', "Config static $class::\$$name must be marked as private", Deprecation::SCOPE_GLOBAL); + Deprecation::notice('3.2.0', "Config static $class::\$$name must be marked as private", + Deprecation::SCOPE_GLOBAL); // Don't warn more than once per static $this->statics[$class][$name]['access'] = T_PRIVATE; } @@ -211,13 +212,23 @@ class SS_ConfigStaticManifest_Parser { $class = $next[1]; } else if($type == T_NAMESPACE) { - $next = $this->next(); + $namespace = ''; + while(true) { + $next = $this->next(); - if($next[0] != T_STRING) { - user_error("Couldn\'t parse {$this->path} when building config static manifest", E_USER_ERROR); + if($next == ';') { + break; + } elseif($next[0] == T_NS_SEPARATOR) { + $namespace .= $next[1]; + $next = $this->next(); + } + + if($next[0] != T_STRING) { + user_error("Couldn\'t parse {$this->path} when building config static manifest", E_USER_ERROR); + } + + $namespace .= $next[1]; } - - $namespace = $next[1]; } else if($type == '{' || $type == T_CURLY_OPEN || $type == T_DOLLAR_OPEN_CURLY_BRACES){ $depth += 1; @@ -288,7 +299,8 @@ class SS_ConfigStaticManifest_Parser { $depth -= 1; } - // Parse out the assignment side of a static declaration, ending on either a ';' or a ',' outside an array + // Parse out the assignment side of a static declaration, + // ending on either a ';' or a ',' outside an array if($type == T_WHITESPACE) { $value .= ' '; } diff --git a/tests/core/manifest/ConfigStaticManifestTest.php b/tests/core/manifest/ConfigStaticManifestTest.php index cb87841b5..87d1103db 100644 --- a/tests/core/manifest/ConfigStaticManifestTest.php +++ b/tests/core/manifest/ConfigStaticManifestTest.php @@ -170,7 +170,8 @@ DOC; return; } - $parser = new SS_ConfigStaticManifest_Parser(__DIR__ . '/ConfigStaticManifestTest/ConfigStaticManifestTestMyObject.php'); + $parser = new SS_ConfigStaticManifest_Parser(__DIR__ . + '/ConfigStaticManifestTest/ConfigStaticManifestTestMyObject.php'); $parser->parse(); $statics = $parser->getStatics(); @@ -182,4 +183,19 @@ DOC; $this->assertEquals($expectedValue, $statics['ConfigStaticManifestTestMyObject']['db']['value']); } + + public function testParsingNamespacesclass() { + $parser = new SS_ConfigStaticManifest_Parser(__DIR__ . + '/ConfigStaticManifestTest/ConfigStaticManifestTestNamespace.php'); + $parser->parse(); + + $statics = $parser->getStatics(); + + $expectedValue = array( + 'Name' => 'Varchar', + 'Description' => 'Text', + ); + + $this->assertEquals($expectedValue, $statics['config\staticmanifest\NamespaceTest']['db']['value']); + } } diff --git a/tests/core/manifest/ConfigStaticManifestTest/ConfigStaticManifestTestNamespace.php b/tests/core/manifest/ConfigStaticManifestTest/ConfigStaticManifestTestNamespace.php new file mode 100644 index 000000000..a2128af98 --- /dev/null +++ b/tests/core/manifest/ConfigStaticManifestTest/ConfigStaticManifestTestNamespace.php @@ -0,0 +1,10 @@ + 'Varchar', + 'Description' => 'Text', + ); +}