Compare commits

...

1 Commits

Author SHA1 Message Date
Alexander M. Turek
04a7e4c1bf [ClassLoader][Routing] Fix namespace parsing on php 8. 2020-08-09 13:28:08 +02:00
2 changed files with 12 additions and 2 deletions

View File

@@ -216,6 +216,11 @@ REGEX;
$inNamespace = false;
$tokens = token_get_all($source);
$nsTokens = [T_WHITESPACE => true, T_NS_SEPARATOR => true, T_STRING => true];
if (\defined('T_NAME_QUALIFIED')) {
$nsTokens[T_NAME_QUALIFIED] = true;
}
for ($i = 0; isset($tokens[$i]); ++$i) {
$token = $tokens[$i];
if (!isset($token[1]) || 'b"' === $token) {
@@ -230,7 +235,7 @@ REGEX;
$rawChunk .= $token[1];
// namespace name and whitespaces
while (isset($tokens[++$i][1]) && \in_array($tokens[$i][0], [T_WHITESPACE, T_NS_SEPARATOR, T_STRING])) {
while (isset($tokens[++$i][1], $nsTokens[$tokens[$i][0]])) {
$rawChunk .= $tokens[$i][1];
}
if ('{' === $tokens[$i]) {

View File

@@ -93,6 +93,11 @@ class ClassMapGenerator
$contents = file_get_contents($path);
$tokens = token_get_all($contents);
$nsTokens = [T_STRING => true, T_NS_SEPARATOR => true];
if (\defined('T_NAME_QUALIFIED')) {
$nsTokens[T_NAME_QUALIFIED] = true;
}
$classes = [];
$namespace = '';
@@ -110,7 +115,7 @@ class ClassMapGenerator
$namespace = '';
// If there is a namespace, extract it
while (isset($tokens[++$i][1])) {
if (\in_array($tokens[$i][0], [T_STRING, T_NS_SEPARATOR])) {
if (isset($nsTokens[$tokens[$i][0]])) {
$namespace .= $tokens[$i][1];
}
}