Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1280 from silverstripe-rebelalliance/feature/config

FIX Parsing heredoc, nowdoc & comments in ConfigStaticManifest
  • Loading branch information...
commit 8b2a911c806f74a6780a7bce8dce75728c1e6781 2 parents e486574 + d8a1df4
@sminnee sminnee authored
View
13 core/manifest/ConfigStaticManifest.php
@@ -268,6 +268,9 @@ function parseStatic($access, $class) {
else if($type == ';' || $type == ',' || $type == '=') {
break;
}
+ else if($type == T_COMMENT || $type == T_DOC_COMMENT) {
+ // NOP
+ }
else {
user_error('Unexpected token when building static manifest: '.print_r($token, true), E_USER_ERROR);
}
@@ -315,9 +318,17 @@ function parseStatic($access, $class) {
$this->statics[$class] = array();
}
+ $value = trim($value);
+ if ($value) {
+ $value = eval('static $temp = '.$value.";\n".'return $temp'.";\n");
+ }
+ else {
+ $value = null;
+ }
+
$this->statics[$class][$variable] = array(
'access' => $access,
- 'value' => eval('return '.$value.';')
+ 'value' => $value
);
if($token == ',') $this->parseStatic($access, $class);
View
45 tests/core/manifest/ConfigStaticManifestTest.php
@@ -20,9 +20,20 @@ class ConfigStaticManifestTest extends SapphireTest {
static $sfloat = 2.5;
static $sstring = 'string';
static $sarray = array(1, 2, array(3, 4), 5);
+ static $sheredoc = <<<DOC
+heredoc
+DOC;
+ static $snowdoc = <<<'DOC'
+nowdoc
+DOC;
// Assigning multiple values
- static $onone, $onull = null, $oint = 1, $ofloat = 2.5, $ostring = 'string', $oarray = array(1, 2, array(3, 4), 5);
+ static $onone, $onull = null, $oint = 1, $ofloat = 2.5, $ostring = 'string', $oarray = array(1, 2, array(3, 4), 5), $oheredoc = <<<DOC
+heredoc
+DOC
+, $onowdoc = <<<'DOC'
+nowdoc
+DOC;
static
$mnone,
@@ -34,7 +45,25 @@ class ConfigStaticManifestTest extends SapphireTest {
1, 2,
array(3, 4),
5
- );
+ ),
+ $mheredoc = <<<DOC
+heredoc
+DOC
+ ,
+ $mnowdoc = <<<'DOC'
+nowdoc
+DOC;
+
+
+ static /* Has comment inline */ $commented_int = 1, /* And here */ $commented_string = 'string';
+
+ static
+ /**
+ * Has docblock inline
+ */
+ $docblocked_int = 1,
+ /** And here */
+ $docblocked_string = 'string';
// Should ignore static methpds
static function static_method() {}
@@ -90,6 +119,8 @@ public function testParsingValues() {
'float',
'string',
'array',
+ 'heredoc',
+ 'nowdoc'
);
$prepends = array(
@@ -111,6 +142,16 @@ public function testParsingValues() {
}
}
+ public function testIgnoreComments() {
+ $statics = $this->parseSelf()->getStatics();
+
+ $this->assertEquals(self::$commented_int, $statics[__CLASS__]['commented_int']['value']);
+ $this->assertEquals(self::$commented_string, $statics[__CLASS__]['commented_string']['value']);
+
+ $this->assertEquals(self::$docblocked_int, $statics[__CLASS__]['docblocked_int']['value']);
+ $this->assertEquals(self::$docblocked_string, $statics[__CLASS__]['docblocked_string']['value']);
+ }
+
public function testIgnoresMethodStatics() {
$statics = $this->parseSelf()->getStatics();
$this->assertNull(@$statics[__CLASS__]['method_static']);
Please sign in to comment.
Something went wrong with that request. Please try again.