Skip to content

Commit ab621ee

Browse files
committed
bug #18907 [Routing] Fix the annotation loader taking a class constant as a beginning of a class name (jakzal, nicolas-grekas)
This PR was merged into the 2.3 branch. Discussion ---------- [Routing] Fix the annotation loader taking a class constant as a beginning of a class name | Q | A | ------------- | --- | Branch? | 2.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #18633 | License | MIT | Doc PR | - Code copy/pasted from ClassMapGenerator.php Commits ------- 8d4f35d [Routing] Finish annotation loader taking a class constant as a beginning of a class name 43c7f9b [Routing] Fix the annotation loader taking a class constant as a beginning of a class name
2 parents b576fe1 + 8d4f35d commit ab621ee

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,24 @@ protected function findClass($file)
112112
}
113113

114114
if (T_CLASS === $token[0]) {
115-
$class = true;
115+
// Skip usage of ::class constant
116+
$isClassConstant = false;
117+
for ($j = $i - 1; $j > 0; --$j) {
118+
if (!isset($tokens[$j][1])) {
119+
break;
120+
}
121+
122+
if (T_DOUBLE_COLON === $tokens[$j][0]) {
123+
$isClassConstant = true;
124+
break;
125+
} elseif (!in_array($tokens[$j][0], array(T_WHITESPACE, T_DOC_COMMENT, T_COMMENT))) {
126+
break;
127+
}
128+
}
129+
130+
if (!$isClassConstant) {
131+
$class = true;
132+
}
116133
}
117134

118135
if (T_NAMESPACE === $token[0]) {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses;
4+
5+
trait FooTrait
6+
{
7+
public function doBar()
8+
{
9+
$baz = self::class;
10+
if (true) {
11+
}
12+
}
13+
}

src/Symfony/Component/Routing/Tests/Loader/AnnotationFileLoaderTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ public function testLoad()
3535
$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooClass.php');
3636
}
3737

38+
/**
39+
* @requires PHP 5.4
40+
*/
41+
public function testLoadTraitWithClassConstant()
42+
{
43+
$this->reader->expects($this->never())->method('getClassAnnotation');
44+
45+
$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooTrait.php');
46+
}
47+
3848
/**
3949
* @requires PHP 5.6
4050
*/

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy