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 e016c78

Browse filesBrowse files
committed
Skip anonymous classes inside a trait when loading annotated routes
1 parent 70c8c2d commit e016c78
Copy full SHA for e016c78

File tree

3 files changed

+37
-2
lines changed
Filter options

3 files changed

+37
-2
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ protected function findClass($file)
107107
}
108108

109109
if (T_CLASS === $token[0]) {
110-
// Skip usage of ::class constant
110+
// Skip usage of ::class constant and anonymous classes
111111
$isClassConstant = false;
112112
for ($j = $i - 1; $j > 0; --$j) {
113113
if (!isset($tokens[$j][1])) {
114114
break;
115115
}
116116

117-
if (T_DOUBLE_COLON === $tokens[$j][0]) {
117+
if (T_DOUBLE_COLON === $tokens[$j][0] || T_NEW === $tokens[$j][0]) {
118118
$isClassConstant = true;
119119
break;
120120
} elseif (!in_array($tokens[$j][0], array(T_WHITESPACE, T_DOC_COMMENT, T_COMMENT))) {
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Routing\Tests\Fixtures\OtherAnnotatedClasses;
13+
14+
trait AnonymousClassInTrait
15+
{
16+
public function test()
17+
{
18+
return new class() {
19+
public function foo()
20+
{
21+
}
22+
};
23+
}
24+
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Tests/Loader/AnnotationFileLoaderTest.php
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ public function testLoadVariadic()
5858
$this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/VariadicClass.php');
5959
}
6060

61+
/**
62+
* @requires PHP 7.0
63+
*/
64+
public function testLoadAnonymousClass()
65+
{
66+
$this->reader->expects($this->never())->method('getClassAnnotation');
67+
$this->reader->expects($this->never())->method('getMethodAnnotations');
68+
69+
$this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/AnonymousClassInTrait.php');
70+
}
71+
6172
public function testSupports()
6273
{
6374
$fixture = __DIR__.'/../Fixtures/annotated.php';

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.