Permalink
Browse files

FIX Parsing heredoc, nowdoc & comments in ConfigStaticManifest

  • Loading branch information...
1 parent e6352df commit 60b72edfba8a0fbe887f86dc26eb572e02b9ec19 Hamish Friedlander committed Mar 12, 2013
Showing with 35 additions and 3 deletions.
  1. +4 −1 core/manifest/ConfigStaticManifest.php
  2. +31 −2 tests/core/manifest/ConfigStaticManifestTest.php
@@ -268,6 +268,9 @@ function parseStatic($access, $class) {
else if($type == ';' || $type == ',' || $type == '=') {
break;
}
+ else if($type == T_COMMENT) {
+ // NOP
+ }
else {
user_error('Unexpected token when building static manifest: '.print_r($token, true), E_USER_ERROR);
}
@@ -317,7 +320,7 @@ function parseStatic($access, $class) {
$this->statics[$class][$variable] = array(
'access' => $access,
- 'value' => eval('return '.$value.';')
+ 'value' => eval('return '.trim($value).";\n")
);
if($token == ',') $this->parseStatic($access, $class);
@@ -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,17 @@ 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';
// Should ignore static methpds
static function static_method() {}
@@ -90,6 +111,8 @@ public function testParsingValues() {
'float',
'string',
'array',
+ 'heredoc',
+ 'nowdoc'
);
$prepends = array(
@@ -111,6 +134,12 @@ 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']);
+ }
+
public function testIgnoresMethodStatics() {
$statics = $this->parseSelf()->getStatics();
$this->assertNull(@$statics[__CLASS__]['method_static']);

0 comments on commit 60b72ed

Please sign in to comment.