Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
7 changes: 4 additions & 3 deletions src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,10 @@ protected function findClass($file)

$nsTokens = [\T_NS_SEPARATOR => true, \T_STRING => true];
if (\defined('T_NAME_QUALIFIED')) {
$nsTokens[T_NAME_QUALIFIED] = true;
$nsTokens[\T_NAME_QUALIFIED] = true;
}

for ($i = 0; isset($tokens[$i]); ++$i) {
$token = $tokens[$i];

if (!isset($token[1])) {
continue;
}
Expand All @@ -124,6 +122,9 @@ protected function findClass($file)
$skipClassToken = false;
for ($j = $i - 1; $j > 0; --$j) {
if (!isset($tokens[$j][1])) {
if ('(' === $tokens[$j] || ',' === $tokens[$j]) {
$skipClassToken = true;
}
break;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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
{

}
Original file line number Diff line number Diff line change
@@ -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
{

}
Original file line number Diff line number Diff line change
@@ -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
{

}
Original file line number Diff line number Diff line change
@@ -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
{

}
Original file line number Diff line number Diff line change
@@ -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
{

}
Original file line number Diff line number Diff line change
@@ -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
{

}
Original file line number Diff line number Diff line change
@@ -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
{

}
Original file line number Diff line number Diff line change
@@ -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
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,72 @@ public function testSupports()
$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');
}

/**
* @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');
}
}