Skip to content

Commit 0614c9e

Browse files
committed
[ClassLoader][Routing] Fix namespace parsing on php 8.
1 parent 58381b7 commit 0614c9e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Loader/AnnotationFileLoader.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ protected function findClass($file)
9797
throw new \InvalidArgumentException(sprintf('The file "%s" does not contain PHP code. Did you forgot to add the "<?php" start tag at the beginning of the file?', $file));
9898
}
9999

100+
$nsTokens = [T_NS_SEPARATOR => true, T_STRING => true];
101+
if (\defined('T_NAME_QUALIFIED')) {
102+
$nsTokens[T_NAME_QUALIFIED] = true;
103+
}
104+
100105
for ($i = 0; isset($tokens[$i]); ++$i) {
101106
$token = $tokens[$i];
102107

@@ -108,9 +113,9 @@ protected function findClass($file)
108113
return $namespace.'\\'.$token[1];
109114
}
110115

111-
if (true === $namespace && T_STRING === $token[0]) {
116+
if (true === $namespace && isset($nsTokens[$token[0]])) {
112117
$namespace = $token[1];
113-
while (isset($tokens[++$i][1]) && \in_array($tokens[$i][0], [T_NS_SEPARATOR, T_STRING])) {
118+
while (isset($tokens[++$i][1], $nsTokens[$tokens[$i][0]])) {
114119
$namespace .= $tokens[$i][1];
115120
}
116121
$token = $tokens[$i];

0 commit comments

Comments
 (0)