8000 [Routing] Fix the annotation loader taking a class constant as a beginning of a class name by nicolas-grekas · Pull Request #18907 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Routing] Fix the annotation loader taking a class constant as a beginning of a class name #18907

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,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]) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses;

trait FooTrait
{
public function doBar()
{
$baz = self::class;
if (true) {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ public function testLoad()
$this->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
*/
Expand Down
0