8000 Merge branch '2.7' into 2.8 · symfony/symfony@e617502 · GitHub
[go: up one dir, main page]

Skip to content

Commit e617502

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: [Routing] Finish annotation loader taking a class constant as a beginning of a class name [Routing] Fix the annotation loader taking a class constant as a beginning of a class name
2 parents dfc0c81 + 00763f6 commit e617502

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)
0