Skip to content

Commit cafa138

Browse files
Merge branch '4.4' into 5.2
* 4.4: Switched to non-null defaults in exception constructors [Routing] fix conflict with param named class in attribute [Cache] fix setting items' metadata on commit()
2 parents 348b591 + 6991999 commit cafa138

13 files changed

+212
-6
lines changed

Exception/MethodNotAllowedException.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ class MethodNotAllowedException extends \RuntimeException implements ExceptionIn
2222
{
2323
protected $allowedMethods = [];
2424

25-
public function __construct(array $allowedMethods, string $message = null, int $code = 0, \Throwable $previous = null)
25+
/**
26+
* @param string[] $allowedMethods
27+
*/
28+
public function __construct(array $allowedMethods, ?string $message = '', int $code = 0, \Throwable $previous = null)
2629
{
2730
$this->allowedMethods = array_map('strtoupper', $allowedMethods);
2831

@@ -32,7 +35,7 @@ public function __construct(array $allowedMethods, string $message = null, int $
3235
/**
3336
* Gets the allowed HTTP methods.
3437
*
35-
* @return array
38+
* @return string[]
3639
*/
3740
public function getAllowedMethods()
3841
{

Loader/AnnotationFileLoader.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,8 @@ protected function findClass(string $file)
9797
if (\defined('T_NAME_QUALIFIED')) {
9898
$nsTokens[\T_NAME_QUALIFIED] = true;
9999
}
100-
101100
for ($i = 0; isset($tokens[$i]); ++$i) {
102101
$token = $tokens[$i];
103-
104102
if (!isset($token[1])) {
105103
continue;
106104
}
@@ -122,6 +120,9 @@ protected function findClass(string $file)
122120
$skipClassToken = false;
123121
for ($j = $i - 1; $j > 0; --$j) {
124122
if (!isset($tokens[$j][1])) {
123+
if ('(' === $tokens[$j] || ',' === $tokens[$j]) {
124+
$skipClassToken = true;
125+
}
125126
break;
126127
}
127128

RouteCollectionBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,11 @@ private function load($resource, string $type = null): array
350350
}
351351

352352
if (null === $resolver = $this->loader->getResolver()) {
353-
throw new LoaderLoadException($resource, null, null, null, $type);
353+
throw new LoaderLoadException($resource, null, 0, null, $type);
354354
}
355355

356356
if (false === $loader = $resolver->resolve($resource, $type)) {
357-
throw new LoaderLoadException($resource, null, null, null, $type);
357+
throw new LoaderLoadException($resource, null, 0, null, $type);
358358
}
359359

360360
$collections = $loader->load($resource, $type);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Symfony\Component\Routing\Tests\Fixtures\Attributes;
4+
5+
#[\Attribute(\Attribute::TARGET_CLASS)]
6+
class FooAttributes
7+
{
8+
public string $class;
9+
public array $foo = [];
10+
11+
public function __construct(string $class, array $foo)
12+
{
13+
$this->class = $class;
14+
$this->foo = $foo;
15+
}
16+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Symfony\Component\Routing\Tests\Fixtures\AttributesFixtures;
4+
5+
use Symfony\Component\Routing\Tests\Fixtures\Attributes\FooAttributes;
6+
use Symfony\Component\Security\Core\User\User;
7+
8+
#[FooAttributes(
9+
foo: [
10+
'bar' => ['foo','bar'],
11+
'foo'
12+
],
13+
class: User::class
14+
)]
15+
class AttributesClassParamAfterCommaController
16+
{
17+
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Symfony\Component\Routing\Tests\Fixtures\AttributesFixtures;
4+
5+
use Symfony\Component\Routing\Tests\Fixtures\Attributes\FooAttributes;
6+
use Symfony\Component\Security\Core\User\User;
7+
8+
#[FooAttributes(
9+
class: User::class,
10+
foo: [
11+
'bar' => ['foo','bar'],
12+
'foo'
13+
]
14+
)]
15+
class AttributesClassParamAfterParenthesisController
16+
{
17+
18+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Symfony\Component\Routing\Tests\Fixtures\AttributesFixtures;
4+
5+
use Symfony\Component\Routing\Tests\Fixtures\Attributes\FooAttributes;
6+
use Symfony\Component\Security\Core\User\User;
7+
8+
#[FooAttributes(foo: ['bar' => ['foo','bar'],'foo'],class: User::class)]
9+
class AttributesClassParamInlineAfterCommaController
10+
{
11+
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Symfony\Component\Routing\Tests\Fixtures\AttributesFixtures;
4+
5+
use Symfony\Component\Routing\Tests\Fixtures\Attributes\FooAttributes;
6+
use Symfony\Component\Security\Core\User\User;
7+
8+
#[FooAttributes(class: User::class,foo: ['bar' => ['foo','bar'],'foo'])]
9+
class AttributesClassParamInlineAfterParenthesisController
10+
{
11+
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Symfony\Component\Routing\Tests\Fixtures\AttributesFixtures;
4+
5+
use Symfony\Component\Routing\Tests\Fixtures\Attributes\FooAttributes;
6+
use Symfony\Component\Security\Core\User\User;
7+
8+
#[FooAttributes(foo: ['bar' => ['foo','bar'],'foo'],class: 'Symfony\Component\Security\Core\User\User')]
9+
class AttributesClassParamInlineQuotedAfterCommaController
10+
{
11+
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Symfony\Component\Routing\Tests\Fixtures\AttributesFixtures;
4+
5+
use Symfony\Component\Routing\Tests\Fixtures\Attributes\FooAttributes;
6+
use Symfony\Component\Security\Core\User\User;
7+
8+
#[FooAttributes(class: 'Symfony\Component\Security\Core\User\User',foo: ['bar' => ['foo','bar'],'foo'])]
9+
class AttributesClassParamInlineQuotedAfterParenthesisController
10+
{
11+
12+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Symfony\Component\Routing\Tests\Fixtures\AttributesFixtures;
4+
5+
use Symfony\Component\Routing\Tests\Fixtures\Attributes\FooAttributes;
6+
7+
#[FooAttributes(
8+
foo: [
9+
'bar' => ['foo','bar'],
10+
'foo'
11+
],
12+
class: 'Symfony\Component\Security\Core\User\User'
13+
)]
14+
class AttributesClassParamQuotedAfterCommaController
15+
{
16+
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Symfony\Component\Routing\Tests\Fixtures\AttributesFixtures;
4+
5+
use Symfony\Component\Routing\Tests\Fixtures\Attributes\FooAttributes;
6+
7+
#[FooAttributes(
8+
class: 'Symfony\Component\Security\Core\User\User',
9+
foo: [
10+
'bar' => ['foo','bar'],
11+
'foo'
12+
]
13+
)]
14+
class AttributesClassParamQuotedAfterParenthesisController
15+
{
16+
17+
}

Tests/Loader/AnnotationFileLoaderTest.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,72 @@ public function testSupports()
8585
$this->assertTrue($this->loader->supports($fixture, 'annotation'), '->supports() checks the resource type if specified');
8686
$this->assertFalse($this->loader->supports($fixture, 'foo'), '->supports() checks the resource type if specified');
8787
}
88+
89+
/**
90+
* @requires PHP 8
91+
*/
92+
public function testLoadAttributesClassAfterComma()
93+
{
94+
$this->reader->expects($this->once())->method('getClassAnnotation');
95+
96+
$this->loader->load(__DIR__.'/../Fixtures/AttributesFixtures/AttributesClassParamAfterCommaController.php');
97+
}
98+
99+
public function testLoadAttributesInlineClassAfterComma()
100+
{
101+
$this->reader->expects($this->once())->method('getClassAnnotation');
102+
103+
$this->loader->load(__DIR__.'/../Fixtures/AttributesFixtures/AttributesClassParamInlineAfterCommaController.php');
104+
}
105+
106+
/**
107+
* @requires PHP 8
108+
*/
109+
public function testLoadAttributesQuotedClassAfterComma()
110+
{
111+
$this->reader->expects($this->once())->method('getClassAnnotation');
112+
113+
$this->loader->load(__DIR__.'/../Fixtures/AttributesFixtures/AttributesClassParamQuotedAfterCommaController.php');
114+
}
115+
116+
public function testLoadAttributesInlineQuotedClassAfterComma()
117+
{
118+
$this->reader->expects($this->once())->method('getClassAnnotation');
119+
120+
$this->loader->load(__DIR__.'/../Fixtures/AttributesFixtures/AttributesClassParamInlineQuotedAfterCommaController.php');
121+
}
122+
123+
/**
124+
* @requires PHP 8
125+
*/
126+
public function testLoadAttributesClassAfterParenthesis()
127+
{
128+
$this->reader->expects($this->once())->method('getClassAnnotation');
129+
130+
$this->loader->load(__DIR__.'/../Fixtures/AttributesFixtures/AttributesClassParamAfterParenthesisController.php');
131+
}
132+
133+
public function testLoadAttributesInlineClassAfterParenthesis()
134+
{
135+
$this->reader->expects($this->once())->method('getClassAnnotation');
136+
137+
$this->loader->load(__DIR__.'/../Fixtures/AttributesFixtures/AttributesClassParamInlineAfterParenthesisController.php');
138+
}
139+
140+
/**
141+
* @requires PHP 8
142+
*/
143+
public function testLoadAttributesQuotedClassAfterParenthesis()
144+
{
145+
$this->reader->expects($this->once())->method('getClassAnnotation');
146+
147+
$this->loader->load(__DIR__.'/../Fixtures/AttributesFixtures/AttributesClassParamQuotedAfterParenthesisController.php');
148+
}
149+
150+
public function testLoadAttributesInlineQuotedClassAfterParenthesis()
151+
{
152+
$this->reader->expects($this->once())->method('getClassAnnotation');
153+
154+
$this->loader->load(__DIR__.'/../Fixtures/AttributesFixtures/AttributesClassParamInlineQuotedAfterParenthesisController.php');
155+
}
88156
}

0 commit comments

Comments
 (0)