Skip to content

Commit c5617ff

Browse files
committed
[Routing] Support the "attribute" type (alias of "annotation") in annotation loaders
1 parent f66f1df commit c5617ff

7 files changed

+7
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* Add `getMissingParameters` and `getRouteName` methods on `MissingMandatoryParametersException`
88
* Allow using UTF-8 parameter names
9+
* Support the `attribute` type (alias of `annotation`) in annotation loaders
910

1011
5.3
1112
---

Loader/AnnotationClassLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ protected function addRoute(RouteCollection $collection, object $annot, array $g
237237
*/
238238
public function supports(mixed $resource, string $type = null): bool
239239
{
240-
return \is_string($resource) && preg_match('/^(?:\\\\?[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)+$/', $resource) && (!$type || 'annotation' === $type);
240+
return \is_string($resource) && preg_match('/^(?:\\\\?[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)+$/', $resource) && (!$type || \in_array($type, ['annotation', 'attribute'], true));
241241
}
242242

243243
/**

Loader/AnnotationDirectoryLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function (\SplFileInfo $current) {
6969
*/
7070
public function supports(mixed $resource, string $type = null): bool
7171
{
72-
if ('annotation' === $type) {
72+
if (\in_array($type, ['annotation', 'attribute'], true)) {
7373
return true;
7474
}
7575

Loader/AnnotationFileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function load(mixed $file, string $type = null): ?RouteCollection
6767
*/
6868
public function supports(mixed $resource, string $type = null): bool
6969
{
70-
return \is_string($resource) && 'php' === pathinfo($resource, \PATHINFO_EXTENSION) && (!$type || 'annotation' === $type);
70+
return \is_string($resource) && 'php' === pathinfo($resource, \PATHINFO_EXTENSION) && (!$type || \in_array($type, ['annotation', 'attribute'], true));
7171
}
7272

7373
/**

Tests/Loader/AnnotationClassLoaderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public function provideTestSupportsChecksResource()
4646
public function testSupportsChecksTypeIfSpecified()
4747
{
4848
$this->assertTrue($this->loader->supports('class', 'annotation'), '->supports() checks the resource type if specified');
49+
$this->assertTrue($this->loader->supports('class', 'attribute'), '->supports() checks the resource type if specified');
4950
$this->assertFalse($this->loader->supports('class', 'foo'), '->supports() checks the resource type if specified');
5051
}
5152

Tests/Loader/AnnotationDirectoryLoaderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public function testSupports()
7878
$this->assertFalse($this->loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
7979

8080
$this->assertTrue($this->loader->supports($fixturesDir, 'annotation'), '->supports() checks the resource type if specified');
81+
$this->assertTrue($this->loader->supports($fixturesDir, 'attribute'), '->supports() checks the resource type if specified');
8182
$this->assertFalse($this->loader->supports($fixturesDir, 'foo'), '->supports() checks the resource type if specified');
8283
}
8384

Tests/Loader/AnnotationFileLoaderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public function testSupports()
8383
$this->assertFalse($this->loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
8484

8585
$this->assertTrue($this->loader->supports($fixture, 'annotation'), '->supports() checks the resource type if specified');
86+
$this->assertTrue($this->loader->supports($fixture, 'attribute'), '->supports() checks the resource type if specified');
8687
$this->assertFalse($this->loader->supports($fixture, 'foo'), '->supports() checks the resource type if specified');
8788
}
8889

0 commit comments

Comments
 (0)