Skip to content

Commit

Permalink
FIX: ConfigStaticManifest not handling multipart namespaces
Browse files Browse the repository at this point in the history
Fixes #2126
  • Loading branch information
simonwelsh committed Jun 26, 2013
1 parent 83726b2 commit e55be50
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
28 changes: 20 additions & 8 deletions core/manifest/ConfigStaticManifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public function get($class, $name, $default) {
$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;
}
Expand Down Expand Up @@ -211,13 +212,23 @@ function parse() {
$class = $next[1];
}
else if($type == T_NAMESPACE) {
$next = $this->next();

if($next[0] != T_STRING) {
user_error("Couldn\'t parse {$this->path} when building config static manifest", E_USER_ERROR);
$namespace = '';
while(true) {
$next = $this->next();

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;
Expand Down Expand Up @@ -288,7 +299,8 @@ function parseStatic($access, $class) {
$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 .= ' ';
}
Expand Down
18 changes: 17 additions & 1 deletion tests/core/manifest/ConfigStaticManifestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ public function testParsingShortArray() {
return;
}

$parser = new SS_ConfigStaticManifest_Parser(__DIR__ . '/ConfigStaticManifestTest/ConfigStaticManifestTestMyObject.php');
$parser = new SS_ConfigStaticManifest_Parser(__DIR__ .
'/ConfigStaticManifestTest/ConfigStaticManifestTestMyObject.php');
$parser->parse();

$statics = $parser->getStatics();
Expand All @@ -182,4 +183,19 @@ public function testParsingShortArray() {

$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']);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace config\staticmanifest;

class NamespaceTest implements \TestOnly {
static private $db = array(
'Name' => 'Varchar',
'Description' => 'Text',
);
}

0 comments on commit e55be50

Please sign in to comment.