[Routing] fix conflict with param named class in attribute
This commit is contained in:
parent
a7f12dab24
commit
27bba684d8
@ -97,12 +97,10 @@ class AnnotationFileLoader extends FileLoader
|
|||||||
|
|
||||||
$nsTokens = [\T_NS_SEPARATOR => true, \T_STRING => true];
|
$nsTokens = [\T_NS_SEPARATOR => true, \T_STRING => true];
|
||||||
if (\defined('T_NAME_QUALIFIED')) {
|
if (\defined('T_NAME_QUALIFIED')) {
|
||||||
$nsTokens[T_NAME_QUALIFIED] = true;
|
$nsTokens[\T_NAME_QUALIFIED] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
for ($i = 0; isset($tokens[$i]); ++$i) {
|
for ($i = 0; isset($tokens[$i]); ++$i) {
|
||||||
$token = $tokens[$i];
|
$token = $tokens[$i];
|
||||||
|
|
||||||
if (!isset($token[1])) {
|
if (!isset($token[1])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -124,6 +122,9 @@ class AnnotationFileLoader extends FileLoader
|
|||||||
$skipClassToken = false;
|
$skipClassToken = false;
|
||||||
for ($j = $i - 1; $j > 0; --$j) {
|
for ($j = $i - 1; $j > 0; --$j) {
|
||||||
if (!isset($tokens[$j][1])) {
|
if (!isset($tokens[$j][1])) {
|
||||||
|
if ('(' === $tokens[$j] || ',' === $tokens[$j]) {
|
||||||
|
$skipClassToken = true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Symfony\Component\Routing\Tests\Fixtures\Attributes;
|
||||||
|
|
||||||
|
#[\Attribute(\Attribute::TARGET_CLASS)]
|
||||||
|
class FooAttributes
|
||||||
|
{
|
||||||
|
public string $class;
|
||||||
|
public array $foo = [];
|
||||||
|
|
||||||
|
public function __construct(string $class, array $foo)
|
||||||
|
{
|
||||||
|
$this->class = $class;
|
||||||
|
$this->foo = $foo;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Symfony\Component\Routing\Tests\Fixtures\AttributesFixtures;
|
||||||
|
|
||||||
|
use Symfony\Component\Routing\Tests\Fixtures\Attributes\FooAttributes;
|
||||||
|
use Symfony\Component\Security\Core\User\User;
|
||||||
|
|
||||||
|
#[FooAttributes(
|
||||||
|
foo: [
|
||||||
|
'bar' => ['foo','bar'],
|
||||||
|
'foo'
|
||||||
|
],
|
||||||
|
class: User::class
|
||||||
|
)]
|
||||||
|
class AttributesClassParamAfterCommaController
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Symfony\Component\Routing\Tests\Fixtures\AttributesFixtures;
|
||||||
|
|
||||||
|
use Symfony\Component\Routing\Tests\Fixtures\Attributes\FooAttributes;
|
||||||
|
use Symfony\Component\Security\Core\User\User;
|
||||||
|
|
||||||
|
#[FooAttributes(
|
||||||
|
class: User::class,
|
||||||
|
foo: [
|
||||||
|
'bar' => ['foo','bar'],
|
||||||
|
'foo'
|
||||||
|
]
|
||||||
|
)]
|
||||||
|
class AttributesClassParamAfterParenthesisController
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Symfony\Component\Routing\Tests\Fixtures\AttributesFixtures;
|
||||||
|
|
||||||
|
use Symfony\Component\Routing\Tests\Fixtures\Attributes\FooAttributes;
|
||||||
|
use Symfony\Component\Security\Core\User\User;
|
||||||
|
|
||||||
|
#[FooAttributes(foo: ['bar' => ['foo','bar'],'foo'],class: User::class)]
|
||||||
|
class AttributesClassParamInlineAfterCommaController
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Symfony\Component\Routing\Tests\Fixtures\AttributesFixtures;
|
||||||
|
|
||||||
|
use Symfony\Component\Routing\Tests\Fixtures\Attributes\FooAttributes;
|
||||||
|
use Symfony\Component\Security\Core\User\User;
|
||||||
|
|
||||||
|
#[FooAttributes(class: User::class,foo: ['bar' => ['foo','bar'],'foo'])]
|
||||||
|
class AttributesClassParamInlineAfterParenthesisController
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Symfony\Component\Routing\Tests\Fixtures\AttributesFixtures;
|
||||||
|
|
||||||
|
use Symfony\Component\Routing\Tests\Fixtures\Attributes\FooAttributes;
|
||||||
|
use Symfony\Component\Security\Core\User\User;
|
||||||
|
|
||||||
|
#[FooAttributes(foo: ['bar' => ['foo','bar'],'foo'],class: 'Symfony\Component\Security\Core\User\User')]
|
||||||
|
class AttributesClassParamInlineQuotedAfterCommaController
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Symfony\Component\Routing\Tests\Fixtures\AttributesFixtures;
|
||||||
|
|
||||||
|
use Symfony\Component\Routing\Tests\Fixtures\Attributes\FooAttributes;
|
||||||
|
use Symfony\Component\Security\Core\User\User;
|
||||||
|
|
||||||
|
#[FooAttributes(class: 'Symfony\Component\Security\Core\User\User',foo: ['bar' => ['foo','bar'],'foo'])]
|
||||||
|
class AttributesClassParamInlineQuotedAfterParenthesisController
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Symfony\Component\Routing\Tests\Fixtures\AttributesFixtures;
|
||||||
|
|
||||||
|
use Symfony\Component\Routing\Tests\Fixtures\Attributes\FooAttributes;
|
||||||
|
|
||||||
|
#[FooAttributes(
|
||||||
|
foo: [
|
||||||
|
'bar' => ['foo','bar'],
|
||||||
|
'foo'
|
||||||
|
],
|
||||||
|
class: 'Symfony\Component\Security\Core\User\User'
|
||||||
|
)]
|
||||||
|
class AttributesClassParamQuotedAfterCommaController
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Symfony\Component\Routing\Tests\Fixtures\AttributesFixtures;
|
||||||
|
|
||||||
|
use Symfony\Component\Routing\Tests\Fixtures\Attributes\FooAttributes;
|
||||||
|
|
||||||
|
#[FooAttributes(
|
||||||
|
class: 'Symfony\Component\Security\Core\User\User',
|
||||||
|
foo: [
|
||||||
|
'bar' => ['foo','bar'],
|
||||||
|
'foo'
|
||||||
|
]
|
||||||
|
)]
|
||||||
|
class AttributesClassParamQuotedAfterParenthesisController
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -85,4 +85,72 @@ class AnnotationFileLoaderTest extends AbstractAnnotationLoaderTest
|
|||||||
$this->assertTrue($this->loader->supports($fixture, 'annotation'), '->supports() checks the resource type if specified');
|
$this->assertTrue($this->loader->supports($fixture, 'annotation'), '->supports() checks the resource type if specified');
|
||||||
$this->assertFalse($this->loader->supports($fixture, 'foo'), '->supports() checks the resource type if specified');
|
$this->assertFalse($this->loader->supports($fixture, 'foo'), '->supports() checks the resource type if specified');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @requires PHP 8
|
||||||
|
*/
|
||||||
|
public function testLoadAttributesClassAfterComma()
|
||||||
|
{
|
||||||
|
$this->reader->expects($this->once())->method('getClassAnnotation');
|
||||||
|
|
||||||
|
$this->loader->load(__DIR__.'/../Fixtures/AttributesFixtures/AttributesClassParamAfterCommaController.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLoadAttributesInlineClassAfterComma()
|
||||||
|
{
|
||||||
|
$this->reader->expects($this->once())->method('getClassAnnotation');
|
||||||
|
|
||||||
|
$this->loader->load(__DIR__.'/../Fixtures/AttributesFixtures/AttributesClassParamInlineAfterCommaController.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @requires PHP 8
|
||||||
|
*/
|
||||||
|
public function testLoadAttributesQuotedClassAfterComma()
|
||||||
|
{
|
||||||
|
$this->reader->expects($this->once())->method('getClassAnnotation');
|
||||||
|
|
||||||
|
$this->loader->load(__DIR__.'/../Fixtures/AttributesFixtures/AttributesClassParamQuotedAfterCommaController.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLoadAttributesInlineQuotedClassAfterComma()
|
||||||
|
{
|
||||||
|
$this->reader->expects($this->once())->method('getClassAnnotation');
|
||||||
|
|
||||||
|
$this->loader->load(__DIR__.'/../Fixtures/AttributesFixtures/AttributesClassParamInlineQuotedAfterCommaController.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @requires PHP 8
|
||||||
|
*/
|
||||||
|
public function testLoadAttributesClassAfterParenthesis()
|
||||||
|
{
|
||||||
|
$this->reader->expects($this->once())->method('getClassAnnotation');
|
||||||
|
|
||||||
|
$this->loader->load(__DIR__.'/../Fixtures/AttributesFixtures/AttributesClassParamAfterParenthesisController.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLoadAttributesInlineClassAfterParenthesis()
|
||||||
|
{
|
||||||
|
$this->reader->expects($this->once())->method('getClassAnnotation');
|
||||||
|
|
||||||
|
$this->loader->load(__DIR__.'/../Fixtures/AttributesFixtures/AttributesClassParamInlineAfterParenthesisController.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @requires PHP 8
|
||||||
|
*/
|
||||||
|
public function testLoadAttributesQuotedClassAfterParenthesis()
|
||||||
|
{
|
||||||
|
$this->reader->expects($this->once())->method('getClassAnnotation');
|
||||||
|
|
||||||
|
$this->loader->load(__DIR__.'/../Fixtures/AttributesFixtures/AttributesClassParamQuotedAfterParenthesisController.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLoadAttributesInlineQuotedClassAfterParenthesis()
|
||||||
|
{
|
||||||
|
$this->reader->expects($this->once())->method('getClassAnnotation');
|
||||||
|
|
||||||
|
$this->loader->load(__DIR__.'/../Fixtures/AttributesFixtures/AttributesClassParamInlineQuotedAfterParenthesisController.php');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user