Skip to content

Commit

Permalink
bug #18907 [Routing] Fix the annotation loader taking a class constan…
Browse files Browse the repository at this point in the history
…t 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
  • Loading branch information
fabpot committed May 29, 2016
2 parents b576fe1 + 8d4f35d commit ab621ee
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php
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
@@ -0,0 +1,13 @@
<?php

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

trait FooTrait
{
public function doBar()
{
$baz = self::class;
if (true) {
}
}
}
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 comments on commit ab621ee

Please sign in to comment.