From 43c7f9b5e95cd2b330f489eab08e8f43a32285da Mon Sep 17 00:00:00 2001 From: Jakub Zalas Date: Mon, 25 Apr 2016 16:50:46 +0100 Subject: [PATCH 1/2] [Routing] Fix the annotation loader taking a class constant as a beginning of a class name --- .../Routing/Loader/AnnotationFileLoader.php | 2 ++ .../Tests/Fixtures/AnnotatedClasses/FooTrait.php | 13 +++++++++++++ .../Tests/Loader/AnnotationFileLoaderTest.php | 10 ++++++++++ 3 files changed, 25 insertions(+) create mode 100644 src/Symfony/Component/Routing/Tests/Fixtures/AnnotatedClasses/FooTrait.php diff --git a/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php index a3a7e0e5ae50e..7e424fd336c5c 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php @@ -96,6 +96,8 @@ protected function findClass($file) $token = $tokens[$i]; if (!isset($token[1])) { + $class = false; + continue; } diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/AnnotatedClasses/FooTrait.php b/src/Symfony/Component/Routing/Tests/Fixtures/AnnotatedClasses/FooTrait.php new file mode 100644 index 0000000000000..f34c6b64cf431 --- /dev/null +++ b/src/Symfony/Component/Routing/Tests/Fixtures/AnnotatedClasses/FooTrait.php @@ -0,0 +1,13 @@ +loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooClass.php'); } + /** + * @requires PHP 5.4 + */ + public function testLoadTraitWithClassConstant() + { + $this->reader->expects($this->never())->method('getClassAnnotation'); + + $this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooTrait.php'); + } + /** * @requires PHP 5.6 */ From 8d4f35d12cc660bb5bc6d7a3955ad3fd953913d2 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sun, 29 May 2016 12:13:06 +0200 Subject: [PATCH 2/2] [Routing] Finish annotation loader taking a class constant as a beginning of a class name --- .../Routing/Loader/AnnotationFileLoader.php | 21 ++++++++++++++++--- .../Fixtures/AnnotatedClasses/FooTrait.php | 2 +- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php index 7e424fd336c5c..b8fc03615f968 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php @@ -96,8 +96,6 @@ protected function findClass($file) $token = $tokens[$i]; if (!isset($token[1])) { - $class = false; - continue; } @@ -114,7 +112,24 @@ protected function findClass($file) } if (T_CLASS === $token[0]) { - $class = true; + // Skip usage of ::class constant + $isClassConstant = false; + for ($j = $i - 1; $j > 0; --$j) { + if (!isset($tokens[$j][1])) { + break; + } + + if (T_DOUBLE_COLON === $tokens[$j][0]) { + $isClassConstant = true; + break; + } elseif (!in_array($tokens[$j][0], array(T_WHITESPACE, T_DOC_COMMENT, T_COMMENT))) { + break; + } + } + + if (!$isClassConstant) { + $class = true; + } } if (T_NAMESPACE === $token[0]) { diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/AnnotatedClasses/FooTrait.php b/src/Symfony/Component/Routing/Tests/Fixtures/AnnotatedClasses/FooTrait.php index f34c6b64cf431..ee8f4b071a368 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/AnnotatedClasses/FooTrait.php +++ b/src/Symfony/Component/Routing/Tests/Fixtures/AnnotatedClasses/FooTrait.php @@ -10,4 +10,4 @@ public function doBar() if (true) { } } -} \ No newline at end of file +}