From 27cea80b15a986d43b832658b13d01c08a5cfce1 Mon Sep 17 00:00:00 2001 From: Loz Calver Date: Thu, 7 Jul 2016 10:23:38 +0100 Subject: [PATCH] FIX: SS_ConfigStaticManifest_Parser failed to handle ::class syntax (fixes #5701) (#5781) --- core/manifest/ConfigStaticManifest.php | 13 +++++++++++++ tests/core/manifest/ConfigStaticManifestTest.php | 10 ++++++++++ .../ConfigStaticManifestTestClassKeyword.php | 11 +++++++++++ 3 files changed, 34 insertions(+) create mode 100644 tests/core/manifest/ConfigStaticManifestTest/ConfigStaticManifestTestClassKeyword.php diff --git a/core/manifest/ConfigStaticManifest.php b/core/manifest/ConfigStaticManifest.php index ba488a5b7..9e0ac8f36 100644 --- a/core/manifest/ConfigStaticManifest.php +++ b/core/manifest/ConfigStaticManifest.php @@ -242,6 +242,19 @@ class SS_ConfigStaticManifest_Parser { $type = is_array($token) ? $token[0] : $token; if($type == T_CLASS) { + // Fetch the last token + $pos = $this->pos - 1; // Subtract 1 as the pointer is always 1 place ahead of the current token + do { + $pos--; + $prev = $this->tokens[$pos]; + } while ($pos > 0 && is_array($prev) && $prev[0] == T_WHITESPACE); + + // Ignore class keyword if it's being used for class name resolution: ClassName::class + $lastType = ($prev === (array)$prev) ? $prev[0] : $prev; + if ($lastType === T_PAAMAYIM_NEKUDOTAYIM) { + continue; + } + $next = $this->nextString(); if($next === null) { user_error("Couldn\'t parse {$this->path} when building config static manifest", E_USER_ERROR); diff --git a/tests/core/manifest/ConfigStaticManifestTest.php b/tests/core/manifest/ConfigStaticManifestTest.php index 3709bd384..4b60d197a 100644 --- a/tests/core/manifest/ConfigStaticManifestTest.php +++ b/tests/core/manifest/ConfigStaticManifestTest.php @@ -257,6 +257,16 @@ DOC; $this->assertEquals($expected, $statics[':ss:test2']); } + + public function testParsingClassKeyword() { + $parser = new SS_ConfigStaticManifest_Parser(__DIR__ . + '/ConfigStaticManifestTest/ConfigStaticManifestTestClassKeyword.php'); + $parser->parse(); + + $statics = $parser->getStatics(); + + $this->assertEquals('bar', $statics['ConfigStaticManifestTestClassKeyword']['foo']['value']); + } } class ConfigStaticManifestTest_Parser extends SS_ConfigStaticManifest_Parser implements TestOnly { diff --git a/tests/core/manifest/ConfigStaticManifestTest/ConfigStaticManifestTestClassKeyword.php b/tests/core/manifest/ConfigStaticManifestTest/ConfigStaticManifestTestClassKeyword.php new file mode 100644 index 000000000..cfd8e740b --- /dev/null +++ b/tests/core/manifest/ConfigStaticManifestTest/ConfigStaticManifestTestClassKeyword.php @@ -0,0 +1,11 @@ +inst = Injector::inst()->get(static::class); + } + +}