Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ab621ee

Browse filesBrowse 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
Copy full SHA for ab621ee

File tree

3 files changed

+41
-1
lines changed
Filter options

3 files changed

+41
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php
+18-1Lines 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]) {
+13Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Tests/Loader/AnnotationFileLoaderTest.php
+10Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.